Skip to content

Commit

Permalink
Merge pull request #2 from cherifGsoul/remove_bootstraping
Browse files Browse the repository at this point in the history
change middleware registration
  • Loading branch information
Mohamed Cherif Bouchelaghem committed Sep 14, 2015
2 parents 39d2941 + 02e866d commit 377166f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
11 changes: 6 additions & 5 deletions Tactician.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ protected function buildTactician()

$this->registerMiddleware($handlerMiddleware);

$this->tactician = Yii::createObject('League\Tactician\CommandBus',[
$this->middlewares
]
);
}


Expand All @@ -57,7 +53,12 @@ public function registerMiddleware($middleware)
public function handle( $command )
{
Yii::trace(sprintf('Handle command class for %s', get_class( $command ) ) );
return $this->tactician->handle( $command );

$tactician = Yii::createObject('League\Tactician\CommandBus',[
$this->middlewares
]
);
return $tactician->handle( $command );
}

public function getMiddlewares()
Expand Down
19 changes: 4 additions & 15 deletions tests/TacticianTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ protected function setUp()
* @test
*/
public function should_handle_command()
{

{
$this->assertEquals(
'foobar',
$this->_commandBus->handle(new CompleteTaskCommand())
Expand All @@ -34,26 +33,16 @@ public function should_handle_command()
*/
public function should_register_middleware_to_be_executed()
{
$middleware = $this->getMock(Middleware::class,array('execute'));


$middleware->expects($this->any())
->method('execute')
->will($this->returnValue('Heelo'));
$middleware = $this->getMock('League\Tactician\Middleware');

$this->_commandBus->registerMiddleware($middleware);

$tactician = $this->_commandBus->getTactician();

$this->assertEquals(2,count($this->_commandBus->middlewares));

$this->assertEquals(
'foobar',
$this->_commandBus->handle(new CompleteTaskCommand())
);

$this->assertEquals(
'foobar',
$tactician->handle(new CompleteTaskCommand())
);
}


Expand Down

0 comments on commit 377166f

Please sign in to comment.