|
16 | 16 | use Symfony\Component\Messenger\MessageBus;
|
17 | 17 | use Symfony\Component\Messenger\MessageBusInterface;
|
18 | 18 | use Symfony\Component\Messenger\Middleware\MiddlewareInterface;
|
| 19 | +use Symfony\Component\Messenger\Middleware\StackInterface; |
19 | 20 | use Symfony\Component\Messenger\Stamp\BusNameStamp;
|
20 | 21 | use Symfony\Component\Messenger\Stamp\DelayStamp;
|
21 | 22 | use Symfony\Component\Messenger\Stamp\ReceivedStamp;
|
@@ -148,4 +149,44 @@ public function testItAddsTheStampsToEnvelope()
|
148 | 149 | $finalEnvelope = (new MessageBus())->dispatch(new Envelope(new \stdClass()), [new DelayStamp(5), new BusNameStam
8000
p('bar')]);
|
149 | 150 | $this->assertCount(2, $finalEnvelope->all());
|
150 | 151 | }
|
| 152 | + |
| 153 | + public function provideConstructorDataStucture() |
| 154 | + { |
| 155 | + yield 'iterator' => [new \ArrayObject([ |
| 156 | + new SimpleMiddleware(), |
| 157 | + new SimpleMiddleware(), |
| 158 | + ])]; |
| 159 | + |
| 160 | + yield 'array' => [[ |
| 161 | + new SimpleMiddleware(), |
| 162 | + new SimpleMiddleware(), |
| 163 | + ]]; |
| 164 | + |
| 165 | + yield 'generator' => [(function (): \Generator { |
| 166 | + yield new SimpleMiddleware(); |
| 167 | + yield new SimpleMiddleware(); |
| 168 | + })()]; |
| 169 | + } |
| 170 | + |
| 171 | + /** @dataProvider provideConstructorDataStucture */ |
| 172 | + public function testConstructDataStructure($dataStructure) |
| 173 | + { |
| 174 | + $bus = new MessageBus($dataStructure); |
| 175 | + $envelope = new Envelope(new DummyMessage('Hello')); |
| 176 | + $newEnvelope = $bus->dispatch($envelope); |
| 177 | + $this->assertSame($envelope->getMessage(), $newEnvelope->getMessage()); |
| 178 | + |
| 179 | + // Test rewindable capacity |
| 180 | + $envelope = new Envelope(new DummyMessage('Hello')); |
| 181 | + $newEnvelope = $bus->dispatch($envelope); |
| 182 | + $this->assertSame($envelope->getMessage(), $newEnvelope->getMessage()); |
| 183 | + } |
| 184 | +} |
| 185 | + |
| 186 | +class SimpleMiddleware implements MiddlewareInterface |
| 187 | +{ |
| 188 | + public function handle(Envelope $envelope, StackInterface $stack): Envelope |
| 189 | + { |
| 190 | + return $envelope; |
| 191 | + } |
151 | 192 | }
|
0 commit comments