[Messenger] Added more test for MessageBus

This commit is contained in:
Grégoire Pineau 2019-07-03 14:56:57 +02:00
parent 6bf5d8fce3
commit 5f4ab23991

View File

@ -16,6 +16,7 @@ use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBus;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
use Symfony\Component\Messenger\Middleware\StackInterface;
use Symfony\Component\Messenger\Stamp\BusNameStamp;
use Symfony\Component\Messenger\Stamp\DelayStamp;
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
@ -148,4 +149,44 @@ class MessageBusTest extends TestCase
$finalEnvelope = (new MessageBus())->dispatch(new Envelope(new \stdClass()), [new DelayStamp(5), new BusNameStamp('bar')]);
$this->assertCount(2, $finalEnvelope->all());
}
public function provideConstructorDataStucture()
{
yield 'iterator' => [new \ArrayObject([
new SimpleMiddleware(),
new SimpleMiddleware(),
])];
yield 'array' => [[
new SimpleMiddleware(),
new SimpleMiddleware(),
]];
yield 'generator' => [(function (): \Generator {
yield new SimpleMiddleware();
yield new SimpleMiddleware();
})()];
}
/** @dataProvider provideConstructorDataStucture */
public function testConstructDataStructure($dataStructure)
{
$bus = new MessageBus($dataStructure);
$envelope = new Envelope(new DummyMessage('Hello'));
$newEnvelope = $bus->dispatch($envelope);
$this->assertSame($envelope->getMessage(), $newEnvelope->getMessage());
// Test rewindable capacity
$envelope = new Envelope(new DummyMessage('Hello'));
$newEnvelope = $bus->dispatch($envelope);
$this->assertSame($envelope->getMessage(), $newEnvelope->getMessage());
}
}
class SimpleMiddleware implements MiddlewareInterface
{
public function handle(Envelope $envelope, StackInterface $stack): Envelope
{
return $envelope;
}
}