1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Cubiche/Metadata component. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) Cubiche |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Cubiche\Core\Metadata\Tests\Units\Cache; |
13
|
|
|
|
14
|
|
|
use Cubiche\Core\Metadata\Cache\CacheInterface; |
15
|
|
|
use Cubiche\Core\Metadata\ClassMetadata; |
16
|
|
|
use Cubiche\Core\Metadata\PropertyMetadata; |
17
|
|
|
use Cubiche\Core\Metadata\Tests\Fixtures\User; |
18
|
|
|
use Cubiche\Core\Metadata\Tests\Units\TestCase; |
19
|
|
|
use mageekguy\atoum\adapter as Adapter; |
20
|
|
|
use mageekguy\atoum\annotations\extractor as Extractor; |
21
|
|
|
use mageekguy\atoum\asserter\generator as Generator; |
22
|
|
|
use mageekguy\atoum\test\assertion\manager as Manager; |
23
|
|
|
use mageekguy\atoum\tools\variable\analyzer as Analyzer; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* CacheTestCase class. |
27
|
|
|
* |
28
|
|
|
* Generated by TestGenerator on 2017-05-16 at 13:17:21. |
29
|
|
|
* |
30
|
|
|
* @engine isolate |
31
|
|
|
*/ |
32
|
|
|
abstract class CacheTestCase extends TestCase |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
protected $cacheDirectory; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param Adapter $adapter |
41
|
|
|
* @param Extractor $annotationExtractor |
42
|
|
|
* @param Generator $asserterGenerator |
43
|
|
|
* @param Manager $assertionManager |
44
|
|
|
* @param \Closure $reflectionClassFactory |
45
|
|
|
* @param \Closure $phpExtensionFactory |
46
|
|
|
* @param Analyzer $analyzer |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
49
|
|
|
Adapter $adapter = null, |
50
|
|
|
Extractor $annotationExtractor = null, |
51
|
|
|
Generator $asserterGenerator = null, |
52
|
|
|
Manager $assertionManager = null, |
53
|
|
|
\Closure $reflectionClassFactory = null, |
54
|
|
|
\Closure $phpExtensionFactory = null, |
55
|
|
|
Analyzer $analyzer = null |
56
|
|
|
) { |
57
|
|
|
parent::__construct( |
58
|
|
|
$adapter, |
59
|
|
|
$annotationExtractor, |
60
|
|
|
$asserterGenerator, |
61
|
|
|
$assertionManager, |
62
|
|
|
$reflectionClassFactory, |
63
|
|
|
$phpExtensionFactory, |
64
|
|
|
$analyzer |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$this->cacheDirectory = __DIR__.'/Cache'; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return CacheInterface |
72
|
|
|
*/ |
73
|
|
|
abstract protected function createCache(); |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Create the cache directory. |
77
|
|
|
*/ |
78
|
|
|
public function setUp() |
79
|
|
|
{ |
80
|
|
|
if (!is_dir($this->cacheDirectory)) { |
81
|
|
|
mkdir($this->cacheDirectory); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Remove the cache directory. |
87
|
|
|
*/ |
88
|
|
|
public function tearDown() |
89
|
|
|
{ |
90
|
|
|
$this->rmdir($this->cacheDirectory); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Test Load method. |
95
|
|
|
*/ |
96
|
|
|
public function testLoad() |
97
|
|
|
{ |
98
|
|
|
$this |
99
|
|
|
->given($cache = $this->createCache()) |
100
|
|
|
->and($className = User::class) |
101
|
|
|
->then() |
102
|
|
|
->variable($cache->load($className)) |
103
|
|
|
->isNull() |
104
|
|
|
; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Test Save method. |
109
|
|
|
*/ |
110
|
|
|
public function testSave() |
111
|
|
|
{ |
112
|
|
|
$this |
113
|
|
|
->given($cache = $this->createCache()) |
114
|
|
|
->and($metadata = new ClassMetadata(User::class)) |
115
|
|
|
->and($metadata->addPropertyMetadata(new PropertyMetadata(User::class, 'name'))) |
116
|
|
|
->when($cache->save($metadata)) |
117
|
|
|
->then() |
118
|
|
|
->object($classMetadata = $cache->load(User::class)) |
119
|
|
|
->isInstanceOf(ClassMetadata::class) |
120
|
|
|
; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
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.