Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Messenger] Added more test for MessageBus #32338

Merged
merged 1 commit into from Jul 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/Symfony/Component/Messenger/Tests/MessageBusTest.php
Expand Up @@ -16,6 +16,7 @@
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;
Expand Down Expand Up @@ -148,4 +149,44 @@ public function testItAddsTheStampsToEnvelope()
$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;
}
}