diff --git a/src/Symfony/Component/Messenger/AbstractMessageBusDecorator.php b/src/Symfony/Component/Messenger/AbstractMessageBusDecorator.php new file mode 100644 index 0000000000000..30149cb0ad787 --- /dev/null +++ b/src/Symfony/Component/Messenger/AbstractMessageBusDecorator.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Messenger; + +/** + * A decorated message bus. + * + * Use this abstract class to create your message bus decorator to specialise your + * bus instances and type-hint against them. + * + * @author Samuel Roze + */ +abstract class AbstractMessageBusDecorator implements MessageBusInterface +{ + private $decoratedBus; + + public function __construct(MessageBusInterface $decoratedBus) + { + $this->decoratedBus = $decoratedBus; + } + + /** + * {@inheritdoc} + */ + public function dispatch($message) + { + return $this->decoratedBus->dispatch($message); + } +} diff --git a/src/Symfony/Component/Messenger/Tests/AbstractMessageBusDecoratorTest.php b/src/Symfony/Component/Messenger/Tests/AbstractMessageBusDecoratorTest.php new file mode 100644 index 0000000000000..17711366d6429 --- /dev/null +++ b/src/Symfony/Component/Messenger/Tests/AbstractMessageBusDecoratorTest.php @@ -0,0 +1,34 @@ + + * + * 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\AbstractMessageBusDecorator; +use Symfony\Component\Messenger\MessageBusInterface; +use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage; + +class AbstractMessageBusDecoratorTest extends TestCase +{ + public function testItCanBeExtendedAndProxiesTheMessagesToTheBus() + { + $message = new DummyMessage('Foo'); + + $bus = $this->getMockBuilder(MessageBusInterface::class)->getMock(); + $bus->expects($this->once())->method('dispatch')->with($message)->willReturn('bar'); + + $this->assertSame('bar', (new CommandBus($bus))->dispatch($message)); + } +} + +class CommandBus extends AbstractMessageBusDecorator +{ +}