1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Cmp\Cache\Factory; |
4
|
|
|
|
5
|
|
|
use Cmp\Cache\Backend\ArrayCache; |
6
|
|
|
use Cmp\Cache\Backend\ChainCache; |
7
|
|
|
use Cmp\Cache\Backend\RedisCache; |
8
|
|
|
use Cmp\Cache\Cache; |
9
|
|
|
use Cmp\Cache\Factory\CacheFactoryInterface; |
10
|
|
|
use PhpSpec\ObjectBehavior; |
11
|
|
|
use Psr\Log\LoggerInterface; |
12
|
|
|
use Psr\Log\LogLevel; |
13
|
|
|
use Redis; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class CacheBuilderSpec |
17
|
|
|
* |
18
|
|
|
* @package spec\Cmp\Cache\Factory |
19
|
|
|
* @mixin \Cmp\Cache\Factory\CacheBuilder |
20
|
|
|
*/ |
21
|
|
|
class CacheBuilderSpec extends ObjectBehavior |
22
|
|
|
{ |
23
|
|
|
function let(CacheFactoryInterface $factory) |
24
|
|
|
{ |
25
|
|
|
$this->beConstructedWith($factory); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function it_can_build_a_silent_cache(CacheFactoryInterface $factory, Cache $cache) |
29
|
|
|
{ |
30
|
|
|
$factory->arrayCache()->willReturn($cache); |
31
|
|
|
$factory->loggerCache($cache, false, null, LogLevel::ALERT)->willReturn($cache); |
32
|
|
|
|
33
|
|
|
$this->withoutExceptions()->shouldReturn($this); |
34
|
|
|
|
35
|
|
|
$this->build()->shouldBeAnInstanceOf($cache); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_can_build_a_cache_with_logging(CacheFactoryInterface $factory, Cache $cache, LoggerInterface $logger) |
39
|
|
|
{ |
40
|
|
|
$factory->arrayCache()->willReturn($cache); |
41
|
|
|
$factory->loggerCache($cache, true, $logger, 'warning')->willReturn($cache); |
42
|
|
|
|
43
|
|
|
$this->withLogging($logger, 'warning')->shouldReturn($this); |
44
|
|
|
|
45
|
|
|
$this->build()->shouldBeAnInstanceOf($cache); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
function it_can_chain_caches( |
49
|
|
|
CacheFactoryInterface $factory, |
50
|
|
|
ArrayCache $arrayCache, |
51
|
|
|
Redis $redis, |
52
|
|
|
Cache $anotherCache, |
53
|
|
|
RedisCache $redisOne, |
54
|
|
|
RedisCache $redisTwo, |
55
|
|
|
ChainCache $chainCache |
56
|
|
|
) { |
57
|
|
|
$factory->arrayCache()->willReturn($arrayCache); |
58
|
|
|
$factory->redisCache($redis)->willReturn($redisOne); |
59
|
|
|
$factory->redisFromParams('host', 'port', 'db', 'timeout')->willReturn($redisTwo); |
60
|
|
|
$factory->chainCache([$arrayCache, $anotherCache, $redisOne, $redisTwo])->willReturn($chainCache); |
61
|
|
|
|
62
|
|
|
$this->withArrayCache()->shouldReturn($this); |
63
|
|
|
$this->withCache($anotherCache)->shouldReturn($this); |
64
|
|
|
$this->withRedis($redis)->shouldReturn($this); |
65
|
|
|
$this->withRedisCacheFromParams('host', 'port', 'db', 'timeout')->shouldReturn($this); |
66
|
|
|
|
67
|
|
|
$this->build()->shouldBeAnInstanceOf($chainCache); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|