From 50cfb719efc884a9434939ac7b2fd461bd6e3528 Mon Sep 17 00:00:00 2001 From: robin <57806687+HiroKX@users.noreply.github.com> Date: Sat, 21 Oct 2023 23:41:55 +0200 Subject: [PATCH] fixing the generator of test when using make:crud --- src/Maker/MakeCrud.php | 10 +- src/Resources/skeleton/crud/test/Test.tpl.php | 125 ------------------ 2 files changed, 4 insertions(+), 131 deletions(-) delete mode 100644 src/Resources/skeleton/crud/test/Test.tpl.php diff --git a/src/Maker/MakeCrud.php b/src/Maker/MakeCrud.php index a6ed27ce7..51d5c5dbc 100644 --- a/src/Maker/MakeCrud.php +++ b/src/Maker/MakeCrud.php @@ -251,11 +251,9 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen $repositoryClassName, ]); - $usesEntityManager = EntityManagerInterface::class === $repositoryClassName; - if ($usesEntityManager) { - $useStatements->addUseStatement(EntityRepository::class); - } + $useStatements->addUseStatement(EntityRepository::class); + if (EntityManagerInterface::class !== $repositoryClassName) { $useStatements->addUseStatement(EntityManagerInterface::class); @@ -263,7 +261,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen $generator->generateFile( 'tests/Controller/'.$testClassDetails->getShortName().'.php', - $usesEntityManager ? 'crud/test/Test.EntityManager.tpl.php' : 'crud/test/Test.tpl.php', + 'crud/test/Test.EntityManager.tpl.php', [ 'use_statements' => $useStatements, 'entity_full_class_name' => $entityClassDetails->getFullName(), @@ -274,7 +272,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen 'class_name' => Str::getShortClassName($testClassDetails->getFullName()), 'namespace' => Str::getNamespace($testClassDetails->getFullName()), 'form_fields' => $entityDoctrineDetails->getFormFields(), - 'repository_class_name' => $usesEntityManager ? EntityManagerInterface::class : $repositoryVars['repository_class_name'], + 'repository_class_name' => EntityManagerInterface::class, 'form_field_prefix' => strtolower(Str::asSnakeCase($entityTwigVarSingular)), ] ); diff --git a/src/Resources/skeleton/crud/test/Test.tpl.php b/src/Resources/skeleton/crud/test/Test.tpl.php deleted file mode 100644 index d767ce698..000000000 --- a/src/Resources/skeleton/crud/test/Test.tpl.php +++ /dev/null @@ -1,125 +0,0 @@ - - - -namespace ; - - - -class extends WebTestCase -{ - private KernelBrowser $client; - private $repository; - private string $path = '/'; - private EntityManagerInterface $manager; - - protected function setUp(): void - { - $this->client = static::createClient(); - $this->repository = static::getContainer()->get('doctrine')->getRepository(::class); - - foreach ($this->repository->findAll() as $object) { - $this->manager->remove($object); - } - } - - public function testIndex(): void - { - $crawler = $this->client->request('GET', $this->path); - - self::assertResponseStatusCodeSame(200); - self::assertPageTitleContains(' index'); - - // Use the $crawler to perform additional assertions e.g. - // self::assertSame('Some text on the page', $crawler->filter('.p')->first()); - } - - public function testNew(): void - { - $originalNumObjectsInRepository = count($this->repository->findAll()); - - $this->markTestIncomplete(); - $this->client->request('GET', sprintf('%snew', $this->path)); - - self::assertResponseStatusCodeSame(200); - - $this->client->submitForm('Save', [ - $typeOptions): ?> - '[]' => 'Testing', - - ]); - - self::assertResponseRedirects('/'); - - self::assertSame($originalNumObjectsInRepository + 1, count($this->repository->findAll())); - } - - public function testShow(): void - { - $this->markTestIncomplete(); - $fixture = new (); - $typeOptions): ?> - $fixture->set('My Title'); - - - $this->manager->persist($fixture); - $this->manager->flush(); - - $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); - - self::assertResponseStatusCodeSame(200); - self::assertPageTitleContains(''); - - // Use assertions to check that the properties are properly displayed. - } - - public function testEdit(): void - { - $this->markTestIncomplete(); - $fixture = new (); - $typeOptions): ?> - $fixture->set('My Title'); - - - $this->manager->persist($fixture); - $this->manager->flush(); - - $this->client->request('GET', sprintf('%s%s/edit', $this->path, $fixture->getId())); - - $this->client->submitForm('Update', [ - $typeOptions): ?> - '[]' => 'Something New', - - ]); - - self::assertResponseRedirects('/'); - - $fixture = $this->repository->findAll(); - - $typeOptions): ?> - self::assertSame('Something New', $fixture[0]->get()); - - } - - public function testRemove(): void - { - $this->markTestIncomplete(); - - $originalNumObjectsInRepository = count($this->repository->findAll()); - - $fixture = new (); - $typeOptions): ?> - $fixture->set('My Title'); - - - $this->manager->persist($fixture); - $this->manager->flush(); - - self::assertSame($originalNumObjectsInRepository + 1, count($this->repository->findAll())); - - $this->client->request('GET', sprintf('%s%s', $this->path, $fixture->getId())); - $this->client->submitForm('Delete'); - - self::assertSame($originalNumObjectsInRepository, count($this->repository->findAll())); - self::assertResponseRedirects('/'); - } -}