Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit 7775fc9

Browse files
committed
Updated test config file to make use of Yaml imports
1 parent fca5ea7 commit 7775fc9

File tree

8 files changed

+32
-63
lines changed

8 files changed

+32
-63
lines changed

tests/Command/CommandTestCase.php

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
namespace Phpfastcache\Bundle\Tests\Command;
1717

1818
use Phpfastcache\Bundle\Service\Phpfastcache;
19+
use Phpfastcache\CacheManager;
1920
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
2021
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
2122
use PHPUnit\Framework\MockObject\MockObject;
2223
use PHPUnit\Framework\TestCase;
2324
use Symfony\Bundle\FrameworkBundle\Console\Application;
2425
use Symfony\Component\HttpKernel\Kernel;
26+
use Symfony\Component\Yaml\Yaml;
2527

2628
/**
2729
* Base Class for command tests
@@ -31,6 +33,8 @@
3133
abstract class CommandTestCase extends TestCase
3234
{
3335

36+
protected $ymlConfigFile = __DIR__ . '/../Resources/Config/phpfastcache.yaml';
37+
3438
/**
3539
* @var \Symfony\Bundle\FrameworkBundle\Console\Application
3640
*/
@@ -57,6 +61,8 @@ abstract class CommandTestCase extends TestCase
5761
*/
5862
public function setUp()
5963
{
64+
CacheManager::clearInstances();
65+
putenv('COLUMNS=200');// Prevent broken console rendering with unit tests
6066
$this->container = $this->getMockBuilder('\\Symfony\\Component\\DependencyInjection\\ContainerInterface')->getMock();
6167

6268
/** @var Kernel|MockObject $kernel */
@@ -71,26 +77,9 @@ public function setUp()
7177
->will($this->returnValue($this->container));
7278
$this->application = new Application($kernel);
7379

74-
$this->phpfastcacheParameters = [
75-
'twig_driver' => 'filecache',
76-
'twig_block_debug' => true,
77-
'drivers' =>
78-
[
79-
'filecache' =>
80-
[
81-
'type' => 'Files',
82-
'parameters' =>
83-
[
84-
'path' => \sys_get_temp_dir() . '/phpfastcache/',
85-
],
86-
],
87-
'staticcache' =>
88-
[
89-
'type' => 'Memstatic',
90-
'parameters' => [],
91-
],
92-
],
93-
];
80+
$parameters = Yaml::parse(\file_get_contents($this->ymlConfigFile));
81+
82+
$this->phpfastcacheParameters = $parameters['phpfastcache'];
9483

9584
$this->phpfastcache = new Phpfastcache($this->phpfastcacheParameters);
9685

tests/Command/PhpfastcacheClearCommandTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@
2424
*/
2525
class PhpfastcacheClearCommandTest extends CommandTestCase
2626
{
27-
28-
public function setUp()
29-
{
30-
CacheManager::clearInstances();
31-
putenv('COLUMNS=200');// Prevent broken console rendering with unit tests
32-
parent::setUp();
33-
}
34-
3527
public function testCommandClearAllCacheInstances()
3628
{
3729
$command = $this->application->find('phpfastcache:clear');

tests/Command/PhpfastcacheDelCommandTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@
2424
*/
2525
class PhpfastcacheDelCommandTest extends CommandTestCase
2626
{
27-
28-
public function setUp()
29-
{
30-
CacheManager::clearInstances();
31-
putenv('COLUMNS=200');// Prevent broken console rendering with unit tests
32-
parent::setUp();
33-
}
34-
3527
public function testCommandSetCacheItem()
3628
{
3729
$value = \md5(\random_bytes(255));

tests/Command/PhpfastcacheGetCommandTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@
2424
*/
2525
class PhpfastcacheGetCommandTest extends CommandTestCase
2626
{
27-
28-
public function setUp()
29-
{
30-
CacheManager::clearInstances();
31-
putenv('COLUMNS=200');// Prevent broken console rendering with unit tests
32-
parent::setUp();
33-
}
34-
3527
public function testCommandSetCacheItem()
3628
{
3729
$value = \md5(\random_bytes(255));

tests/Command/PhpfastcacheSetCommandTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@
2424
*/
2525
class PhpfastcacheSetCommandTest extends CommandTestCase
2626
{
27-
28-
public function setUp()
29-
{
30-
CacheManager::clearInstances();
31-
putenv('COLUMNS=200');// Prevent broken console rendering with unit tests
32-
parent::setUp();
33-
}
34-
3527
public function testCommandSetCacheItem()
3628
{
3729
$value = \md5(\random_bytes(255));

tests/Functional/AbstractWebTestCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ protected function profileRequest(string $method, string $uri, array $headers =
6969
public static function setUpBeforeClass()
7070
{
7171
static::deleteTmpDir();
72+
PhpfastcacheManager::clearInstances();
7273
$kernel = static::createClient()->getKernel();
7374

7475
/**

tests/Functional/App/config.yaml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
imports:
22
- { resource: 'services.yaml' }
3+
- { resource: './../../Resources/Config/phpfastcache.yaml' }
34

45
framework:
56
secret: test
@@ -11,14 +12,4 @@ framework:
1112

1213
web_profiler:
1314
toolbar: false
14-
intercept_redirects: false
15-
16-
# PhpFastCache configuration
17-
phpfastcache:
18-
twig_driver: "filecache" # This option must be a valid declared driver, in our example: "filecache"
19-
twig_block_debug: true # This option will wrap CACHE/ENDCACHE blocks with block debug as HTML comment
20-
drivers:
21-
filecache:
22-
type: Files
23-
parameters:
24-
path: "%kernel.cache_dir%/phpfastcache/"
15+
intercept_redirects: false
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# PhpFastCache unit tests configuration
2+
phpfastcache:
3+
twig_driver: "filecache" # This option must be a valid declared driver, in our example: "filecache"
4+
twig_block_debug: true # This option will wrap CACHE/ENDCACHE blocks with block debug as HTML comment
5+
drivers:
6+
filecache:
7+
type: Files
8+
parameters:
9+
path: '' # Automatic
10+
memorycache:
11+
type: Files
12+
parameters:
13+
path: '' # Automatic
14+
itemDetailedDate: true
15+
preventCacheSlams: true
16+
cacheFileExtension: db
17+
securityKey: symfony-flex-test
18+
staticcache:
19+
type: Memstatic
20+
parameters: []

0 commit comments

Comments
 (0)