Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/factory-parameters' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nickl- committed Jul 13, 2012
2 parents 2fe1723 + a31aaa2 commit ca1fef7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions library/Respect/Rest/Routes/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public function getReflection($method)
public function runTarget($method, &$params)
{
if (is_null($this->instance))
$this->instance = call_user_func($this->factory);
$this->instance = call_user_func_array($this->factory, array($method, &$params));

if (!$this->instance instanceof Routable)
throw new InvalidArgumentException('Routed classes must implement the Respect\\Rest\\Routable interface');
throw new InvalidArgumentException('Routed classes must implement the Respect\\Rest\\Routable interface');

return call_user_func_array(
array($this->instance, $method), $params
Expand Down
58 changes: 29 additions & 29 deletions tests/library/Respect/Rest/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testMagicConstructorCanCreateCallbackRoutes()
$concreteCallbackRoute = $router->callbackRoute('GET', '/', $target);

$this->assertInstanceOf(
'Respect\Rest\Routes\Callback',
'Respect\Rest\Routes\Callback',
$callbackRoute,
'Returned result from a magic constructor in this case should return a Routes\Callback'
);
Expand All @@ -55,7 +55,7 @@ public function testMagicConstructorCanCreateCallbackRoutes()
'When there are no arguments the Routes\Callback should have none as well'
);
$this->assertEquals(
$callbackRoute,
$callbackRoute,
$concreteCallbackRoute,
'The magic and concrete instances of Routes\Callback should be equivalent'
);
Expand All @@ -73,17 +73,17 @@ public function testMagicConstructorCanCreateCallbackRoutesWithExtraParams()
$concreteCallbackRoute = $router->callbackRoute('GET', '/', $target, array('extra'));

$this->assertInstanceOf(
'Respect\Rest\Routes\Callback',
'Respect\Rest\Routes\Callback',
$callbackRoute,
'Returned result from a magic constructor in this case should return a Routes\Callback'
);
$this->assertContains(
'extra',
'extra',
$callbackRoute->arguments,
'The "extra" appended to the magic constructor should be present on the arguments list'
);
$this->assertEquals(
$callbackRoute,
$callbackRoute,
$concreteCallbackRoute,
'The magic and concrete instances of Routes\Callback should be equivalent'
);
Expand All @@ -101,12 +101,12 @@ public function testMagicConstructorCanRouteToPreBuiltInstances()
$concreteInstanceRoute = $router->instanceRoute('GET', '/', $myInstance);

$this->assertInstanceOf(
'Respect\Rest\Routes\Instance',
'Respect\Rest\Routes\Instance',
$instanceRoute,
'Returned result from a magic constructor in this case should return a Routes\Instance'
);
$this->assertEquals(
$instanceRoute,
$instanceRoute,
$concreteInstanceRoute,
'The magic and concrete instances of Routes\Instance should be equivalent'
);
Expand All @@ -124,12 +124,12 @@ public function testMagicConstructorCanRouteToStaticValue($staticValue, $reason)
$concreteStaticRoute = $router->staticRoute('GET','/', $staticValue);

$this->assertInstanceOf(
'Respect\Rest\Routes\StaticValue',
'Respect\Rest\Routes\StaticValue',
$staticRoute,
$reason
);
$this->assertEquals(
$staticRoute,
$staticRoute,
$concreteStaticRoute,
'The magic and concrete instances of Routes\Static should be equivalent'
);
Expand All @@ -155,7 +155,7 @@ public function testMagicConstructorCannotRouteSomeStaticValues($staticValue, $r
$nonStaticRoute = $router->get('/', $staticValue);

$this->assertNotInstanceOf(
'Respect\Rest\Routes\StaticValue',
'Respect\Rest\Routes\StaticValue',
$nonStaticRoute,
$reason
);
Expand All @@ -182,12 +182,12 @@ public function testMagicConstructorCanRouteToClasses()
$concreteClassRoute = $router->classRoute('GET', '/', $className);

$this->assertInstanceOf(
'Respect\Rest\Routes\ClassName',
'Respect\Rest\Routes\ClassName',
$classRoute,
'Returned result from a magic constructor in this case should return a Routes\ClassName'
);
$this->assertEquals(
$classRoute,
$classRoute,
$concreteClassRoute,
'The magic and concrete instances of Routes\ClassName should be equivalent'
);
Expand All @@ -206,17 +206,17 @@ public function testMagicConstructorCanRouteToClassesUsingConstructorParams()
$concreteClassRoute = $router->classRoute('GET', '/', $className, array('some', 'constructor', 'params'));

$this->assertInstanceOf(
'Respect\Rest\Routes\ClassName',
'Respect\Rest\Routes\ClassName',
$classRoute,
'Returned result from a magic constructor in this case should return a Routes\ClassName'
);
$this->assertEquals(
array('some', 'constructor', 'params'),
array('some', 'constructor', 'params'),
$classRoute->constructorParams,
'The constructor params should be available on the instance of Routes\ClassName'
);
$this->assertEquals(
$classRoute,
$classRoute,
$concreteClassRoute,
'The magic and concrete instances of Routes\ClassName should be equivalent'
);
Expand All @@ -233,12 +233,12 @@ public function testMagicConstructorCanRouteToFactoriesThatReturnInstancesOfACla
$concreteFactoryRoute = $router->factoryRoute('GET', '/', 'DateTime', array('DateTime', 'createFromFormat'));

$this->assertInstanceOf(
'Respect\Rest\Routes\Factory',
'Respect\Rest\Routes\Factory',
$factoryRoute,
'Returned result from a magic constructor in this case should return a Routes\Factory'
);
$this->assertEquals(
$factoryRoute,
$factoryRoute,
$concreteFactoryRoute,
'The magic and concrete instances of Routes\Factory should be equivalent'
);
Expand All @@ -259,7 +259,7 @@ public function testCanToRespondToGlobalOptionsMethodAutomatically()
$response = (string) $router->dispatch('OPTIONS', '*')->response();

$this->assertContains(
'Allow: GET, POST, EAT',
'Allow: GET, POST, EAT',
xdebug_get_headers(),
'There should be a sent Allow header with all methods from all routes'
);
Expand All @@ -280,15 +280,15 @@ public function testDeveloperCanOverridePostMethodWithQueryStringParameter()
$router->post('/bulbs', 'Some Bulbs Post Response');

$result = (string) $router->dispatch('POST', '/bulbs')->response();

$this->assertSame(
'Some Bulbs Put Response',
'Some Bulbs Put Response',
$result,
'Router should dispatch to PUT (overriden) instead of POST'
);

$this->assertNotSame(
'Some Bulbs Post Response',
'Some Bulbs Post Response',
$result,
'Router NOT dispatch to POST when method is overriden'
);
Expand All @@ -309,13 +309,13 @@ public function testDeveloperCanTurnOffMethodOverriding(Router $router)
$result = (string) $router->dispatch('POST', '/bulbs')->response();

$this->assertSame(
'Some Bulbs Post Response',
'Some Bulbs Post Response',
$result,
'Router should dispatch to POST (not overriden) instead of PUT'
);

$this->assertNotSame(
'Some Bulbs Put Response',
'Some Bulbs Put Response',
$result,
'Router NOT dispatch to PUT when method is overriden'
);
Expand Down Expand Up @@ -349,7 +349,7 @@ public function testRouterCanBeAutoDispatchedIfProtocolIsDefined()
$router = new Router;
$router->get('/', 'Hello Respect');
unset($router);

$this->expectOutputString('Hello Respect');
}

Expand All @@ -359,7 +359,7 @@ public function testReturns404WhenNoRoutesExist()
$response = (string) $router->dispatch('GET', '/')->response();

$this->assertEquals(
'404',
'404',
static::$status,
'There should be a sent 404 status'
);
Expand All @@ -372,7 +372,7 @@ public function testReturns404WhenNoRouteMatches()
$response = (string) $router->dispatch('GET', '/')->response();

$this->assertEquals(
'404',
'404',
static::$status,
'There should be a sent 404 status'
);
Expand All @@ -382,10 +382,10 @@ public function testReturns404WhenNoRouteMatches()

function header($h) {
$s = debug_backtrace(true);
$rt = function($a) {return isset($a['object'])
&& $a['object'] instanceof RouterTest;};
$rt = function($a) {return isset($a['object'])
&& $a['object'] instanceof RouterTest;};
if (array_filter($s, $rt) && 0 === strpos($h, 'HTTP/1.1 ')) {
RouterTest::$status = substr($h, 9);
}
return \header($h);
}
}

0 comments on commit ca1fef7

Please sign in to comment.