diff --git a/tests/Command/InstallCommandTest.php b/tests/Command/InstallCommandTest.php index 3cf3d2ad6..ceec39018 100644 --- a/tests/Command/InstallCommandTest.php +++ b/tests/Command/InstallCommandTest.php @@ -51,7 +51,7 @@ class InstallCommandTest extends WallabagTestCase $this->getNewClient(); } - $this->resetDatabase($this->getTestClient()); + $this->resetDatabase(); } protected function tearDown(): void @@ -67,7 +67,7 @@ class InstallCommandTest extends WallabagTestCase // Create a new client to avoid the error: // Transaction commit failed because the transaction has been marked for rollback only. $client = $this->getNewClient(); - $this->resetDatabase($client); + $this->resetDatabase(); } parent::tearDown(); @@ -276,4 +276,38 @@ class InstallCommandTest extends WallabagTestCase return $command; } + + private function resetDatabase() + { + $application = new Application($this->getTestClient()->getKernel()); + $application->setAutoExit(false); + + $application->run(new ArrayInput([ + 'command' => 'doctrine:schema:drop', + '--no-interaction' => true, + '--force' => true, + '--full-database' => true, + '--env' => 'test', + ]), new NullOutput()); + + $application->run(new ArrayInput([ + 'command' => 'doctrine:migrations:migrate', + '--no-interaction' => true, + '--env' => 'test', + ]), new NullOutput()); + + $application->run(new ArrayInput([ + 'command' => 'doctrine:fixtures:load', + '--no-interaction' => true, + '--env' => 'test', + ]), new NullOutput()); + + /* + * Recreate client to avoid error: + * + * [Doctrine\DBAL\ConnectionException] + * Transaction commit failed because the transaction has been marked for rollback only. + */ + $this->getNewClient(); + } } diff --git a/tests/WallabagTestCase.php b/tests/WallabagTestCase.php index c2df2ce35..8f70a115e 100644 --- a/tests/WallabagTestCase.php +++ b/tests/WallabagTestCase.php @@ -3,11 +3,8 @@ namespace Tests\Wallabag; use Doctrine\ORM\EntityManagerInterface; -use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -use Symfony\Component\Console\Input\ArrayInput; -use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Wallabag\Entity\User; @@ -39,40 +36,6 @@ abstract class WallabagTestCase extends WebTestCase return $this->client; } - public function resetDatabase(KernelBrowser $client) - { - $application = new Application($client->getKernel()); - $application->setAutoExit(false); - - $application->run(new ArrayInput([ - 'command' => 'doctrine:schema:drop', - '--no-interaction' => true, - '--force' => true, - '--full-database' => true, - '--env' => 'test', - ]), new NullOutput()); - - $application->run(new ArrayInput([ - 'command' => 'doctrine:migrations:migrate', - '--no-interaction' => true, - '--env' => 'test', - ]), new NullOutput()); - - $application->run(new ArrayInput([ - 'command' => 'doctrine:fixtures:load', - '--no-interaction' => true, - '--env' => 'test', - ]), new NullOutput()); - - /* - * Recreate client to avoid error: - * - * [Doctrine\DBAL\ConnectionException] - * Transaction commit failed because the transaction has been marked for rollback only. - */ - $this->client = $this->getNewClient(); - } - public function getEntityManager() { return $this->client->getContainer()->get(EntityManagerInterface::class);