From c13542879f5cd08973f777861df2a8250509346d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20Eugon=C3=A9?= Date: Fri, 16 Jul 2021 10:04:52 +0200 Subject: [PATCH] Implemented a job that triggers other jobs based on user defined schedule rules (#25) * Create BufferingJobLauncher to ease testing classes using a job launcher * Implemented a job that triggers other jobs based on schedules * Provide JobExecution to schedulers so it can look for some context to decide * Add comments to schedule components --- tests/LaunchJobMessageHandlerTest.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/LaunchJobMessageHandlerTest.php b/tests/LaunchJobMessageHandlerTest.php index 109fcb0..f43dc77 100644 --- a/tests/LaunchJobMessageHandlerTest.php +++ b/tests/LaunchJobMessageHandlerTest.php @@ -5,24 +5,26 @@ namespace Yokai\Batch\Tests\Bridge\Symfony\Messenger; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Yokai\Batch\Bridge\Symfony\Messenger\LaunchJobMessage; use Yokai\Batch\Bridge\Symfony\Messenger\LaunchJobMessageHandler; -use Yokai\Batch\JobExecution; -use Yokai\Batch\Launcher\JobLauncherInterface; +use Yokai\Batch\Test\Factory\SequenceJobExecutionIdGenerator; +use Yokai\Batch\Test\Launcher\BufferingJobLauncher; final class LaunchJobMessageHandlerTest extends TestCase { - use ProphecyTrait; - public function testInvoke(): void { - $jobLauncher = $this->prophesize(JobLauncherInterface::class); - $jobLauncher->launch('foo', ['bar' => 'BAR']) - ->shouldBeCalled() - ->willReturn(JobExecution::createRoot('123456', 'foo')); + $launcher = new BufferingJobLauncher(new SequenceJobExecutionIdGenerator(['123456'])); - $handler = new LaunchJobMessageHandler($jobLauncher->reveal()); + $handler = new LaunchJobMessageHandler($launcher); $handler->__invoke(new LaunchJobMessage('foo', ['bar' => 'BAR'])); + + self::assertCount(1, $launcher->getExecutions()); + self::assertSame('foo', $launcher->getExecutions()[0]->getJobName()); + self::assertSame('123456', $launcher->getExecutions()[0]->getId()); + self::assertSame( + ['bar' => 'BAR', '_id' => '123456'], + \iterator_to_array($launcher->getExecutions()[0]->getParameters()->getIterator()) + ); } }