Php Symfony2中测试条令实体的权利主张

Php Symfony2中测试条令实体的权利主张,php,unit-testing,symfony,doctrine-orm,phpunit,Php,Unit Testing,Symfony,Doctrine Orm,Phpunit,我正在为我的实体编写一些测试,下面是代码: $device = new Device(); $strTool = new StringTools(); $imei = $strTool->randomNumber(17); $device->setImei($imei); $device->setDescription($strTool->generateRandomString(50)); $this->em->persist($device); $th

我正在为我的实体编写一些测试,下面是代码:

$device = new Device();
$strTool = new StringTools();

$imei = $strTool->randomNumber(17);
$device->setImei($imei);
$device->setDescription($strTool->generateRandomString(50));

$this->em->persist($device);
$this->em->flush();

$devices = $this->em->getRepository('DeviceBundle:Device')->findOneBy(array('imei' => $imei));

$this->assertCount(1, $devices);
$this->assertTrue(is_object($device));
但第一次测试
assertCount
失败,显示以下消息:

PHPUnit#u框架#u异常:的参数#2(无值) PHPUnit_Framework_Assert::assertCount()必须是可计数或 可穿越


测试从DB获取结果的正确方法是什么?

findOneBy
只返回一个元素,改用
findBy


顺便说一句,你在这里测试的是教义本身。条令经过了很好的测试,因此您无需这样做。

我正在尝试测试我的实体,看看它们是否正确映射,等等,您是如何测试实体的?除非您的setter或getter添加了额外的逻辑(例如:
getFullName=getFirstname.''.getLastname
),否则无需测试您的实体。但是,例如,您需要测试实体存储库中的自定义方法(例如:
getpostwithmostcoments
)。