-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
CachePoolsTest.php
103 lines (89 loc) · 3.25 KB
/
CachePoolsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
class CachePoolsTest extends AbstractWebTestCase
{
public function testCachePools()
{
$this->doTestCachePools([], AdapterInterface::class);
}
/**
* @requires extension redis
*/
public function testRedisCachePools()
{
try {
$this->doTestCachePools(['root_config' => 'redis_config.yml', 'environment' => 'redis_cache'], RedisAdapter::class);
} catch (\PHPUnit\Framework\Error\Warning $e) {
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
throw $e;
}
$this->markTestSkipped($e->getMessage());
} catch (\PHPUnit\Framework\Error\Warning $e) {
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
throw $e;
}
$this->markTestSkipped($e->getMessage());
} catch (InvalidArgumentException $e) {
if (0 !== strpos($e->getMessage(), 'Redis connection ')) {
throw $e;
}
$this->markTestSkipped($e->getMessage());
}
}
/**
* @requires extension redis
*/
public function testRedisCustomCachePools()
{
try {
$this->doTestCachePools(['root_config' => 'redis_custom_config.yml', 'environment' => 'custom_redis_cache'], RedisAdapter::class);
} catch (\PHPUnit\Framework\Error\Warning $e) {
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
throw $e;
}
$this->markTestSkipped($e->getMessage());
} catch (\PHPUnit\Framework\Error\Warning $e) {
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
throw $e;
}
$this->markTestSkipped($e->getMessage());
}
}
private function doTestCachePools($options, $adapterClass)
{
static::bootKernel($options);
$container = static::$kernel->getContainer();
$pool1 = $container->get('cache.pool1');
$this->assertInstanceOf($adapterClass, $pool1);
$key = 'foobar';
$pool1->deleteItem($key);
$item = $pool1->getItem($key);
$this->assertFalse($item->isHit());
$item->set('baz');
$pool1->save($item);
$item = $pool1->getItem($key);
$this->assertTrue($item->isHit());
$pool2 = $container->get('cache.pool2');
$pool2->save($item);
$container->get('cache_clearer')->clear($container->getParameter('kernel.cache_dir'));
$item = $pool1->getItem($key);
$this->assertFalse($item->isHit());
$item = $pool2->getItem($key);
$this->assertTrue($item->isHit());
}
protected static function createKernel(array $options = [])
{
return parent::createKernel(['test_case' => 'CachePools'] + $options);
}
}