Files
dataflow-bundle/Tests/Runner/PendingDataflowRunnerTest.php
AUDUL 4e82b114c4 Add auto update count processed item while running job (#79)
* Add auto update count processed item while running job
2025-10-02 15:22:37 +02:00

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();
}
}