Laravel-Test-Helpers
Laravel-Test-Helpers copied to clipboard
Bug: asserting of relationships does not check returned value
Hi,
I found a 'bug' in AssertHasMany(), AssertHasOne() etc
If I do my relationship like this:
public function photos()
{
$this->hasMany('Photo');
}
Then AssertHasMany will pass 'green' on phpunit.
public function testProjectHasManyPhotos()
{
$this->assertHasMany('photos', 'Project');
}
But this is the wrong syntax as I discovered after hours of debugging to work out why my program was not work. It should be;
public function photos()
{
return $this->hasMany('Photo');
}
So we should make the Asserts ensure the relationship is there AND returned, or it is actually NOT working, and eloquent will fail when you try and use the relationship in your code.
Took me hours to work this out :)