Reputation: 18680
I'm writing some test for my entities and this is the code:
$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));
But first test assertCount
is failing with this message:
PHPUnit_Framework_Exception: Argument #2 (No Value) of PHPUnit_Framework_Assert::assertCount() must be a countable or traversable
What is the right way to test I get results from DB?
Upvotes: 0
Views: 1207
Reputation: 1181
findOneBy
return only one element, use findBy
instead.
btw, what you are testing here is Doctrine itself. Doctrine is pretty well tested so there is no need for you to do that.
Upvotes: 2