Skip to content

Commit

Permalink
Merge branch 'release/0.4.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
ihabunek committed Oct 21, 2014
2 parents ee6eccc + 8837df2 commit af87cf4
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 22 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -2,6 +2,7 @@ language: php

php:
- 5.5
- 5.6
- hhvm

before_script:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,16 @@
Cicada changelog
================

0.4.10 (2014-10-21)
-------------------

Features:

* Fixed Invoker to map subclasses (it is now possible to use a subclass of
Application and it will be properly mapped in callbacks which reference
Application)
* Updated HTTP Foundation dependency to 2.5.x

0.4.9 (2014-10-15)
------------------

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -31,7 +31,7 @@ $app = new Application();

// Add a route
$app->get('/hello/{name}', function (Application $app, Request $request, $name) {
return Response("Hello $name");
return new Response("Hello $name");
});

$app->run();
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -25,7 +25,7 @@
"php": ">=5.4.0",
"apache/log4php": "2.3.0",
"evenement/evenement": "2.0.*",
"symfony/http-foundation": "2.4.*",
"symfony/http-foundation": "2.5.*",
"pimple/pimple": "~3.0"
},
"require-dev": {
Expand Down
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/Invoker.php
Expand Up @@ -178,15 +178,15 @@ private function reindexClassParams(array $classParams)
throw new \InvalidArgumentException("\$classParams entries must be objects.");
}

$class = get_class($param);

if (isset($reindexed[$class])) {
throw new \InvalidArgumentException(
"\$classParams contains multiple objects of the same class [$class]."
);
// Iterate for param class and all parent classes. This way you can
// inject subclasses as well as the specified class
for ($class = get_class($param); $class !== false; $class = get_parent_class($class)) {
if (isset($reindexed[$class])) {
throw new \InvalidArgumentException("\$classParams contains multiple objects of the same class [$class].");
}

$reindexed[$class] = $param;
}

$reindexed[$class] = $param;
}

return $reindexed;
Expand Down
32 changes: 32 additions & 0 deletions tests/InvokerTest.php
Expand Up @@ -26,6 +26,11 @@ function invokerTestFunction(Application $app, Request $request, $foo, $bar)
return func_get_args();
}

class ApplicationSubClass extends Application
{

}

class InvokerTest extends \PHPUnit_Framework_TestCase
{
private $namedParams = [
Expand Down Expand Up @@ -160,6 +165,33 @@ public function testInvokeObjectMethod()
$this->assertEquals($expected5, $actual5);
}

public function testInvokeSubClass()
{
// Check that a subclass of Application is properly injected
$app = new ApplicationSubClass();
$request = new Request();
$classParams = [$app, $request];

$invoker = new Invoker();
$actual1 = $invoker->invoke("Cicada\Tests\InvokerTestAction::execute1", $this->namedParams, $classParams);
$actual2 = $invoker->invoke("Cicada\Tests\InvokerTestAction::execute2", $this->namedParams, $classParams);
$actual3 = $invoker->invoke("Cicada\Tests\InvokerTestAction::execute3", $this->namedParams, $classParams);
$actual4 = $invoker->invoke("Cicada\Tests\InvokerTestAction::execute4", $this->namedParams, $classParams);
$actual5 = $invoker->invoke("Cicada\Tests\InvokerTestAction::execute5", $this->namedParams, $classParams);

$expected1 = ['foo_val', 'bar_val'];
$expected2 = ['foo_val', 'bar_val', $request];
$expected3 = [$app, $request, 'foo_val', 'bar_val'];
$expected4 = [$app, $request, 'foo_val', 'bar_val'];
$expected5 = [$app, $request, 'foo_val', 'bar_val', null];

$this->assertEquals($expected1, $actual1);
$this->assertEquals($expected2, $actual2);
$this->assertEquals($expected3, $actual3);
$this->assertEquals($expected4, $actual4);
$this->assertEquals($expected5, $actual5);
}

public function testInvokeFunction()
{
$app = new Application();
Expand Down

0 comments on commit af87cf4

Please sign in to comment.