Skip to content

Commit dc86665

Browse files
committed
Add tests for command bus
1 parent c70b64d commit dc86665

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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() {} }

src/Laracasts/Commander/DefaultCommandBus.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ function __construct(Application $app, CommandTranslator $commandTranslator)
4141
public function decorate($className)
4242
{
4343
$this->decorators[] = $className;
44+
45+
return $this;
4446
}
4547

4648
/**

0 commit comments

Comments
 (0)