mirror of
https://github.com/code-rhapsodie/dataflow-bundle.git
synced 2026-03-26 07:42:13 +01:00
51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace CodeRhapsodie\DataflowBundle\Tests\Runner;
|
|
|
|
use CodeRhapsodie\DataflowBundle\Entity\Job;
|
|
use CodeRhapsodie\DataflowBundle\Processor\JobProcessorInterface;
|
|
use CodeRhapsodie\DataflowBundle\Repository\JobRepository;
|
|
use CodeRhapsodie\DataflowBundle\Runner\PendingDataflowRunner;
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class PendingDataflowRunnerTest extends TestCase
|
|
{
|
|
private PendingDataflowRunner $runner;
|
|
private JobRepository|MockObject $repository;
|
|
private JobProcessorInterface|MockObject $processor;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->repository = $this->createMock(JobRepository::class);
|
|
$this->processor = $this->createMock(JobProcessorInterface::class);
|
|
|
|
$this->runner = new PendingDataflowRunner($this->repository, $this->processor);
|
|
}
|
|
|
|
public function testRunPendingDataflows()
|
|
{
|
|
$job1 = new Job();
|
|
$job2 = new Job();
|
|
|
|
$this->repository
|
|
->expects($this->exactly(3))
|
|
->method('findNextPendingDataflow')
|
|
->willReturnOnConsecutiveCalls($job1, $job2, null)
|
|
;
|
|
|
|
$matcher = $this->exactly(2);
|
|
$this->processor
|
|
->expects($matcher)
|
|
->method('process')
|
|
->with($this->callback(fn($arg) => match ($matcher->numberOfInvocations()) {
|
|
1 => $arg === $job1,
|
|
2 => $arg === $job2,
|
|
default => false,
|
|
}))
|
|
;
|
|
|
|
$this->runner->runPendingDataflows();
|
|
}
|
|
}
|