From 4658c228959f03ca46a4c8c5bdfdfb2f34fe65b4 Mon Sep 17 00:00:00 2001 From: David Bowen Date: Sat, 1 Jun 2013 02:43:38 +0200 Subject: [PATCH] Fixed not accepting multiple args in relationships A fix for the issue of it currently not likely when relationships have more than one argument defined (e.g. belongsTo('table', 'key') would fail the validation). This fix checks how many arguments the parameter provides, and then does the check to see if the "model" bit matches the expected, while just providing the normal arguments back as is. --- src/Way/Tests/ModelHelpers.php | 37 +++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/Way/Tests/ModelHelpers.php b/src/Way/Tests/ModelHelpers.php index cf3bb64..7269592 100644 --- a/src/Way/Tests/ModelHelpers.php +++ b/src/Way/Tests/ModelHelpers.php @@ -55,11 +55,42 @@ public function assertRelationship($relationship, $class, $type) { $this->assertRespondsTo($relationship, $class); + $mocked = Mockery::mock($class."[$type]"); + + $mocked->shouldReceive($type) + ->once() + ->andReturnUsing(function () + { + return func_get_args(); + }); + + $args = $mocked->$relationship(); + $class = Mockery::mock($class."[$type]"); - $class->shouldReceive($type) - ->with('/' . str_singular($relationship) . '/i') - ->once(); + switch(count($args)) + { + case 1 : + $class->shouldReceive($type) + ->once() + ->with('/' . str_singular($relationship) . '/i'); + break; + case 2 : + $class->shouldReceive($type) + ->once() + ->with('/' . str_singular($relationship) . '/i', $args[1]); + break; + case 3 : + $class->shouldReceive($type) + ->once() + ->with('/' . str_singular($relationship) . '/i', $args[1], $args[2]); + break; + case 4 : + $class->shouldReceive($type) + ->once() + ->with('/' . str_singular($relationship) . '/i', $args[1], $args[2], $args[3]); + break; + } $class->$relationship(); }