entityManager = self::getContainer()->get(EntityManagerInterface::class); $this->resetStaffingTables(self::getContainer()->get(Connection::class)); $this->tester = new CommandTester((new Application(self::$kernel))->find('app:assignment-generate')); } public function testDraftsAreCreatedForEnabledRowsOnly(): void { $this->staffingRule($this->entityManager, 'DKIMP'); $this->staffingRule($this->entityManager, 'DGSMP', enabled: false); $destination = $this->staffingDestination($this->entityManager, 'DKIMP110127', 'DKIMP'); $this->staffingDestination($this->entityManager, 'DGSMP110127', 'DGSMP'); $this->entityManager->flush(); $this->assertSame(Command::SUCCESS, $this->tester->execute([])); $assignments = $this->assignments(); $this->assertCount(3, $assignments); [$guide, $secondGuide, $course] = $assignments; $this->assertSame($destination->getId(), $guide->getDestination()->getId()); $this->assertSame('Reiseleitung', $guide->getJobProfile()->getName()); $this->assertSame(1, $guide->getAvailableDispositions()); $this->assertSame(5, $guide->getPickup()); $this->assertSame(['Skigebietsguiding (pro Einheit)'], $guide->getFees()->map(static fn ($fee) => $fee->getName())->toArray()); $this->assertSame(Assignment::STATUS_DRAFT, $guide->getStatus()); $this->assertSame('system', $guide->getCreatedBy()); $this->assertSame('Reiseleitung', $secondGuide->getJobProfile()->getName()); $this->assertSame(1, $secondGuide->getAvailableDispositions()); $this->assertSame(0, $secondGuide->getPickup()); $this->assertCount(0, $secondGuide->getFees()); $this->assertSame('Kursleitung Ski Anfänger:innen', $course->getJobProfile()->getName()); $this->assertSame(0, $course->getPickup()); } public function testADeletedDraftIsNotCreatedAgain(): void { $this->staffingRule($this->entityManager, 'DKIMP'); $this->staffingDestination($this->entityManager, 'DKIMP110127', 'DKIMP'); $this->entityManager->flush(); $this->tester->execute([]); foreach ($this->assignments() as $assignment) { $assignment->setDeleted(); } $this->entityManager->flush(); $this->tester->execute([]); $this->assertStringContainsString('davon 1 schon mit Einsätzen', $this->tester->getDisplay()); $this->assertCount(3, $this->assignments()); } public function testADryRunWritesNothing(): void { $this->staffingRule($this->entityManager, 'DKIMP'); $this->staffingDestination($this->entityManager, 'DKIMP110127', 'DKIMP'); $this->entityManager->flush(); $this->assertSame(Command::SUCCESS, $this->tester->execute(['--dry-run' => true])); $this->assertStringContainsString('1× Reiseleitung (Busbegleitung)', $this->tester->getDisplay()); $this->assertCount(0, $this->assignments()); } public function testAMissingJobProfileStopsTheRunBeforeItWrites(): void { $this->staffingRule($this->entityManager, 'DKIMP'); $this->staffingDestination($this->entityManager, 'DKIMP110127', 'DKIMP'); $this->entityManager->flush(); self::getContainer()->get(Connection::class)->executeStatement('UPDATE job_profile SET deleted_at = NOW() WHERE id = 21'); $this->assertSame(Command::FAILURE, $this->tester->execute([])); $this->assertCount(0, $this->assignments()); } /** * @return list */ private function assignments(): array { $this->entityManager->clear(); return $this->entityManager->getRepository(Assignment::class)->findBy([], ['id' => 'ASC']); } }