repository = $this->createMock(DispositionRepository::class); $entityManager = $this->createMock(EntityManagerInterface::class); $entityManager ->method('getRepository') ->willReturn($this->repository) ; $this->service = new DispositionStatusService($entityManager, new NullLogger()); } public function testANormalPlacementEnds(): void { $disposition = $this->createDisposition(skipFormalities: false); $this->givenEndedDispositions($disposition); $this->service->setEndedStatus(); $this->assertSame(Disposition::STATUS_ENDED, $disposition->getStatus()); } public function testASkipFormalitiesPlacementIsCompletedInsteadOfEnded(): void { $disposition = $this->createDisposition(skipFormalities: true); $this->givenEndedDispositions($disposition); $this->service->setEndedStatus(); $this->assertSame(Disposition::STATUS_COMPLETED, $disposition->getStatus()); } /** * Both kinds come out of the same query, so the split has to happen per disposition. */ public function testAMixedBatchIsSplitPerDisposition(): void { $normal = $this->createDisposition(skipFormalities: false); $skipped = $this->createDisposition(skipFormalities: true); $this->givenEndedDispositions($normal, $skipped); $this->service->setEndedStatus(); $this->assertSame(Disposition::STATUS_ENDED, $normal->getStatus()); $this->assertSame(Disposition::STATUS_COMPLETED, $skipped->getStatus()); } public function testNothingIsFlushedWhenThereIsNothingToEnd(): void { $this->givenEndedDispositions(); $this->assertSame('No ended dispositions to update', $this->service->setEndedStatus()); } private function givenEndedDispositions(Disposition ...$dispositions): void { $this->repository ->method('findEndedDispositions') ->willReturn($dispositions) ; } private function createDisposition(bool $skipFormalities): Disposition { $assignment = (new Assignment())->setSkipFormalities($skipFormalities); return new Disposition(new Application($assignment, new Teamer())); } }