Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: asserting of relationships does not check returned value #21

Open
laurencei opened this issue Jul 2, 2013 · 0 comments
Open

Bug: asserting of relationships does not check returned value #21

laurencei opened this issue Jul 2, 2013 · 0 comments

Comments

@laurencei
Copy link

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant