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

updated the bus to accept a prebuilt command #4

Merged
merged 1 commit into from
Dec 9, 2016
Merged
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
3 changes: 3 additions & 0 deletions src/Bus.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ protected function resolveMiddleware(array $middleware)
*/
protected function mapInputToCommand($command, $input)
{
if (is_object($command)) {
return $command;
}
$dependencies = [];
$class = new ReflectionClass($command);
foreach ($class->getConstructor()->getParameters() as $parameter) {
Expand Down
9 changes: 9 additions & 0 deletions tests/Bus/TestBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ public function test_it_handles_a_command()
$this->assertInstanceOf('Joselfonseca\LaravelTactician\Tests\Stubs\TestCommand', $bus->dispatch('Joselfonseca\LaravelTactician\Tests\Stubs\TestCommand', [], []));
}


public function test_it_accepts_prebuilt_command_objects()
{
$bus = app('Joselfonseca\LaravelTactician\CommandBusInterface');
$bus->addHandler('Joselfonseca\LaravelTactician\Tests\Stubs\TestCommand',
'Joselfonseca\LaravelTactician\Tests\Stubs\TestCommandHandler');
$this->assertInstanceOf('Joselfonseca\LaravelTactician\Tests\Stubs\TestCommand', $bus->dispatch(app('Joselfonseca\LaravelTactician\Tests\Stubs\TestCommand'), [], []));
}

/**
* Test if a a middleware can be applied to the stack
*/
Expand Down