|
11 | 11 |
|
12 | 12 | namespace Orbitale\Bundle\CmsBundle\Tests; |
13 | 13 |
|
14 | | -use Doctrine\DBAL\Connection; |
15 | 14 | use Orbitale\Bundle\CmsBundle\Tests\Fixtures\TestBundle\Entity\Page; |
16 | 15 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
| 16 | +use Symfony\Component\Console\Output\BufferedOutput; |
| 17 | +use Symfony\Component\Console\Output\ConsoleOutput; |
| 18 | +use Symfony\Component\Console\Output\NullOutput; |
| 19 | +use Symfony\Component\Filesystem\Filesystem; |
| 20 | +use Symfony\Bundle\FrameworkBundle\Console\Application; |
| 21 | +use Symfony\Component\Console\Input\ArrayInput; |
17 | 22 |
|
18 | 23 | class AbstractTestCase extends WebTestCase |
19 | 24 | { |
20 | 25 | public function setUp(): void |
21 | 26 | { |
22 | 27 | static::bootKernel(); |
23 | 28 |
|
24 | | - /** @var Connection $c */ |
25 | | - $c = self::getContainer()->get(Connection::class); |
26 | | - $method = method_exists($c, 'executeQuery') ? 'executeQuery' : 'query'; |
27 | | - $c->$method('delete from orbitale_cms_pages where 1'); |
28 | | - $c->$method('delete from orbitale_cms_categories where 1'); |
| 29 | + $databaseFile = self::$kernel->getContainer()->getParameter('database_path'); |
| 30 | + |
| 31 | + $fs = new Filesystem(); |
| 32 | + |
| 33 | + if ($fs->exists($databaseFile)) { |
| 34 | + $fs->remove($databaseFile); |
| 35 | + } |
| 36 | + |
| 37 | + $application = new Application(self::$kernel); |
| 38 | + $application->setAutoExit(false); |
| 39 | + $out = new BufferedOutput(); |
| 40 | + $returns = []; |
| 41 | + $returns[] = $application->run(new ArrayInput(['command' => 'doctrine:database:create']), $out); |
| 42 | + $returns[] = $application->run(new ArrayInput(['command' => 'doctrine:schema:update', '--dump-sql' => true, '--complete' => true]), $out); |
| 43 | + $returns[] = $application->run(new ArrayInput(['command' => 'doctrine:schema:create']), $out); |
| 44 | + |
| 45 | + if (\in_array(1, $returns, true)) { |
| 46 | + self::fail(\sprintf("A database setup command has failed:\n%s", $out->fetch())); |
| 47 | + } |
| 48 | + |
29 | 49 | static::ensureKernelShutdown(); |
30 | 50 | } |
31 | 51 |
|
|
0 commit comments