Skip to content

Commit

Permalink
Merge 6f2f7df into 5d8dc8c
Browse files Browse the repository at this point in the history
  • Loading branch information
bursonic committed Nov 7, 2016
2 parents 5d8dc8c + 6f2f7df commit 0475665
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
@@ -1,13 +1,16 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm

matrix:
include:
- php: 5.4
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
- php: 5.5
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": ">=5.5"
"php": ">=5.4"
},
"require-dev": {
"mockery/mockery": "~0.9",
Expand Down
2 changes: 1 addition & 1 deletion examples/1-beginner-standard-usage.php
Expand Up @@ -23,7 +23,7 @@ public function handleRegisterUserCommand(RegisterUserCommand $command)

// Setup the bus, normally in your DI container ///////////////////////////////
$locator = new InMemoryLocator();
$locator->addHandler(new RegisterUserHandler(), RegisterUserCommand::class);
$locator->addHandler(new RegisterUserHandler(), 'RegisterUserCommand');

// Middleware is Tactician's plugin system. Even finding the handler and
// executing it is a plugin that we're configuring here.
Expand Down
2 changes: 1 addition & 1 deletion examples/3-intermediate-custom-naming-conventions.php
Expand Up @@ -38,7 +38,7 @@ public function handle($command)

// Now let's recreate our CommandHandlerMiddleware again but with the naming scheme
// we prefer to use!
$locator->addHandler(new NewRegisterUserHandler(), RegisterUserCommand::class);
$locator->addHandler(new NewRegisterUserHandler(), 'RegisterUserCommand');
$handlerMiddleware = new CommandHandlerMiddleware(new ClassNameExtractor(), $locator, new MyCustomInflector());

$commandBus = new CommandBus([$handlerMiddleware]);
Expand Down
2 changes: 1 addition & 1 deletion examples/repeated-sample-code.php
Expand Up @@ -23,7 +23,7 @@ public function handleRegisterUserCommand(RegisterUserCommand $command)
}

$locator = new InMemoryLocator();
$locator->addHandler(new RegisterUserHandler(), RegisterUserCommand::class);
$locator->addHandler(new RegisterUserHandler(), 'RegisterUserCommand');

$handlerMiddleware = new League\Tactician\Handler\CommandHandlerMiddleware(
new ClassNameExtractor(),
Expand Down
8 changes: 4 additions & 4 deletions tests/CommandBusTest.php
Expand Up @@ -12,23 +12,23 @@ public function testAllMiddlewareAreExecutedAndReturnValuesAreRespected()
{
$executionOrder = [];

$middleware1 = Mockery::mock(Middleware::class);
$middleware1 = Mockery::mock('League\\Tactician\\Middleware');
$middleware1->shouldReceive('execute')->andReturnUsing(
function ($command, $next) use (&$executionOrder) {
$executionOrder[] = 1;
return $next($command);
}
);

$middleware2 = Mockery::mock(Middleware::class);
$middleware2 = Mockery::mock('League\\Tactician\\Middleware');
$middleware2->shouldReceive('execute')->andReturnUsing(
function ($command, $next) use (&$executionOrder) {
$executionOrder[] = 2;
return $next($command);
}
);

$middleware3 = Mockery::mock(Middleware::class);
$middleware3 = Mockery::mock('League\\Tactician\\Middleware');
$middleware3->shouldReceive('execute')->andReturnUsing(
function () use (&$executionOrder) {
$executionOrder[] = 3;
Expand All @@ -44,7 +44,7 @@ function () use (&$executionOrder) {

public function testSingleMiddlewareWorks()
{
$middleware = Mockery::mock(Middleware::class);
$middleware = Mockery::mock('League\\Tactician\\Middleware');
$middleware->shouldReceive('execute')->once()->andReturn('foobar');

$commandBus = new CommandBus([$middleware]);
Expand Down
5 changes: 2 additions & 3 deletions tests/Exception/CanNotInvokeHandlerExceptionTest.php
Expand Up @@ -3,7 +3,6 @@
namespace League\Tactician\Tests\Exception;

use League\Tactician\Exception\CanNotInvokeHandlerException;
use League\Tactician\Exception\Exception;
use League\Tactician\Tests\Fixtures\Command\CompleteTaskCommand;

class CanNotInvokeHandlerExceptionTest extends \PHPUnit_Framework_TestCase
Expand All @@ -14,10 +13,10 @@ public function testExceptionContainsDebuggingInfo()

$exception = CanNotInvokeHandlerException::forCommand($command, 'Because stuff');

$this->assertContains(CompleteTaskCommand::class, $exception->getMessage());
$this->assertContains(get_class($command), $exception->getMessage());
$this->assertContains('Because stuff', $exception->getMessage());
$this->assertSame($command, $exception->getCommand());
$this->assertInstanceOf(Exception::class, $exception);
$this->assertInstanceOf('League\\Tactician\\Exception\\Exception', $exception);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions tests/Exception/InvalidCommandExceptionTest.php
Expand Up @@ -3,7 +3,6 @@
namespace League\Tactician\Tests\Exception;

use League\Tactician\Exception\InvalidCommandException;
use League\Tactician\Exception\Exception;

class InvalidCommandExceptionTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -15,6 +14,6 @@ public function testExceptionContainsDebuggingInfo()

$this->assertContains('type: string', $exception->getMessage());
$this->assertSame($command, $exception->getInvalidCommand());
$this->assertInstanceOf(Exception::class, $exception);
$this->assertInstanceOf('League\\Tactician\\Exception\\Exception', $exception);
}
}
12 changes: 6 additions & 6 deletions tests/Exception/MissingHandlerExceptionTest.php
Expand Up @@ -3,17 +3,17 @@
namespace League\Tactician\Tests\Exception;

use League\Tactician\Exception\MissingHandlerException;
use League\Tactician\Tests\Fixtures\Command\CompleteTaskCommand;
use League\Tactician\Exception\Exception;

class MissingHandlerExceptionTest extends \PHPUnit_Framework_TestCase
{
const FIXTURE_COMMAND_CLASS = 'League\\Tactician\\Tests\\Fixtures\\Command\\CompleteTaskCommand';

public function testExceptionContainsDebuggingInfo()
{
$exception = MissingHandlerException::forCommand(CompleteTaskCommand::class);
$exception = MissingHandlerException::forCommand(self::FIXTURE_COMMAND_CLASS);

$this->assertContains(CompleteTaskCommand::class, $exception->getMessage());
$this->assertSame(CompleteTaskCommand::class, $exception->getCommandName());
$this->assertInstanceOf(Exception::class, $exception);
$this->assertContains(self::FIXTURE_COMMAND_CLASS, $exception->getMessage());
$this->assertSame(self::FIXTURE_COMMAND_CLASS, $exception->getCommandName());
$this->assertInstanceOf('League\\Tactician\\Exception\\Exception', $exception);
}
}
18 changes: 10 additions & 8 deletions tests/Handler/CommandHandlerMiddlewareTest.php
Expand Up @@ -3,12 +3,10 @@
namespace League\Tactician\Tests\Handler;

use League\Tactician\Handler\CommandHandlerMiddleware;
use League\Tactician\Handler\CommandNameExtractor\CommandNameExtractor;
use League\Tactician\Handler\Locator\HandlerLocator;
use League\Tactician\Handler\MethodNameInflector\MethodNameInflector;
use League\Tactician\Tests\Fixtures\Command\CompleteTaskCommand;
use League\Tactician\Tests\Fixtures\Handler\DynamicMethodsHandler;
use League\Tactician\Tests\Fixtures\Handler\ConcreteMethodsHandler;
use stdClass;
use Mockery;

Expand Down Expand Up @@ -36,9 +34,13 @@ class CommandHandlerMiddlewareTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->commandNameExtractor = Mockery::mock(CommandNameExtractor::class);
$this->handlerLocator = Mockery::mock(HandlerLocator::class);
$this->methodNameInflector = Mockery::mock(MethodNameInflector::class);
$this->commandNameExtractor = Mockery::mock(
'League\\Tactician\\Handler\\CommandNameExtractor\\CommandNameExtractor'
);
$this->handlerLocator = Mockery::mock('League\\Tactician\\Handler\\Locator\\HandlerLocator');
$this->methodNameInflector = Mockery::mock(
'League\\Tactician\\Handler\\MethodNameInflector\\MethodNameInflector'
);

$this->middleware = new CommandHandlerMiddleware(
$this->commandNameExtractor,
Expand All @@ -51,7 +53,7 @@ public function testHandlerIsExecuted()
{
$command = new CompleteTaskCommand();

$handler = Mockery::mock(ConcreteMethodsHandler::class);
$handler = Mockery::mock('League\\Tactician\\Tests\\Fixtures\\Handler\\ConcreteMethodsHandler');
$handler
->shouldReceive('handleCompleteTaskCommand')
->with($command)
Expand All @@ -65,13 +67,13 @@ public function testHandlerIsExecuted()

$this->handlerLocator
->shouldReceive('getHandlerForCommand')
->with(CompleteTaskCommand::class)
->with('League\\Tactician\\Tests\\Fixtures\\Command\\CompleteTaskCommand')
->andReturn($handler);

$this->commandNameExtractor
->shouldReceive('extract')
->with($command)
->andReturn(CompleteTaskCommand::class);
->andReturn('League\\Tactician\\Tests\\Fixtures\\Command\\CompleteTaskCommand');

$this->assertEquals('a-return-value', $this->middleware->execute($command, $this->mockNext()));
}
Expand Down
25 changes: 16 additions & 9 deletions tests/Handler/Locator/InMemoryLocatorTest.php
Expand Up @@ -23,31 +23,36 @@ public function testHandlerIsReturnedForSpecificClass()
{
$handler = new stdClass();

$this->inMemoryLocator->addHandler($handler, CompleteTaskCommand::class);
$this->inMemoryLocator->addHandler(
$handler,
'League\\Tactician\\Tests\\Fixtures\\Command\\CompleteTaskCommand'
);

$this->assertSame(
$handler,
$this->inMemoryLocator->getHandlerForCommand(CompleteTaskCommand::class)
$this->inMemoryLocator->getHandlerForCommand(
'League\\Tactician\\Tests\\Fixtures\\Command\\CompleteTaskCommand'
)
);
}

public function testConstructorAcceptsMapOfCommandClassesToHandlers()
{
$commandToHandlerMap = [
AddTaskCommand::class => new stdClass(),
CompleteTaskCommand::class => new stdClass()
'League\\Tactician\\Tests\\Fixtures\\Command\\AddTaskCommand' => new stdClass(),
'League\\Tactician\\Tests\\Fixtures\\Command\\CompleteTaskCommand' => new stdClass()
];

$locator = new InMemoryLocator($commandToHandlerMap);

$this->assertSame(
$commandToHandlerMap[AddTaskCommand::class],
$locator->getHandlerForCommand(AddTaskCommand::class)
$commandToHandlerMap['League\\Tactician\\Tests\\Fixtures\\Command\\AddTaskCommand'],
$locator->getHandlerForCommand('League\\Tactician\\Tests\\Fixtures\\Command\\AddTaskCommand')
);

$this->assertSame(
$commandToHandlerMap[CompleteTaskCommand::class],
$locator->getHandlerForCommand(CompleteTaskCommand::class)
$commandToHandlerMap['League\\Tactician\\Tests\\Fixtures\\Command\\CompleteTaskCommand'],
$locator->getHandlerForCommand('League\\Tactician\\Tests\\Fixtures\\Command\\CompleteTaskCommand')
);
}

Expand All @@ -56,6 +61,8 @@ public function testConstructorAcceptsMapOfCommandClassesToHandlers()
*/
public function testHandlerMissing()
{
$this->inMemoryLocator->getHandlerForCommand(CompleteTaskCommand::class);
$this->inMemoryLocator->getHandlerForCommand(
'League\\Tactician\\Tests\\Fixtures\\Command\\CompleteTaskCommand'
);
}
}
14 changes: 7 additions & 7 deletions tests/Setup/QuickStartTest.php
Expand Up @@ -2,29 +2,29 @@

namespace League\Tactician\Tests\Setup;

use League\Tactician\CommandBus;
use League\Tactician\Setup\QuickStart;
use League\Tactician\Tests\Fixtures\Command\AddTaskCommand;
use League\Tactician\Tests\Fixtures\Command\CompleteTaskCommand;
use Mockery;

class QuickStartTest extends \PHPUnit_Framework_TestCase
{
public function testReturnsACommandBus()
{
$commandBus = QuickStart::create([]);
$this->assertInstanceOf(CommandBus::class, $commandBus);
$this->assertInstanceOf('League\\Tactician\\CommandBus', $commandBus);
}

public function testCommandToHandlerMapIsProperlyConfigured()
{
$map = [
AddTaskCommand::class => Mockery::mock(ConcreteMethodsHandler::class),
CompleteTaskCommand::class => Mockery::mock(ConcreteMethodsHandler::class),
'League\\Tactician\\Tests\\Fixtures\\Command\\AddTaskCommand'
=> Mockery::mock('League\\Tactician\\Tests\\Fixtures\\Handler\\ConcreteMethodsHandler'),
'League\\Tactician\\Tests\\Fixtures\\Command\\CompleteTaskCommand'
=> Mockery::mock('League\\Tactician\\Tests\\Fixtures\\Handler\\ConcreteMethodsHandler'),
];

$map[AddTaskCommand::class]->shouldReceive('handle')->once();
$map[CompleteTaskCommand::class]->shouldReceive('handle')->never();
$map['League\\Tactician\\Tests\\Fixtures\\Command\\AddTaskCommand']->shouldReceive('handle')->once();
$map['League\\Tactician\\Tests\\Fixtures\\Command\\CompleteTaskCommand']->shouldReceive('handle')->never();

$commandBus = QuickStart::create($map);
$commandBus->handle(new AddTaskCommand());
Expand Down

0 comments on commit 0475665

Please sign in to comment.