|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\CacheBundle\Tests\Adapter; |
|
15
|
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
use Sonata\Cache\CacheElement; |
|
18
|
|
|
use Sonata\CacheBundle\Adapter\ApcCache; |
|
19
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
20
|
|
|
|
|
21
|
|
|
class ApcCacheTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
private $router; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var ApcCache |
|
27
|
|
|
*/ |
|
28
|
|
|
private $cache; |
|
29
|
|
|
|
|
30
|
|
|
public function setUp(): void |
|
31
|
|
|
{ |
|
32
|
|
|
if (!\function_exists('apcu_store')) { |
|
33
|
|
|
$this->markTestSkipped('APC is not installed'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if (0 === ini_get('apcu.enable_cli')) { |
|
|
|
|
|
|
37
|
|
|
$this->markTestSkipped('APC is not enabled in cli, please add apcu.enable_cli=On into the apcu.ini file'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$this->router = $this->createMock(RouterInterface::class); |
|
41
|
|
|
|
|
42
|
|
|
$this->cache = new ApcCache($this->router, 'token', 'prefix_', [], []); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testInitCache(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$this->assertTrue($this->cache->flush([])); |
|
48
|
|
|
$this->assertTrue($this->cache->flushAll()); |
|
49
|
|
|
|
|
50
|
|
|
$cacheElement = $this->cache->set(['id' => 7], 'data'); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertInstanceOf(CacheElement::class, $cacheElement); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertTrue($this->cache->has(['id' => 7])); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertFalse($this->cache->has(['id' => 8])); |
|
57
|
|
|
|
|
58
|
|
|
$cacheElement = $this->cache->get(['id' => 7]); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertInstanceOf(CacheElement::class, $cacheElement); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testGetUrl(): void |
|
64
|
|
|
{ |
|
65
|
|
|
$this->router |
|
66
|
|
|
->expects($this->once()) |
|
67
|
|
|
->method('generate') |
|
68
|
|
|
->with($this->equalTo('sonata_cache_apc'), $this->equalTo(['token' => 'token'])) |
|
69
|
|
|
->willReturn('/sonata/cache/apc/token'); |
|
70
|
|
|
|
|
71
|
|
|
$method = new \ReflectionMethod($this->cache, 'getUrl'); |
|
72
|
|
|
$method->setAccessible(true); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertSame('/sonata/cache/apc/token', $method->invoke($this->cache)); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|