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

testPutActionWithNestedEntityThatHasANestedCollection() public method

    public function testPutActionWithNestedEntityThatHasANestedCollection()
    {
        $car1 = new Car();
        $car1->name = "Chrysler Caravan";
        $car1->year = 2003;
        $car2 = new Car();
        $car2->name = "Suzuki Sidekick";
        $car2->year = 1999;
        $mother = new Person();
        $mother->name = "Sharon Lemon";
        $mother->cars->add($car1);
        $mother->cars->add($car2);
        $person = new Person();
        $person->name = "Stan Lemon";
        $person->mother = $mother;
        $this->em->persist($person);
        $this->em->flush($person);
        $this->em->clear();
        $request = $this->makeRequest('PUT', '/person/' . $person->id, json_encode(array('name' => $person->name, 'mother' => array('id' => $mother->id, 'name' => $mother->name, 'mother' => array('name' => 'Arbutus'), 'cars' => array(array('id' => $car1->id, 'name' => $car1->name, 'year' => $car1->year), array('name' => 'Ford Fusion', 'year' => 2013))))));
        $this->controller->putAction($request, 'person', $person->id);
        $refresh = $this->em->getRepository('Lemon\\RestBundle\\Tests\\Fixtures\\Person')->findOneBy(array('id' => $person->id));
        $this->assertNotNull($refresh);
        $this->assertEquals($person->id, $refresh->id);
        $this->assertEquals($person->name, $refresh->name);
        $this->assertNotNull($refresh->mother);
        $this->assertEquals($person->mother->id, $refresh->mother->id);
        $this->assertEquals($person->mother->name, $refresh->mother->name);
        $this->assertNotNull($refresh->mother->mother);
        $this->assertCount(2, $refresh->mother->cars);
        $this->assertArrayHasObjectWithValue($car1->name, $refresh->mother->cars, 'name');
        $this->assertArrayHasObjectWithValue((string) $car1->year, $refresh->mother->cars, 'year');
        $this->assertArrayHasObjectWithValue('Ford Fusion', $refresh->mother->cars, 'name');
        $this->assertArrayHasObjectWithValue('2013', $refresh->mother->cars, 'year');
    }