1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Cmp\Cache\Application; |
4
|
|
|
|
5
|
|
|
use Cmp\Cache\Domain\Cache; |
6
|
|
|
use PhpSpec\ObjectBehavior; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class TestCacheDecoratorSpec |
10
|
|
|
* |
11
|
|
|
* @package spec\Cmp\Cache\Application |
12
|
|
|
* @mixin \Cmp\Cache\Application\TestCacheDecorator |
13
|
|
|
*/ |
14
|
|
|
class TestCacheDecoratorSpec extends ObjectBehavior |
15
|
|
|
{ |
16
|
|
|
function let(Cache $decorated) |
17
|
|
|
{ |
18
|
|
|
$this->beConstructedWith($decorated); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
function it_is_initializable() |
22
|
|
|
{ |
23
|
|
|
$this->shouldHaveType('\Cmp\Cache\Application\TestCacheDecorator'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
function it_can_register_a_set_operation(Cache $decorated) |
27
|
|
|
{ |
28
|
|
|
$this->hasBeenSet('foo', 'bar', 10)->shouldBe(false); |
29
|
|
|
$this->set('foo', 'bar', 10); |
30
|
|
|
|
31
|
|
|
$this->hasBeenSet('foo', 'bar', 10)->shouldBe(true); |
32
|
|
|
$this->hasBeenSet('foo', 'bar', 1)->shouldBe(false); |
33
|
|
|
$this->hasBeenSet('foo', 'nope')->shouldBe(false); |
34
|
|
|
$decorated->set('foo', 'bar', 10)->shouldHaveBeenCalled(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function it_can_register_a_has_operation(Cache $decorated) |
38
|
|
|
{ |
39
|
|
|
$decorated->has('foo')->willReturn(true); |
40
|
|
|
|
41
|
|
|
$this->hasBeenChecked('foo')->shouldBe(false); |
42
|
|
|
$this->has('foo')->shouldReturn(true); |
43
|
|
|
$this->hasBeenChecked('foo')->shouldBe(true); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
View Code Duplication |
function it_can_register_a_get_operation(Cache $decorated) |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$decorated->get('foo', 'default')->willReturn('bar'); |
49
|
|
|
|
50
|
|
|
$this->hasBeenGet('foo')->shouldBe(false); |
51
|
|
|
$this->get('foo', 'default')->shouldReturn('bar'); |
52
|
|
|
$this->hasBeenGet('foo')->shouldBe(true); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
function it_can_register_a_demand_operation(Cache $decorated) |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$decorated->demand('foo')->willReturn('bar'); |
58
|
|
|
|
59
|
|
|
$this->hasBeenDemanded('foo')->shouldBe(false); |
60
|
|
|
$this->demand('foo')->shouldReturn('bar'); |
61
|
|
|
$this->hasBeenDemanded('foo')->shouldBe(true); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
function it_can_register_a_delete_operation(Cache $decorated) |
65
|
|
|
{ |
66
|
|
|
$this->hasBeenDeleted('foo')->shouldBe(false); |
67
|
|
|
$this->delete('foo'); |
68
|
|
|
|
69
|
|
|
$this->hasBeenDeleted('foo')->shouldBe(true); |
70
|
|
|
$decorated->delete('foo')->shouldHaveBeenCalled(true); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
function it_can_register_a_flush_operation(Cache $decorated) |
74
|
|
|
{ |
75
|
|
|
$this->hasBeenFlushed()->shouldBe(false); |
76
|
|
|
$this->flush(); |
77
|
|
|
|
78
|
|
|
$this->hasBeenFlushed()->shouldBe(true); |
79
|
|
|
$decorated->flush()->shouldHaveBeenCalled(true); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.