Skip to content

Commit

Permalink
Merge pull request #47 from thephpleague/tests
Browse files Browse the repository at this point in the history
Improve tests
  • Loading branch information
sagikazarmark committed Oct 30, 2016
2 parents 849169d + 7c5bce5 commit d693866
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
22 changes: 10 additions & 12 deletions spec/QueueMiddlewareSpec.php
Expand Up @@ -8,6 +8,7 @@
use League\Tactician\Bernard\QueueMiddleware;
use League\Tactician\Middleware;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

final class QueueMiddlewareSpec extends ObjectBehavior
{
Expand All @@ -30,22 +31,19 @@ function it_executes_a_command(Producer $producer, Message $command)
{
$producer->produce($command)->shouldBeCalled();

$this->execute(
$command,
function () {}
);
$this->execute($command, function () {});
}

function it_executes_invokes_the_next_middleware(Producer $producer, Middleware $middleware, Command $command)
{
$producer->produce($command)->shouldNotBeCalled();
$next = function () {};
$middleware->execute($command, $next)->willReturn(true);

$middleware->execute($command, Argument::type('callable'))->shouldBeCalled();

$this->execute(
$command,
function ($command) use ($middleware, $next) {
return $middleware->execute($command, $next);
function ($command) use ($middleware) {
return $middleware->getWrappedObject()->execute($command, function () {});
}
);
}
Expand All @@ -54,13 +52,13 @@ function it_unwraps_a_command(Producer $producer, Message $command, Middleware $
{
$queuedCommand = new QueuedCommand($command->getWrappedObject());
$producer->produce($command)->shouldNotBeCalled();
$next = function () {};
$middleware->execute($command, $next)->willReturn(true);

$middleware->execute($command, Argument::type('callable'))->shouldBeCalled();

$this->execute(
$queuedCommand,
function ($command) use ($middleware, $next) {
return $middleware->execute($command, $next);
function ($command) use ($middleware) {
return $middleware->getWrappedObject()->execute($command, function () {});
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion spec/QueuedCommandSpec.php
Expand Up @@ -18,7 +18,7 @@ function it_is_initializable()
$this->shouldHaveType(QueuedCommand::class);
}

function it_has_a_queueable_command(Message $command)
function it_has_a_command_from_the_queue(Message $command)
{
$this->getCommand()->shouldReturn($command);
}
Expand Down
10 changes: 5 additions & 5 deletions spec/Receiver/SameBusReceiverSpec.php
Expand Up @@ -24,20 +24,20 @@ function it_is_initializable()

function it_is_a_receiver()
{
$this->shouldImplement(Receiver::class);
$this->shouldHaveType(Receiver::class);
}

function it_handles_a_message(CommandBus $commandBus, Message $command)
{
$commandBus->handle(Argument::type(QueuedCommand::class))->willReturn(true);
$commandBus->handle(Argument::type(QueuedCommand::class))->shouldBeCalled();

$this->handle($command)->shouldReturn(true);
$this->handle($command);
}

function it_is_invokable(CommandBus $commandBus, Message $command)
{
$commandBus->handle(Argument::type(QueuedCommand::class))->willReturn(true);
$commandBus->handle(Argument::type(QueuedCommand::class))->shouldBeCalled();

$this->__invoke($command)->shouldReturn(true);
$this->__invoke($command);
}
}
10 changes: 5 additions & 5 deletions spec/Receiver/SeparateBusReceiverSpec.php
Expand Up @@ -22,20 +22,20 @@ function it_is_initializable()

function it_is_a_receiver()
{
$this->shouldImplement(Receiver::class);
$this->shouldHaveType(Receiver::class);
}

function it_handles_a_message(CommandBus $commandBus, Message $command)
{
$commandBus->handle($command)->willReturn(true);
$commandBus->handle($command)->shouldBeCalled();

$this->handle($command)->shouldReturn(true);
$this->handle($command);
}

function it_is_invokable(CommandBus $commandBus, Message $command)
{
$commandBus->handle($command)->willReturn(true);
$commandBus->handle($command)->shouldBeCalled();

$this->__invoke($command)->shouldReturn(true);
$this->__invoke($command);
}
}

0 comments on commit d693866

Please sign in to comment.