Fix tests

This commit is contained in:
2024-06-07 17:30:57 +02:00
parent 9afe77b4ed
commit 1dc528f269
7 changed files with 93 additions and 71 deletions

View File

@@ -3,8 +3,9 @@
namespace App\Test\Controller;
use App\Entity\Species;
use App\Entity\User;
use App\Repository\SpeciesRepository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@@ -12,13 +13,15 @@ class SpeciesControllerTest extends WebTestCase
{
private KernelBrowser $client;
private EntityManagerInterface $manager;
private EntityRepository $repository;
private SpeciesRepository $repository;
private string $path = '/species/';
protected function setUp(): void
{
$this->client = static::createClient();
$this->manager = static::getContainer()->get('doctrine')->getManager();
/** @var EntityManagerInterface $manager */
$manager = static::getContainer()->get(EntityManagerInterface::class);
$this->manager = $manager;
$this->repository = $this->manager->getRepository(Species::class);
foreach ($this->repository->findAll() as $object) {
@@ -26,6 +29,12 @@ class SpeciesControllerTest extends WebTestCase
}
$this->manager->flush();
$userRepository = $this->manager->getRepository(User::class);
/** @var User $user */
$user = $userRepository->findOneByEmail('test@test.fr');
$this->client->loginUser($user);
$this->client->request('GET', sprintf('%snew', $this->path));
}
public function testIndex(): void
@@ -41,7 +50,6 @@ class SpeciesControllerTest extends WebTestCase
public function testNew(): void
{
$this->markTestIncomplete();
$this->client->request('GET', sprintf('%snew', $this->path));
self::assertResponseStatusCodeSame(200);
@@ -59,10 +67,9 @@ class SpeciesControllerTest extends WebTestCase
public function testShow(): void
{
$this->markTestIncomplete();
$fixture = new Species();
$fixture->setScientific_name('My Title');
$fixture->setVernacular_name('My Title');
$fixture->setScientificName('My Title');
$fixture->setVernacularName('My Title');
$fixture->setRegion('My Title');
$this->manager->persist($fixture);
@@ -78,10 +85,9 @@ class SpeciesControllerTest extends WebTestCase
public function testEdit(): void
{
$this->markTestIncomplete();
$fixture = new Species();
$fixture->setScientific_name('Value');
$fixture->setVernacular_name('Value');
$fixture->setScientificName('Value');
$fixture->setVernacularName('Value');
$fixture->setRegion('Value');
$this->manager->persist($fixture);
@@ -99,17 +105,16 @@ class SpeciesControllerTest extends WebTestCase
$fixture = $this->repository->findAll();
self::assertSame('Something New', $fixture[0]->getScientific_name());
self::assertSame('Something New', $fixture[0]->getVernacular_name());
self::assertSame('Something New', $fixture[0]->getScientificName());
self::assertSame('Something New', $fixture[0]->getVernacularName());
self::assertSame('Something New', $fixture[0]->getRegion());
}
public function testRemove(): void
{
$this->markTestIncomplete();
$fixture = new Species();
$fixture->setScientific_name('Value');
$fixture->setVernacular_name('Value');
$fixture->setScientificName('Value');
$fixture->setVernacularName('Value');
$fixture->setRegion('Value');
$this->manager->persist($fixture);