You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.6 KiB
90 lines
2.6 KiB
<?php
|
|
|
|
namespace App\Tests\Controller;
|
|
|
|
use App\Entity\Emoji;
|
|
use App\Entity\Rarity;
|
|
use App\Repository\EmojiRepository;
|
|
use App\Repository\RarityRepository;
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class EmojiControllerTest extends WebTestCase
|
|
{
|
|
private $client;
|
|
private EntityManagerInterface $em;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->client = static::createClient();
|
|
$this->em = static::getContainer()->get(EntityManagerInterface::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
|
|
{
|
|
$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 = (new Rarity())
|
|
->setName('Rare')
|
|
->setDropRate(1.0);
|
|
|
|
$this->em->persist($rarity);
|
|
$this->em->persist($emoji1);
|
|
$this->em->persist($emoji2);
|
|
$this->em->flush();
|
|
|
|
$id1 = $emoji1->getId();
|
|
$id2 = $emoji2->getId();
|
|
|
|
$this->client->request('GET', "/emoji/fusion/$id1/$id2");
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
|
|
|
$data = json_decode($response->getContent(), true);
|
|
$this->assertArrayHasKey('childId', $data);
|
|
$this->assertEquals('Child created', $data['message']);
|
|
}
|
|
|
|
public function testFusionEmojiNotFound(): void
|
|
{
|
|
$emojiRepo = $this->createMock(EmojiRepository::class);
|
|
$emojiRepo->method('find')->willReturn(null);
|
|
|
|
$this->client->request('GET', '/emoji/fusion/999/998');
|
|
|
|
$response = $this->client->getResponse();
|
|
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
|
|
|
|
$data = json_decode($response->getContent(), true);
|
|
$this->assertEquals('One or both emojis not found', $data['error']);
|
|
}
|
|
}
|