Skip to content
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

Fixes issue #10 . #11

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function __invoke($params = [], $object_name = null)
protected function dispatch($object, $params = [])
{
$method = $this->getMethodByParams($params);
if (is_callable([$object, $method])) {
if (is_callable([$object, $method]) && method_exists($object, $method)) {
// the object has the specified method
$result = $this->invokeMethod($object, $method, $params);
} elseif ($object instanceof Closure) {
Expand Down
14 changes: 14 additions & 0 deletions tests/src/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ protected function setUp()
},
'invokable' => function () {
return new FakeInvokable;
},
'methodandinvoke' => function () {
return new FakeClassWithMethod;
}
];

Expand Down Expand Up @@ -164,4 +167,15 @@ public function testDispatch_namedObject()
$expect = 'FOO BAR baz';
$this->assertSame($expect, $actual);
}

public function testMethodExistsInvokable()
{
$params = [
'action' => 'someAction',
'controller' => 'methodandinvoke'
];
$actual = $this->dispatcher->__invoke($params);
$expect = 'Hello World!';
$this->assertSame($expect, $actual);
}
}
10 changes: 10 additions & 0 deletions tests/src/FakeClassWithMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Aura\Dispatcher;

class FakeClassWithMethod
{
public function someAction()
{
return new FakeInvokableClass();
}
}
10 changes: 10 additions & 0 deletions tests/src/FakeInvokableClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Aura\Dispatcher;

class FakeInvokableClass
{
public function __invoke($name = "World!")
{
return "Hello $name";
}
}