Skip to content
This repository was archived by the owner on Apr 19, 2021. It is now read-only.

Commit 56510a3

Browse files
committed
updated the bus to accept a prebuilt command
1 parent 14e0155 commit 56510a3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Bus.php

+3
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ protected function resolveMiddleware(array $middleware)
122122
*/
123123
protected function mapInputToCommand($command, $input)
124124
{
125+
if (is_object($command)) {
126+
return $command;
127+
}
125128
$dependencies = [];
126129
$class = new ReflectionClass($command);
127130
foreach ($class->getConstructor()->getParameters() as $parameter) {

tests/Bus/TestBus.php

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ public function test_it_handles_a_command()
2121
$this->assertInstanceOf('Joselfonseca\LaravelTactician\Tests\Stubs\TestCommand', $bus->dispatch('Joselfonseca\LaravelTactician\Tests\Stubs\TestCommand', [], []));
2222
}
2323

24+
25+
public function test_it_accepts_prebuilt_command_objects()
26+
{
27+
$bus = app('Joselfonseca\LaravelTactician\CommandBusInterface');
28+
$bus->addHandler('Joselfonseca\LaravelTactician\Tests\Stubs\TestCommand',
29+
'Joselfonseca\LaravelTactician\Tests\Stubs\TestCommandHandler');
30+
$this->assertInstanceOf('Joselfonseca\LaravelTactician\Tests\Stubs\TestCommand', $bus->dispatch(app('Joselfonseca\LaravelTactician\Tests\Stubs\TestCommand'), [], []));
31+
}
32+
2433
/**
2534
* Test if a a middleware can be applied to the stack
2635
*/

0 commit comments

Comments
 (0)