Ok, here’s the situation. I use Doctrine 2 and PHPUnit.
I have a list of products, each has a category. I want to test findByCategory() method which should obviously return a list of products for specific category.
Quite simple, but I’m not sure how to test this properly. On some places on web I see just simple examples like:
$this->assertEquals(4, count($foundProducts));
So it just tests the quantity of returned results, but not the actual data.
I also tried this:
foreach($allFoundProducts as $i=>$foundProduct) {
$this->assertEquals($products[$i], $foundProduct);
}
where $products is a list of entities I’ve persisted prior to searching.
But it takes a lot of time to accomplish and sometimes even crashes (insufficient memory).
Please advice me the approach you use to make database tests like this.
Thanks a lot!
I’d test the number of returned results (like in your first example), then run through the results and test their type: