This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Messenger/Tests/MessageBusTest.php

56 lines
1.7 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Messenger\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\MessageBus;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
class MessageBusTest extends TestCase
{
public function testItHasTheRightInterface()
{
$bus = new MessageBus();
$this->assertInstanceOf(MessageBusInterface::class, $bus);
}
public function testItCallsTheMiddlewaresAndChainTheReturnValue()
{
$message = new DummyMessage('Hello');
$responseFromDepthMiddleware = 1234;
2018-03-13 16:34:51 +00:00
$firstMiddleware = $this->getMockBuilder(MiddlewareInterface::class)->getMock();
$firstMiddleware->expects($this->once())
->method('handle')
->with($message, $this->anything())
2018-03-13 16:34:51 +00:00
->will($this->returnCallback(function ($message, $next) {
return $next($message);
}));
2018-03-13 16:34:51 +00:00
$secondMiddleware = $this->getMockBuilder(MiddlewareInterface::class)->getMock();
$secondMiddleware->expects($this->once())
->method('handle')
->with($message, $this->anything())
->willReturn($responseFromDepthMiddleware);
2018-03-13 16:34:51 +00:00
$bus = new MessageBus(array(
$firstMiddleware,
$secondMiddleware,
2018-03-13 16:34:51 +00:00
));
$this->assertEquals($responseFromDepthMiddleware, $bus->dispatch($message));
}
}