|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\Cmp\Cache\Infrastructure; |
|
4
|
|
|
|
|
5
|
|
|
use Cmp\Cache\Domain\Exceptions\ExpiredException; |
|
6
|
|
|
use Cmp\Cache\Domain\Exceptions\NotFoundException; |
|
7
|
|
|
use PhpSpec\ObjectBehavior; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class ArrayCacheSpec |
|
11
|
|
|
* |
|
12
|
|
|
* @package spec\Cmp\Cache\Infrastructure |
|
13
|
|
|
* @mixin \Cmp\Cache\Infrastructure\ArrayCache |
|
14
|
|
|
*/ |
|
15
|
|
|
class ArrayCacheSpec extends ObjectBehavior |
|
16
|
|
|
{ |
|
17
|
|
|
function it_is_initializable() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->shouldHaveType('Cmp\Cache\Infrastructure\ArrayCache'); |
|
20
|
|
|
$this->shouldHaveType('Cmp\Cache\Domain\Cache'); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
function it_can_store_items() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->has('foo')->shouldReturn(false); |
|
26
|
|
|
$this->set('foo', 'bar'); |
|
27
|
|
|
$this->has('foo')->shouldReturn(true); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
function it_can_store_items_for_a_limited_period_of_time() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->has('foo')->shouldReturn(false); |
|
33
|
|
|
$this->set('foo', 'bar', 1); |
|
34
|
|
|
|
|
35
|
|
|
sleep(2); |
|
36
|
|
|
$this->shouldThrow(new ExpiredException('foo'))->duringGet('foo'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function it_throws_an_exception_when_trying_to_get_a_non_set_item() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->shouldThrow(new NotFoundException('foo'))->duringGet('foo'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_can_return_a_default_value_when_pulling_a_non_set_item() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->pull('foo', 'bar')->shouldReturn('bar'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function it_can_empty_the_cache() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->set('foo', 'bar'); |
|
52
|
|
|
$this->has('foo')->shouldReturn(true); |
|
53
|
|
|
|
|
54
|
|
|
$this->flush(); |
|
55
|
|
|
$this->has('foo')->shouldReturn(false); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|