我正在使用doctrine fixtures在我的symfony应用程序中加载测试数据.
$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' ]);
在我的测试用例中,我想测试获取分页实体.
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()); }
我想比较我的灯具和api响应的页面.问题是线下返回所有夹具参考.我想测试的实体是Entity6类型.Entity6依赖于所有其他类型,因此我必须加载所有其他类型.
$ entities = $ this-> fixtureLoader-> getReferenceRepository() - > getReferences();
我如何才能获得Entity6类型的推荐?我深入研究
Doctrine\Common\DataFixtures\ReferenceRepository :: getReferences代码
/** * Get all stored references * * @return array */ public function getReferences() { return $this->references; }
没有选项可以获得特定类型的引用.我尝试循环所有引用以使用get_class检查类类型
foreach ($references as $reference) { $class = get_class($obj); if ($class == "My\DemonBundle\Entity\ORM\Entity6") { $expected[] = $obj; } }
但引用是代理学说权利,所以我得到类型
Proxies\__CG__\My\DemonBundle\Entity\ORM\Entity6
如何从doctrine fixture获取实体类型的引用?Prefixing Proxies__CG__可能不是最好的方法吗?什么是最可靠的方式?