repository = $this->createMock(JobRepository::class); $this->registry = $this->createMock(DataflowTypeRegistryInterface::class); $this->dispatcher = $this->createMock(EventDispatcherInterface::class); $this->jobGateway = $this->createMock(JobGateway::class); $this->processor = new JobProcessor($this->repository, $this->registry, $this->dispatcher, $this->jobGateway); } public function testProcess() { $now = new \DateTimeImmutable(); $job = (new Job()) ->setStatus(Job::STATUS_PENDING) ->setDataflowType($type = 'type') ->setOptions($options = ['option1' => 'value1']) ; $matcher = $this->exactly(2); $this->dispatcher ->expects($matcher) ->method('dispatch') ->with( $this->callback(fn($arg) => $arg instanceof ProcessingEvent && $arg->getJob() === $job), $this->callback(fn($arg) => match ($matcher->numberOfInvocations()) { 1 => $arg === Events::BEFORE_PROCESSING, 2 => $arg === Events::AFTER_PROCESSING, default => false, }) ); $dataflowType = $this->createMock(DataflowTypeInterface::class); $this->registry ->expects($this->once()) ->method('getDataflowType') ->with($type) ->willReturn($dataflowType) ; $bag = [new \Exception('message1')]; $result = new Result('name', new \DateTimeImmutable(), $end = new \DateTimeImmutable(), $count = 10, $bag); $dataflowType ->expects($this->once()) ->method('process') ->with($options) ->willReturn($result) ; $this->jobGateway ->expects($this->exactly(2)) ->method('save') ; $this->processor->process($job); $this->assertGreaterThanOrEqual($now, $job->getStartTime()); $this->assertSame(Job::STATUS_COMPLETED, $job->getStatus()); $this->assertSame($end, $job->getEndTime()); $this->assertSame($count - count($bag), $job->getCount()); } }