|
7 | 7 | use PHPUnit\Framework\TestCase;
|
8 | 8 | use Prophecy\Argument;
|
9 | 9 | use Prophecy\PhpUnit\ProphecyTrait;
|
10 |
| -use Prophecy\Prophecy\ObjectProphecy; |
11 | 10 | use Symfony\Component\Messenger\Envelope;
|
12 | 11 | use Symfony\Component\Messenger\MessageBusInterface;
|
13 | 12 | use Yokai\Batch\BatchStatus;
|
|
17 | 16 | use Yokai\Batch\Factory\UniqidJobExecutionIdGenerator;
|
18 | 17 | use Yokai\Batch\JobExecution;
|
19 | 18 | use Yokai\Batch\Storage\JobExecutionStorageInterface;
|
| 19 | +use Yokai\Batch\Test\Factory\SequenceJobExecutionIdGenerator; |
20 | 20 |
|
21 | 21 | final class DispatchMessageJobLauncherTest extends TestCase
|
22 | 22 | {
|
@@ -63,4 +63,44 @@ static function ($message): bool {
|
63 | 63 | $jobLauncher->launch('testing', ['_id' => '123456789', 'foo' => ['bar']])
|
64 | 64 | );
|
65 | 65 | }
|
| 66 | + |
| 67 | + public function testLaunchWithNoId(): void |
| 68 | + { |
| 69 | + $storage = $this->prophesize(JobExecutionStorageInterface::class); |
| 70 | + $jobExecutionAssertions = Argument::that( |
| 71 | + static function ($jobExecution): bool { |
| 72 | + return $jobExecution instanceof JobExecution |
| 73 | + && $jobExecution->getJobName() === 'testing' |
| 74 | + && $jobExecution->getId() === '123456789'; |
| 75 | + } |
| 76 | + ); |
| 77 | + $storage->store($jobExecutionAssertions) |
| 78 | + ->shouldBeCalled(); |
| 79 | + $storage->retrieve('testing', '123456789') |
| 80 | + ->shouldBeCalled() |
| 81 | + ->willReturn($jobExecution = JobExecution::createRoot('123456789-refreshed', 'testing')); |
| 82 | + |
| 83 | + $messageBus = $this->prophesize(MessageBusInterface::class); |
| 84 | + $messageAssertions = Argument::that( |
| 85 | + static function ($message): bool { |
| 86 | + return $message instanceof LaunchJobMessage |
| 87 | + && $message->getJobName() === 'testing' |
| 88 | + && $message->getConfiguration() === ['_id' => '123456789']; |
| 89 | + } |
| 90 | + ); |
| 91 | + $messageBus->dispatch($messageAssertions) |
| 92 | + ->shouldBeCalled() |
| 93 | + ->willReturn(new Envelope(new LaunchJobMessage('unused'))); |
| 94 | + |
| 95 | + $jobLauncher = new DispatchMessageJobLauncher( |
| 96 | + new JobExecutionFactory(new SequenceJobExecutionIdGenerator(['123456789'])), |
| 97 | + $storage->reveal(), |
| 98 | + $messageBus->reveal() |
| 99 | + ); |
| 100 | + |
| 101 | + self::assertSame( |
| 102 | + $jobExecution, |
| 103 | + $jobLauncher->launch('testing') |
| 104 | + ); |
| 105 | + } |
66 | 106 | }
|
0 commit comments