client = static::createClient(); $container = static::getContainer(); $this->em = static::getContainer()->get(EntityManagerInterface::class); $this->rarityRepository = $container->get(RarityRepository::class); // Démarre une transaction pour pouvoir annuler les modifications des tests $this->em->getConnection()->beginTransaction(); } protected function tearDown(): void { // Rollback la transaction pour annuler les changements des tests $this->em->getConnection()->rollBack(); parent::tearDown(); } public function testReproduceEmoji(): void { $user = (new User()) ->setUsername('testuser') ->setPassword('test'); $this->em->persist($user); $this->em->flush(); $userId = $user->getId(); $emoji1 = (new Emoji()) ->setCode('😀') ->setName('Parent1') ->setStrength(1.0) ->setToughness(1.0) ->setIntelligence(1.0) ->setSpeed(1.0) ->setFightsWon(5); $emoji2 = (new Emoji()) ->setCode('😎') ->setName('Parent2') ->setStrength(2.0) ->setToughness(2.0) ->setIntelligence(2.0) ->setSpeed(2.0) ->setFightsWon(3); $rarity = $this->rarityRepository->findOneBy(['name' => 'Common']); $emoji1->setRarity($rarity); $emoji2->setRarity(rarity: $rarity); $this->em->persist($emoji1); $this->em->persist($emoji2); $this->em->flush(); $id1 = $emoji1->getId(); $id2 = $emoji2->getId(); $this->client->request('GET', "/emojis/fusion/$userId/$id1/$id2"); $response = $this->client->getResponse(); $data = json_decode($response->getContent(), true); $this->assertEquals('Child created', $data['message']); } public function testFusionEmojiNotFound(): void { $emojiRepo = $this->createMock(EmojiRepository::class); $emojiRepo->method('find')->willReturn(null); $this->client->request('GET', '/emojis/fusion/999/998'); $response = $this->client->getResponse(); $this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode()); $data = json_decode($response->getContent(), true); $this->assertNull($data); } }