diff --git a/tests/Controller/Admin/AuthControllerTest.php b/tests/Controller/Admin/AuthControllerTest.php index 56e3a0e..6dfc32d 100644 --- a/tests/Controller/Admin/AuthControllerTest.php +++ b/tests/Controller/Admin/AuthControllerTest.php @@ -3,36 +3,11 @@ namespace App\Tests\Controller\Admin; use App\Entity\User; -use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Tools\SchemaTool; -use Symfony\Bundle\FrameworkBundle\KernelBrowser; -use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use App\Tests\DatabaseWebTestCase; use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; -final class AuthControllerTest extends WebTestCase +final class AuthControllerTest extends DatabaseWebTestCase { - private KernelBrowser $client; - private EntityManagerInterface $entityManager; - - protected function setUp(): void - { - self::ensureKernelShutdown(); - $this->client = self::createClient(); - - $this->entityManager = static::getContainer()->get(EntityManagerInterface::class); - $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata(); - $schemaTool = new SchemaTool($this->entityManager); - $schemaTool->dropSchema($metadata); - $schemaTool->createSchema($metadata); - } - - protected function tearDown(): void - { - parent::tearDown(); - - $this->entityManager->close(); - } - public function testAdminRedirectsToLogin(): void { $this->client->request('GET', '/admin'); diff --git a/tests/Controller/Admin/ScriptMappingControllerTest.php b/tests/Controller/Admin/ScriptMappingControllerTest.php index a6f4295..7491b90 100644 --- a/tests/Controller/Admin/ScriptMappingControllerTest.php +++ b/tests/Controller/Admin/ScriptMappingControllerTest.php @@ -4,41 +4,29 @@ namespace App\Tests\Controller\Admin; use App\Entity\ScriptMapping; use App\Entity\User; -use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Tools\SchemaTool; +use App\Tests\DatabaseWebTestCase; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Bundle\FrameworkBundle\KernelBrowser; -use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\Process\Process; -final class ScriptMappingControllerTest extends WebTestCase +final class ScriptMappingControllerTest extends DatabaseWebTestCase { - private KernelBrowser $client; - private EntityManagerInterface $entityManager; private Filesystem $filesystem; private string $workDir; protected function setUp(): void { - self::ensureKernelShutdown(); - $this->client = self::createClient(); + parent::setUp(); + $this->filesystem = new Filesystem(); $this->workDir = sys_get_temp_dir().'/get-installer-bootstrap-controller-test-'.bin2hex(random_bytes(6)); $this->filesystem->mkdir($this->workDir); - - $this->entityManager = static::getContainer()->get(EntityManagerInterface::class); - $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata(); - $schemaTool = new SchemaTool($this->entityManager); - $schemaTool->dropSchema($metadata); - $schemaTool->createSchema($metadata); } protected function tearDown(): void { - parent::tearDown(); - - $this->entityManager->close(); $this->filesystem->remove($this->workDir); + + parent::tearDown(); } public function testNewMappingRequiresAuthentication(): void diff --git a/tests/Controller/PublicScriptControllerTest.php b/tests/Controller/PublicScriptControllerTest.php index ace0fd8..0aca2e6 100644 --- a/tests/Controller/PublicScriptControllerTest.php +++ b/tests/Controller/PublicScriptControllerTest.php @@ -3,35 +3,10 @@ namespace App\Tests\Controller; use App\Entity\ScriptMapping; -use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Tools\SchemaTool; -use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -use Symfony\Bundle\FrameworkBundle\KernelBrowser; +use App\Tests\DatabaseWebTestCase; -final class PublicScriptControllerTest extends WebTestCase +final class PublicScriptControllerTest extends DatabaseWebTestCase { - private KernelBrowser $client; - private EntityManagerInterface $entityManager; - - protected function setUp(): void - { - self::ensureKernelShutdown(); - $this->client = self::createClient(); - - $this->entityManager = static::getContainer()->get(EntityManagerInterface::class); - $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata(); - $schemaTool = new SchemaTool($this->entityManager); - $schemaTool->dropSchema($metadata); - $schemaTool->createSchema($metadata); - } - - protected function tearDown(): void - { - parent::tearDown(); - - $this->entityManager->close(); - } - public function testUnknownPathReturnsNotFound(): void { $this->client->request('GET', '/missing/install.sh'); diff --git a/tests/DatabaseWebTestCase.php b/tests/DatabaseWebTestCase.php new file mode 100644 index 0000000..317f62a --- /dev/null +++ b/tests/DatabaseWebTestCase.php @@ -0,0 +1,33 @@ +client = self::createClient(); + + $this->entityManager = static::getContainer()->get(EntityManagerInterface::class); + $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata(); + $schemaTool = new SchemaTool($this->entityManager); + $schemaTool->dropSchema($metadata); + $schemaTool->createSchema($metadata); + } + + protected function tearDown(): void + { + parent::tearDown(); + + $this->entityManager->close(); + } +}