test: centralize web database setup
This commit is contained in:
parent
65e59e740c
commit
800f4c233f
4 changed files with 43 additions and 72 deletions
|
|
@ -3,36 +3,11 @@
|
||||||
namespace App\Tests\Controller\Admin;
|
namespace App\Tests\Controller\Admin;
|
||||||
|
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use App\Tests\DatabaseWebTestCase;
|
||||||
use Doctrine\ORM\Tools\SchemaTool;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
||||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
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
|
public function testAdminRedirectsToLogin(): void
|
||||||
{
|
{
|
||||||
$this->client->request('GET', '/admin');
|
$this->client->request('GET', '/admin');
|
||||||
|
|
|
||||||
|
|
@ -4,41 +4,29 @@ namespace App\Tests\Controller\Admin;
|
||||||
|
|
||||||
use App\Entity\ScriptMapping;
|
use App\Entity\ScriptMapping;
|
||||||
use App\Entity\User;
|
use App\Entity\User;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use App\Tests\DatabaseWebTestCase;
|
||||||
use Doctrine\ORM\Tools\SchemaTool;
|
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
||||||
use Symfony\Component\Process\Process;
|
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 Filesystem $filesystem;
|
||||||
private string $workDir;
|
private string $workDir;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
self::ensureKernelShutdown();
|
parent::setUp();
|
||||||
$this->client = self::createClient();
|
|
||||||
$this->filesystem = new Filesystem();
|
$this->filesystem = new Filesystem();
|
||||||
$this->workDir = sys_get_temp_dir().'/get-installer-bootstrap-controller-test-'.bin2hex(random_bytes(6));
|
$this->workDir = sys_get_temp_dir().'/get-installer-bootstrap-controller-test-'.bin2hex(random_bytes(6));
|
||||||
$this->filesystem->mkdir($this->workDir);
|
$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
|
protected function tearDown(): void
|
||||||
{
|
{
|
||||||
parent::tearDown();
|
|
||||||
|
|
||||||
$this->entityManager->close();
|
|
||||||
$this->filesystem->remove($this->workDir);
|
$this->filesystem->remove($this->workDir);
|
||||||
|
|
||||||
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNewMappingRequiresAuthentication(): void
|
public function testNewMappingRequiresAuthentication(): void
|
||||||
|
|
|
||||||
|
|
@ -3,35 +3,10 @@
|
||||||
namespace App\Tests\Controller;
|
namespace App\Tests\Controller;
|
||||||
|
|
||||||
use App\Entity\ScriptMapping;
|
use App\Entity\ScriptMapping;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use App\Tests\DatabaseWebTestCase;
|
||||||
use Doctrine\ORM\Tools\SchemaTool;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
|
||||||
|
|
||||||
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
|
public function testUnknownPathReturnsNotFound(): void
|
||||||
{
|
{
|
||||||
$this->client->request('GET', '/missing/install.sh');
|
$this->client->request('GET', '/missing/install.sh');
|
||||||
|
|
|
||||||
33
tests/DatabaseWebTestCase.php
Normal file
33
tests/DatabaseWebTestCase.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tests;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Doctrine\ORM\Tools\SchemaTool;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||||
|
|
||||||
|
abstract class DatabaseWebTestCase extends WebTestCase
|
||||||
|
{
|
||||||
|
protected KernelBrowser $client;
|
||||||
|
protected 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue