Merge branch 'cleo' of https://codefirst.iut.uca.fr/git/cleo.eiras/EvoLyte into cleo
commit
f24545f3e0
@ -0,0 +1 @@
|
||||
8.3
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class PopulateDBCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'app:populateDB';
|
||||
|
||||
private Connection $connection;
|
||||
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDescription('Populate the database.');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
try {
|
||||
|
||||
// On supprime la table si elle existe déjà
|
||||
$this->connection->executeStatement('DROP TABLE IF EXISTS rarity');
|
||||
|
||||
// On crée la table
|
||||
$this->connection->executeStatement('
|
||||
CREATE TABLE rarity (
|
||||
id INT PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
drop_rate FLOAT NOT NULL
|
||||
)
|
||||
');
|
||||
|
||||
// On peuple la table
|
||||
$this->connection->executeStatement("INSERT INTO rarity (id, name, drop_rate) VALUES
|
||||
(1, 'Common', 0.6),
|
||||
(2, 'Rare', 0.2),
|
||||
(3, 'Epic', 0.1),
|
||||
(4, 'Mythical', 0.085),
|
||||
(5, 'Legendary', 0.015)
|
||||
");
|
||||
|
||||
$output->writeln('Base de données peuplée.');
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln('<error>Erreur : ' . $e->getMessage() . '</error>');
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
<?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']);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue