Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
beStrictAboutOutputDuringTests="true"
executionOrder="random"
>

<php>
Expand Down
5 changes: 5 additions & 0 deletions src/Services/DatabaseTools/AbstractDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,9 @@ protected function getCacheMetadataParameter()
}

abstract protected function getPlatformName(): string;

public static function clearMetadata(): void
{
self::$cachedMetadatas = [];
}
}
3 changes: 1 addition & 2 deletions tests/Test/ConfigEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Liip\TestFixturesBundle\Services\DatabaseTools\ORMSqliteDatabaseTool;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
* Tests that configuration has been loaded and users can be logged in.
Expand All @@ -38,7 +37,7 @@
*
* @internal
*/
class ConfigEventsTest extends KernelTestCase
class ConfigEventsTest extends FixturesTestCase
{
use ContainerProvider;

Expand Down
5 changes: 3 additions & 2 deletions tests/Test/ConfigMongodbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* with this source code in the file LICENSE.
*/

namespace Liip\Acme\Tests\Test;

use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
use Doctrine\Common\DataFixtures\ProxyReferenceRepository;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
Expand All @@ -21,7 +23,6 @@
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Liip\TestFixturesBundle\Services\DatabaseTools\MongoDBDatabaseTool;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
* Test MongoDB.
Expand All @@ -36,7 +37,7 @@
*
* @internal
*/
class ConfigMongodbTest extends KernelTestCase
class ConfigMongodbTest extends FixturesTestCase
{
use ContainerProvider;

Expand Down
3 changes: 1 addition & 2 deletions tests/Test/ConfigMysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Liip\TestFixturesBundle\Services\DatabaseTools\ORMDatabaseTool;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

// BC, needed by "theofidry/alice-data-fixtures: <1.3" not compatible with "doctrine/persistence: ^2.0"
if (interface_exists('\Doctrine\Persistence\ObjectManager')
Expand Down Expand Up @@ -51,7 +50,7 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
*
* @internal
*/
class ConfigMysqlTest extends KernelTestCase
class ConfigMysqlTest extends FixturesTestCase
{
use ContainerProvider;

Expand Down
3 changes: 1 addition & 2 deletions tests/Test/ConfigPhpcrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Liip\TestFixturesBundle\Services\DatabaseTools\PHPCRDatabaseTool;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;

/**
Expand All @@ -38,7 +37,7 @@
*
* @internal
*/
class ConfigPhpcrTest extends KernelTestCase
class ConfigPhpcrTest extends FixturesTestCase
{
use ContainerProvider;

Expand Down
3 changes: 1 addition & 2 deletions tests/Test/ConfigSqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Liip\TestFixturesBundle\Services\DatabaseTools\ORMSqliteDatabaseTool;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
* @runTestsInSeparateProcesses
Expand All @@ -40,7 +39,7 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
*
* @internal
*/
class ConfigSqliteTest extends KernelTestCase
class ConfigSqliteTest extends FixturesTestCase
{
use ContainerProvider;

Expand Down
3 changes: 1 addition & 2 deletions tests/Test/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Liip\TestFixturesBundle\Services\DatabaseTools\ORMSqliteDatabaseTool;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
* Tests that configuration has been loaded and users can be logged in.
Expand All @@ -42,7 +41,7 @@
*
* @internal
*/
class ConfigTest extends KernelTestCase
class ConfigTest extends FixturesTestCase
{
use ContainerProvider;

Expand Down
72 changes: 72 additions & 0 deletions tests/Test/FixturesTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
* (c) Lukas Kahwe Smith <smith@pooteeweet.org>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Liip\Acme\Tests\Test;

use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
* @internal
*/
abstract class FixturesTestCase extends KernelTestCase
{
protected function tearDown(): void
{
if (!$this->isTestSkipped()) {
$this->removeBackups();
}

parent::tearDown();
}

private function removeBackups(): void
{
$cacheDir = self::getContainer()->getParameter('kernel.cache_dir');
$backups = glob($cacheDir.'/test_{mongodb,mysql,postgresql,sqlite}_*', GLOB_BRACE);
foreach ($backups as $backup) {
$this->removeFile($backup);
AbstractDatabaseTool::clearMetadata();
}
}

private function removeFile(string $filename): void
{
if (!is_dir($filename)) {
unlink($filename);

return;
}

$directory = $filename;
$filenames = scandir($directory);
foreach ($filenames as $filename) {
if (\in_array($filename, ['.', '..'], true)) {
continue;
}

$this->removeFile($filename);
}

rmdir($directory);
}

private function isTestSkipped(): bool
{
if (version_compare(\PHPUnit\Runner\Version::id(), '10.0.0', '<')) {
return \PHPUnit\Runner\BaseTestRunner::STATUS_SKIPPED === $this->getStatus();
}

return $this->status()->isSkipped();
}
}
Loading