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

Added support to model helpers for chaining relationship methods #52

Open
wants to merge 1 commit into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+20 −11
Diff settings

Always

Just for now

@@ -67,50 +67,59 @@ public function assertRelationship($relationship, $class, $type)
$args = $this->getArgumentsRelationship($relationship, $class, $type);
$class = Mockery::mock($class."[$type]");
$class = Mockery::mock($class."[$type]")->shouldIgnoreMissing()->asUndefined();
switch(count($args))
{
case 1 :
$class->shouldReceive($type)
->once()
->with('/' . str_singular($relationship) . '/i');
->with('/' . str_singular($relationship) . '/i')
->andReturn(Mockery::self());
break;
case 2 :
$class->shouldReceive($type)
->once()
->with('/' . str_singular($relationship) . '/i', $args[1]);
->with('/' . str_singular($relationship) . '/i', $args[1])
->andReturn(Mockery::self());
break;
case 3 :
$class->shouldReceive($type)
->once()
->with('/' . str_singular($relationship) . '/i', $args[1], $args[2]);
->with('/' . str_singular($relationship) . '/i', $args[1], $args[2])
->andReturn(Mockery::self());
break;
case 4 :
$class->shouldReceive($type)
->once()
->with('/' . str_singular($relationship) . '/i', $args[1], $args[2], $args[3]);
->with('/' . str_singular($relationship) . '/i', $args[1], $args[2], $args[3])
->andReturn(Mockery::self());
break;
default :
$class->shouldReceive($type)
->once();
->once()
->andReturn(Mockery::self());
break;
}
$class->$relationship();
}
public function getArgumentsRelationship($relationship, $class, $type) {
$mocked = Mockery::mock($class."[$type]");
$mocked = Mockery::mock($class."[$type]")->shouldIgnoreMissing()->asUndefined();
$args = array();
$mocked->shouldReceive($type)
->once()
->andReturnUsing(function ()
->andReturnUsing(function () use (&$args)
{
return func_get_args();
$args = func_get_args();
return Mockery::self();
});
return $mocked->$relationship();
$mocked->$relationship();
return $args;
}
}
ProTip! Use n and p to navigate between commits in a pull request.