Skip to content

Added full support for Eloquent's relationship methods with tests. #14

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added support for chained query methods on Eloquent's relationship me…
…thods. Chained method names are not validated or limited so be careful. Test was added as well.
  • Loading branch information
michaeldavidkelley committed Jun 11, 2013
commit 7bac5bd5f0a186d3487adfa3e29065365b6cc3de
4 changes: 3 additions & 1 deletion src/Way/Tests/ModelHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public function assertRelationship($type, $relationshipName, $class, $relatedMod
$this->assertRespondsTo($relationshipName, $class);

$mock = Mockery::mock($class."[$type]");
$m = $mock->shouldReceive($type)->once();
$m = $mock->shouldReceive($type)->once()->andReturn(
Mockery::mock()->shouldIgnoreMissing()
);

if( is_null($relatedModel) ) {
$m->with('/' . str_singular($relationshipName) . '/i');
Expand Down
11 changes: 11 additions & 0 deletions tests/Way/Tests/ModelHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public function owners()
{
return $this->belongsToMany('User', 'test_user', 'owner_id', 'test_id');
}

public function doctors()
{
// Get assigned doctors and generic doctors
return $this->hasMany('Doctor')->where('doctor_id', '=', null);
}
}


Expand Down Expand Up @@ -141,4 +147,9 @@ public function testBelongsToManyRelationshipWithTableForeignKeyAndOtherKey()
{
$this->assertBelongsToMany('owners', 'TestModel', 'User', 'test_user', 'owner_id', 'test_id');
}

public function testRelationshipsCanHaveQueryMethods()
{
$this->assertHasMany('doctors', 'TestModel');
}
}