Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
plvhx committed Sep 24, 2017
1 parent 0bbd7ec commit dd23bc2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Invoker/MethodInvoker.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MethodInvoker implements InvokerInterface
*/
private $method;

public function __construct(Container $container, $args)
public function __construct($args)
{
if (!is_array($args)) {
throw new \InvalidArgumentException(
Expand All @@ -38,7 +38,7 @@ public function __construct(Container $container, $args)

$args['instance'] = (!is_object($args['instance'])
? (class_exists($args['instance'])
? $container->make($args['instance'])
? (new Container)->make($args['instance'])
: null)
: $args['instance']);

Expand Down
16 changes: 8 additions & 8 deletions tests/Invoker/MethodInvokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MethodInvokerTest extends \PHPUnit_Framework_TestCase
public function testCanGetInstance()
{
$invoker = new MethodInvoker(
new Container, ['instance' => \SplPriorityQueue::class, 'method' => 'count']
['instance' => \SplPriorityQueue::class, 'method' => 'count']
);

$this->assertInstanceOf(MethodInvoker::class, $invoker);
Expand All @@ -24,37 +24,37 @@ public function testCanGetInstance()
*/
public function testCannotGetInstanceAndThrowsException0()
{
$invoker = new MethodInvoker(new Container, null);
$invoker = new MethodInvoker(null);
}

/**
* @expectedException \TaskQueue\Invoker\Exception\ArrayPairLengthAwareException
*/
public function testCannotGetInstanceAndThrowsException1()
{
$invoker = new MethodInvoker(new Container, []);
$invoker = new MethodInvoker([]);
}

/**
* @expectedException \TaskQueue\Invoker\Exception\ClassInstanceException
*/
public function testCannotGetInstanceAndThrowsException2()
{
$invoker = new MethodInvoker(new Container, [\SplPriorityQueue::class, 'method' => 'count']);
$invoker = new MethodInvoker([\SplPriorityQueue::class, 'method' => 'count']);
}

/**
* @expectedException \TaskQueue\Invoker\Exception\ClassMethodException
*/
public function testCannotGetInstanceAndThrowsException3()
{
$invoker = new MethodInvoker(new Container, ['instance' => \SplPriotiyQueue::class, 'count']);
$invoker = new MethodInvoker(['instance' => \SplPriotiyQueue::class, 'count']);
}

public function testCanInvokeMethodWithPHPBuiltinArgumentGetter()
{
$invoker = new MethodInvoker(
new Container, ['instance' => \SplPriorityQueue::class, 'method' => 'count']
['instance' => \SplPriorityQueue::class, 'method' => 'count']
);

$this->assertInstanceOf(MethodInvoker::class, $invoker);
Expand All @@ -68,7 +68,7 @@ public function testCanInvokeMethodWithPHPBuiltinArgumentGetter()
public function testCannotInvokeMethodAndThrowsException()
{
$invoker = new MethodInvoker(
new Container, ['instance' => \SplPriorityQueue::class, 'method' => 'count']
['instance' => \SplPriorityQueue::class, 'method' => 'count']
);

$invoker->invokeWithArgs(null);
Expand All @@ -77,7 +77,7 @@ public function testCannotInvokeMethodAndThrowsException()
public function testCanInvokeMethodWithArrayOfArguments()
{
$invoker = new MethodInvoker(
new Container, ['instance' => \SplPriorityQueue::class, 'method' => 'count']
['instance' => \SplPriorityQueue::class, 'method' => 'count']
);

$this->assertInstanceOf(MethodInvoker::class, $invoker);
Expand Down
10 changes: 10 additions & 0 deletions tests/TaskQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,14 @@ public function testCanRegisterFunctionBasedMultipleTasks()

$taskQueue->run();
}

public function testCanRegisterMethodBasedSingleTask()
{
$taskQueue = new TaskQueue;

$taskQueue
->add(new MethodInvoker(['instance' => new \SplFixedArray, 'method' => 'count']));

$taskQueue->run();
}
}

0 comments on commit dd23bc2

Please sign in to comment.