serializer = self::getContainer()->get(SerializerInterface::class); $this->validator = self::getContainer()->get(ValidatorInterface::class); } protected function tearDown(): void { self::ensureKernelShutdown(); } /** * @dataProvider generateMotiveId */ public function testAddValidMotive(int $motiveId): void { $ticket = new Ticket(); $payload = <<buildController(); $response = $controller($ticket, $request); self::assertEquals(201, $response->getStatusCode()); } private function buildController(): ReplaceMotiveController { $security = $this->prophesize(Security::class); $security->isGranted('ROLE_USER')->willReturn(true); $entityManager = $this->prophesize(EntityManagerInterface::class); $entityManager->persist(Argument::type(MotiveHistory::class))->shouldBeCalled(); $entityManager->flush()->shouldBeCalled(); $handler = new ReplaceMotiveCommandHandler( new MockClock(), $entityManager->reveal() ); return new ReplaceMotiveController( $security->reveal(), $handler, $this->serializer, $this->validator, $entityManager->reveal(), ); } public static function generateMotiveId(): iterable { self::bootKernel(); $em = self::getContainer()->get(EntityManagerInterface::class); $motive = $em->createQuery('SELECT m FROM '.Motive::class.' m ') ->setMaxResults(1) ->getOneOrNullResult(); if (null === $motive) { throw new \RuntimeException('the motive table seems to be empty'); } self::ensureKernelShutdown(); yield [$motive->getId()]; } }