Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/Symfony/Component/Messenger/AbstractMessageBusDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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;

/**
* 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 <samuel.roze@gmail.com>
*/
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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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\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
{
}