Skip to content

Commit e1419ed

Browse files
committed
[FrameworkBundle] Fix cache warmers tests
1 parent bbd40a4 commit e1419ed

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

Tests/CacheWarmer/SerializerCacheWarmerTest.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@
2121

2222
class SerializerCacheWarmerTest extends TestCase
2323
{
24+
private PhpArrayAdapter $arrayPool;
25+
26+
protected function tearDown(): void
27+
{
28+
parent::tearDown();
29+
30+
if (isset($this->arrayPool)) {
31+
$this->arrayPool->clear();
32+
unset($this->arrayPool);
33+
}
34+
}
35+
36+
private function getArrayPool(string $file): PhpArrayAdapter
37+
{
38+
return $this->arrayPool = new PhpArrayAdapter($file, new NullAdapter());
39+
}
40+
2441
/**
2542
* @dataProvider loaderProvider
2643
*/
@@ -34,7 +51,7 @@ public function testWarmUp(array $loaders)
3451

3552
$this->assertFileExists($file);
3653

37-
$arrayPool = new PhpArrayAdapter($file, new NullAdapter());
54+
$arrayPool = $this->getArrayPool($file);
3855

3956
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
4057
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
@@ -56,7 +73,7 @@ public function testWarmUpAbsoluteFilePath(array $loaders)
5673
$this->assertFileExists($file);
5774
$this->assertFileDoesNotExist($cacheDir.'/cache-serializer.php');
5875

59-
$arrayPool = new PhpArrayAdapter($file, new NullAdapter());
76+
$arrayPool = $this->getArrayPool($file);
6077

6178
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
6279
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
@@ -75,10 +92,10 @@ public function testWarmUpWithoutBuildDir(array $loaders)
7592

7693
$this->assertFileDoesNotExist($file);
7794

78-
$arrayPool = new PhpArrayAdapter($file, new NullAdapter());
95+
$arrayPool = $this->getArrayPool($file);
7996

80-
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
81-
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
97+
$this->assertFalse($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
98+
$this->assertFalse($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
8299
}
83100

84101
public static function loaderProvider(): array

Tests/CacheWarmer/ValidatorCacheWarmerTest.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@
2020

2121
class ValidatorCacheWarmerTest extends TestCase
2222
{
23+
private PhpArrayAdapter $arrayPool;
24+
25+
protected function tearDown(): void
26+
{
27+
parent::tearDown();
28+
29+
if (isset($this->arrayPool)) {
30+
$this->arrayPool->clear();
31+
unset($this->arrayPool);
32+
}
33+
}
34+
35+
private function getArrayPool(string $file): PhpArrayAdapter
36+
{
37+
return $this->arrayPool = new PhpArrayAdapter($file, new NullAdapter());
38+
}
39+
2340
public function testWarmUp()
2441
{
2542
$validatorBuilder = new ValidatorBuilder();
@@ -36,7 +53,7 @@ public function testWarmUp()
3653

3754
$this->assertFileExists($file);
3855

39-
$arrayPool = new PhpArrayAdapter($file, new NullAdapter());
56+
$arrayPool = $this->getArrayPool($file);
4057

4158
$this->assertTrue($arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Person')->isHit());
4259
$this->assertTrue($arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author')->isHit());
@@ -61,7 +78,7 @@ public function testWarmUpAbsoluteFilePath()
6178
$this->assertFileExists($file);
6279
$this->assertFileDoesNotExist($cacheDir.'/cache-validator.php');
6380

64-
$arrayPool = new PhpArrayAdapter($file, new NullAdapter());
81+
$arrayPool = $this->getArrayPool($file);
6582

6683
$this->assertTrue($arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Person')->isHit());
6784
$this->assertTrue($arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author')->isHit());
@@ -83,10 +100,10 @@ public function testWarmUpWithoutBuilDir()
83100

84101
$this->assertFileDoesNotExist($file);
85102

86-
$arrayPool = new PhpArrayAdapter($file, new NullAdapter());
103+
$arrayPool = $this->getArrayPool($file);
87104

88-
$this->assertTrue($arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Person')->isHit());
89-
$this->assertTrue($arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author')->isHit());
105+
$this->assertFalse($arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Person')->isHit());
106+
$this->assertFalse($arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Author')->isHit());
90107
}
91108

92109
public function testWarmUpWithAnnotations()
@@ -103,7 +120,7 @@ public function testWarmUpWithAnnotations()
103120

104121
$this->assertFileExists($file);
105122

106-
$arrayPool = new PhpArrayAdapter($file, new NullAdapter());
123+
$arrayPool = $this->getArrayPool($file);
107124

108125
$item = $arrayPool->getItem('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Category');
109126
$this->assertTrue($item->isHit());

0 commit comments

Comments
 (0)