|
8 | 8 | use Prophecy\Argument;
|
9 | 9 | use Prophecy\PhpUnit\ProphecyTrait;
|
10 | 10 | use Symfony\Component\Messenger\Envelope;
|
| 11 | +use Symfony\Component\Messenger\Exception\TransportException; |
11 | 12 | use Symfony\Component\Messenger\MessageBusInterface;
|
12 | 13 | use Yokai\Batch\BatchStatus;
|
13 | 14 | use Yokai\Batch\Bridge\Symfony\Messenger\DispatchMessageJobLauncher;
|
@@ -81,4 +82,30 @@ static function ($message): bool {
|
81 | 82 | self::assertSame('123456789', $jobExecutionFromStorage->getId());
|
82 | 83 | self::assertSame(BatchStatus::PENDING, $jobExecutionFromStorage->getStatus()->getValue());
|
83 | 84 | }
|
| 85 | + |
| 86 | + public function testLaunchAndMessengerFail(): void |
| 87 | + { |
| 88 | + $messageBus = $this->prophesize(MessageBusInterface::class); |
| 89 | + $messageBus->dispatch(Argument::any()) |
| 90 | + ->shouldBeCalled() |
| 91 | + ->willThrow(new TransportException('This is a test')); |
| 92 | + |
| 93 | + $jobLauncher = new DispatchMessageJobLauncher( |
| 94 | + new JobExecutionFactory(new UniqidJobExecutionIdGenerator()), |
| 95 | + $storage = new InMemoryJobExecutionStorage(), |
| 96 | + $messageBus->reveal() |
| 97 | + ); |
| 98 | + |
| 99 | + $jobExecutionFromLauncher = $jobLauncher->launch('testing'); |
| 100 | + |
| 101 | + [$jobExecutionFromStorage] = $storage->getExecutions(); |
| 102 | + self::assertSame($jobExecutionFromLauncher, $jobExecutionFromStorage); |
| 103 | + |
| 104 | + self::assertSame('testing', $jobExecutionFromStorage->getJobName()); |
| 105 | + self::assertSame(BatchStatus::FAILED, $jobExecutionFromStorage->getStatus()->getValue()); |
| 106 | + self::assertCount(1, $jobExecutionFromStorage->getFailures()); |
| 107 | + $failure = $jobExecutionFromStorage->getFailures()[0]; |
| 108 | + self::assertSame(TransportException::class, $failure->getClass()); |
| 109 | + self::assertSame('This is a test', $failure->getMessage()); |
| 110 | + } |
84 | 111 | }
|
0 commit comments