I use doctrine tools to load test data into a Symfony application.
$this->fixtureLoader = $this->loadFixtures([ "My\DemonBundle\DataFixtures\ORM\LoadEntity1Data", "My\DemonBundle\DataFixtures\ORM\LoadEntity2Data", "My\DemonBundle\DataFixtures\ORM\LoadEntity3Data", "My\DemonBundle\DataFixtures\ORM\LoadEntity4Data", "My\DemonBundle\DataFixtures\ORM\LoadEntity5Data", 'My\DemonBundle\DataFixtures\ORM\LoadEntity6Data' ]);
In my test case, I want to check if broken objects receive.
public function testGetPaginated() { $entities6 = $this->fixtureLoader->getReferenceRepository()->getReferences(); $expected = array_slice($entities6, 3, 3); $this->client = static::makeClient(); $this->client->request('GET', '/api/v1/entities6', ["page" => 2, "limit" => 3, "order" => "id", "sort" => "asc"], array(), array( 'CONTENT_TYPE' => 'application/json', 'HTTP_ACCEPT' => 'application/json' )); $this->assertSame($expected, $this->client->getResponse()->getContent()); }
I want to compare the page with my fixtures and from the api answer. The problem below the line returns all links to fixtures. The object I want to test is of type Entity6. Entity6 has a dependency on all other types, so I have to download them all.
$ objects = $ this-> fixtureLoader-> getReferenceRepository () β getReferences ();
How to get links only to type Entity6? I burst into
Doctrine \ Common \ DataFixtures \ ReferenceRepository :: getReferences code
public function getReferences() { return $this->references; }
There is no way to get links of a certain type. I tried to loop over all the links to check the type of the class using get_class
foreach ($references as $reference) { $class = get_class($obj); if ($class == "My\DemonBundle\Entity\ORM\Entity6") { $expected[] = $obj; } }
But links are proxy doctrine powers, so I get a class type
Proxies\__CG__\My\DemonBundle\Entity\ORM\Entity6
How to get references to the type of entity from the instruments of the doctrine? Proxies__CG__ prefix may not be the best way to do this? What is the most reliable way?