Lemon\RestBundle\Tests\Controller\ResourceControllerTest::testListAction PHP Method

testListAction() public method

public testListAction ( )
    public function testListAction()
    {
        $person1 = new Person();
        $person1->name = "Stan Lemon";
        $person1->created = new \DateTime();
        $person2 = new Person();
        $person2->name = "Sara Lemon";
        $person2->created = new \DateTime();
        $person3 = new Person();
        $person3->name = "Lucy Lemon";
        $person3->created = new \DateTime();
        $person4 = new Person();
        $person4->name = "Evelyn Lemon";
        $person4->created = new \DateTime();
        $person5 = new Person();
        $person5->name = "Henry Lemon";
        $person5->created = new \DateTime();
        $this->em->persist($person1);
        $this->em->persist($person2);
        $this->em->persist($person3);
        $this->em->persist($person4);
        $this->em->persist($person5);
        $this->em->flush();
        $this->em->clear();
        $parameters = array(DefaultCriteria::OFFSET => 1, DefaultCriteria::LIMIT => 3, DefaultCriteria::ORDER_BY => 'name');
        $request = $this->makeRequest('GET', '/person', null, $parameters);
        /** @var \Symfony\Component\HttpFoundation\Response $response */
        $response = $this->controller->listAction($request, 'person');
        $data = json_decode($response->getContent());
        $this->assertCount(3, $data);
        $this->assertEquals($person5->id, $data[0]->id);
        $this->assertEquals($person3->id, $data[1]->id);
        $this->assertEquals($person2->id, $data[2]->id);
        $this->assertEquals(5, $response->headers->get("x-total-count"));
    }