Skip to content

Commit

Permalink
Implemented a job that triggers other jobs based on user defined sche…
Browse files Browse the repository at this point in the history
…dule 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
  • Loading branch information
yann-eugone authored Jul 16, 2021
1 parent 741875e commit c135428
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions tests/LaunchJobMessageHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
}
}

0 comments on commit c135428

Please sign in to comment.