|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\Laracasts\Commander; |
| 4 | + |
| 5 | +use Laracasts\Commander\BasicCommandTranslator; |
| 6 | +use Laracasts\Commander\CommandBus; |
| 7 | +use PhpSpec\ObjectBehavior; |
| 8 | +use Prophecy\Argument; |
| 9 | +use Illuminate\Foundation\Application; |
| 10 | +use Laracasts\Commander\CommandTranslator; |
| 11 | + |
| 12 | +class DefaultCommandBusSpec extends ObjectBehavior { |
| 13 | + |
| 14 | + function let(Application $app, CommandTranslator $translator) |
| 15 | + { |
| 16 | + $this->beConstructedWith($app, $translator); |
| 17 | + } |
| 18 | + |
| 19 | + function xit_is_initializable() |
| 20 | + { |
| 21 | + $this->shouldHaveType('Laracasts\Commander\DefaultCommandBus'); |
| 22 | + } |
| 23 | + |
| 24 | + function xit_handles_a_command(Application $app, CommandStub $command, CommandTranslator $translator, CommandHandlerStub $handler) |
| 25 | + { |
| 26 | + $translator->toCommandHandler($command)->willReturn('CommandHandler'); |
| 27 | + $app->make('CommandHandler')->willReturn($handler); |
| 28 | + $handler->handle($command)->shouldBeCalled(); |
| 29 | + |
| 30 | + $this->execute($command); |
| 31 | + } |
| 32 | + |
| 33 | + function it_can_trigger_decorators_before_calling_the_handler(Application $app, CommandStub $command, CommandTranslator $translator, CommandHandlerStub $handler) |
| 34 | + { |
| 35 | + $translator->toCommandHandler($command)->willReturn('CommandHandler'); |
| 36 | + $app->make('CommandHandler')->willReturn($handler); |
| 37 | + $handler->handle($command)->shouldBeCalled(); |
| 38 | + |
| 39 | + // If we specify a decorator before calling execute(), that decorator should be |
| 40 | + // resolved out of the container and executed first. |
| 41 | + $decorator = 'spec\Laracasts\Commander\CommandBusDecoratorStub'; |
| 42 | + $app->make($decorator)->shouldBeCalled()->willReturn(new CommandBusDecoratorStub); |
| 43 | + |
| 44 | + $this->decorate($decorator)->execute($command); |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +} |
| 50 | + |
| 51 | +// Stub Stuff |
| 52 | +class CommandStub {} |
| 53 | +class CommandHandlerStub { public function handle($command) {} } |
| 54 | +class CommandBusDecoratorStub implements \Laracasts\Commander\CommandBus { public function execute($command) {} } |
| 55 | + |
| 56 | +namespace Illuminate\Foundation; |
| 57 | +class Application { function make() {} } |
0 commit comments