Skip to content

Commit 98a23a8

Browse files
committed
chore: clear cache in tests
1 parent 8ef1c46 commit 98a23a8

7 files changed

Lines changed: 78 additions & 12 deletions

File tree

tests/Test/ConfigEventsTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
2222
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
2323
use Liip\TestFixturesBundle\Services\DatabaseTools\ORMSqliteDatabaseTool;
24-
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
2524

2625
/**
2726
* Tests that configuration has been loaded and users can be logged in.
@@ -38,7 +37,7 @@
3837
*
3938
* @internal
4039
*/
41-
class ConfigEventsTest extends KernelTestCase
40+
class ConfigEventsTest extends FixturesTestCase
4241
{
4342
use ContainerProvider;
4443

tests/Test/ConfigMongodbTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* with this source code in the file LICENSE.
1212
*/
1313

14+
namespace Liip\Acme\Tests\Test;
15+
1416
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
1517
use Doctrine\Common\DataFixtures\ProxyReferenceRepository;
1618
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
@@ -21,7 +23,6 @@
2123
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
2224
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
2325
use Liip\TestFixturesBundle\Services\DatabaseTools\MongoDBDatabaseTool;
24-
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
2526

2627
/**
2728
* Test MongoDB.
@@ -36,7 +37,7 @@
3637
*
3738
* @internal
3839
*/
39-
class ConfigMongodbTest extends KernelTestCase
40+
class ConfigMongodbTest extends FixturesTestCase
4041
{
4142
use ContainerProvider;
4243

tests/Test/ConfigMysqlTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
2323
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
2424
use Liip\TestFixturesBundle\Services\DatabaseTools\ORMDatabaseTool;
25-
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
2625

2726
// BC, needed by "theofidry/alice-data-fixtures: <1.3" not compatible with "doctrine/persistence: ^2.0"
2827
if (interface_exists('\Doctrine\Persistence\ObjectManager')
@@ -51,7 +50,7 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
5150
*
5251
* @internal
5352
*/
54-
class ConfigMysqlTest extends KernelTestCase
53+
class ConfigMysqlTest extends FixturesTestCase
5554
{
5655
use ContainerProvider;
5756

tests/Test/ConfigPhpcrTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
2323
use Liip\TestFixturesBundle\Services\DatabaseTools\PHPCRDatabaseTool;
2424
use Symfony\Bundle\FrameworkBundle\Console\Application;
25-
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
2625
use Symfony\Component\Console\Tester\CommandTester;
2726

2827
/**
@@ -38,7 +37,7 @@
3837
*
3938
* @internal
4039
*/
41-
class ConfigPhpcrTest extends KernelTestCase
40+
class ConfigPhpcrTest extends FixturesTestCase
4241
{
4342
use ContainerProvider;
4443

tests/Test/ConfigSqliteTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
2828
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
2929
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
3030
use Liip\TestFixturesBundle\Services\DatabaseTools\ORMSqliteDatabaseTool;
31-
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
3231

3332
/**
3433
* @runTestsInSeparateProcesses
@@ -40,7 +39,7 @@ class_alias('\Doctrine\Persistence\ObjectManager', '\Doctrine\Common\Persistence
4039
*
4140
* @internal
4241
*/
43-
class ConfigSqliteTest extends KernelTestCase
42+
class ConfigSqliteTest extends FixturesTestCase
4443
{
4544
use ContainerProvider;
4645

tests/Test/ConfigTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Liip\TestFixturesBundle\Services\DatabaseToolCollection;
2323
use Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool;
2424
use Liip\TestFixturesBundle\Services\DatabaseTools\ORMSqliteDatabaseTool;
25-
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
2625

2726
/**
2827
* Tests that configuration has been loaded and users can be logged in.
@@ -42,7 +41,7 @@
4241
*
4342
* @internal
4443
*/
45-
class ConfigTest extends KernelTestCase
44+
class ConfigTest extends FixturesTestCase
4645
{
4746
use ContainerProvider;
4847

tests/Test/FixturesTestCase.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the Liip/TestFixturesBundle
7+
*
8+
* (c) Lukas Kahwe Smith <smith@pooteeweet.org>
9+
*
10+
* This source file is subject to the MIT license that is bundled
11+
* with this source code in the file LICENSE.
12+
*/
13+
14+
namespace Liip\Acme\Tests\Test;
15+
16+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
17+
18+
/**
19+
* @internal
20+
*/
21+
abstract class FixturesTestCase extends KernelTestCase
22+
{
23+
protected function tearDown(): void
24+
{
25+
if (!$this->isTestSkipped()) {
26+
$this->removeBackups();
27+
}
28+
29+
parent::tearDown();
30+
}
31+
32+
private function removeBackups(): void
33+
{
34+
$cacheDir = self::getContainer()->getParameter('kernel.cache_dir');
35+
$backups = glob($cacheDir.'/test_{mongodb,mysql,postgresql,sqlite}_*', GLOB_BRACE);
36+
foreach ($backups as $backup) {
37+
$this->removeFile($backup);
38+
}
39+
}
40+
41+
private function removeFile(string $filename): void
42+
{
43+
if (!is_dir($filename)) {
44+
unlink($filename);
45+
46+
return;
47+
}
48+
49+
$directory = $filename;
50+
$filenames = scandir($directory);
51+
foreach ($filenames as $filename) {
52+
if (\in_array($filename, ['.', '..'], true)) {
53+
continue;
54+
}
55+
56+
$this->removeFile($filename);
57+
}
58+
59+
rmdir($directory);
60+
}
61+
62+
private function isTestSkipped(): bool
63+
{
64+
if (version_compare(\PHPUnit\Runner\Version::id(), '10.0.0', '<')) {
65+
return \PHPUnit\Runner\BaseTestRunner::STATUS_SKIPPED === $this->getStatus();
66+
}
67+
68+
return $this->status()->isSkipped();
69+
}
70+
}

0 commit comments

Comments
 (0)