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\Driver; |
13
|
|
|
|
14
|
|
|
use Cubiche\Core\Metadata\Exception\MappingException; |
15
|
|
|
use Cubiche\Core\Metadata\Tests\Fixtures\Driver\AnnotationDriver; |
16
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
17
|
|
|
use Doctrine\Common\Annotations\AnnotationRegistry; |
18
|
|
|
use Doctrine\Common\Annotations\CachedReader; |
19
|
|
|
use Doctrine\Common\Cache\FilesystemCache; |
20
|
|
|
use mageekguy\atoum\adapter as Adapter; |
21
|
|
|
use mageekguy\atoum\annotations\extractor as Extractor; |
22
|
|
|
use mageekguy\atoum\asserter\generator as Generator; |
23
|
|
|
use mageekguy\atoum\test\assertion\manager as Manager; |
24
|
|
|
use mageekguy\atoum\tools\variable\analyzer as Analyzer; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* AbstractAnnotationDriverTests class. |
28
|
|
|
* |
29
|
|
|
* Generated by TestGenerator on 2017-05-16 at 13:17:21. |
30
|
|
|
*/ |
31
|
|
|
class AbstractAnnotationDriverTests extends DriverTestCase |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $cacheDirectory; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param Adapter $adapter |
40
|
|
|
* @param Extractor $annotationExtractor |
41
|
|
|
* @param Generator $asserterGenerator |
42
|
|
|
* @param Manager $assertionManager |
43
|
|
|
* @param \Closure $reflectionClassFactory |
44
|
|
|
* @param \Closure $phpExtensionFactory |
45
|
|
|
* @param Analyzer $analyzer |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
48
|
|
|
Adapter $adapter = null, |
49
|
|
|
Extractor $annotationExtractor = null, |
50
|
|
|
Generator $asserterGenerator = null, |
51
|
|
|
Manager $assertionManager = null, |
52
|
|
|
\Closure $reflectionClassFactory = null, |
53
|
|
|
\Closure $phpExtensionFactory = null, |
54
|
|
|
Analyzer $analyzer = null |
55
|
|
|
) { |
56
|
|
|
parent::__construct( |
57
|
|
|
$adapter, |
58
|
|
|
$annotationExtractor, |
59
|
|
|
$asserterGenerator, |
60
|
|
|
$assertionManager, |
61
|
|
|
$reflectionClassFactory, |
62
|
|
|
$phpExtensionFactory, |
63
|
|
|
$analyzer |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$this->cacheDirectory = __DIR__.'/../Driver/Cache'; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Create the cache directory. |
71
|
|
|
*/ |
72
|
|
|
public function setUp() |
73
|
|
|
{ |
74
|
|
|
if (!is_dir($this->cacheDirectory)) { |
75
|
|
|
mkdir($this->cacheDirectory); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Remove the cache directory. |
81
|
|
|
*/ |
82
|
|
|
public function tearDown() |
83
|
|
|
{ |
84
|
|
|
$this->rmdir($this->cacheDirectory); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return AnnotationDriver |
89
|
|
|
*/ |
90
|
|
View Code Duplication |
protected function createDriver() |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
$reader = new CachedReader( |
93
|
|
|
new AnnotationReader(), |
94
|
|
|
new FilesystemCache($this->cacheDirectory), |
95
|
|
|
$debug = true |
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
AnnotationRegistry::registerFile(__DIR__.'/../../Fixtures/Annotations/AggregateRoot.php'); |
|
|
|
|
99
|
|
|
AnnotationRegistry::registerFile(__DIR__.'/../../Fixtures/Annotations/Entity.php'); |
|
|
|
|
100
|
|
|
AnnotationRegistry::registerFile(__DIR__.'/../../Fixtures/Annotations/Field.php'); |
|
|
|
|
101
|
|
|
AnnotationRegistry::registerFile(__DIR__.'/../../Fixtures/Annotations/Id.php'); |
|
|
|
|
102
|
|
|
|
103
|
|
|
$driver = new AnnotationDriver($reader, [__DIR__.'/../../Fixtures']); |
104
|
|
|
$driver->addExcludePaths([ |
105
|
|
|
__DIR__.'/../../Fixtures/Annotations', |
106
|
|
|
__DIR__.'/../../Fixtures/Driver', |
107
|
|
|
__DIR__.'/../../Fixtures/mapping', |
108
|
|
|
__DIR__.'/../../Fixtures/mapping-two', |
109
|
|
|
]); |
110
|
|
|
$driver->setFileExtension('.php'); |
111
|
|
|
|
112
|
|
|
return $driver; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return AnnotationDriver |
117
|
|
|
*/ |
118
|
|
View Code Duplication |
protected function createEmptyDriver() |
|
|
|
|
119
|
|
|
{ |
120
|
|
|
$reader = new CachedReader( |
121
|
|
|
new AnnotationReader(), |
122
|
|
|
new FilesystemCache($this->cacheDirectory), |
123
|
|
|
$debug = true |
124
|
|
|
); |
125
|
|
|
|
126
|
|
|
return new AnnotationDriver($reader); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return AnnotationDriver |
131
|
|
|
*/ |
132
|
|
View Code Duplication |
protected function createDriverWithInvalidPaths() |
|
|
|
|
133
|
|
|
{ |
134
|
|
|
$reader = new CachedReader( |
135
|
|
|
new AnnotationReader(), |
136
|
|
|
new FilesystemCache($this->cacheDirectory), |
137
|
|
|
$debug = true |
138
|
|
|
); |
139
|
|
|
|
140
|
|
|
return new AnnotationDriver($reader, [__DIR__.'/../../Fixtures/Foo']); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Test excludePaths method. |
145
|
|
|
*/ |
146
|
|
|
public function testExcludePaths() |
147
|
|
|
{ |
148
|
|
|
$this |
149
|
|
|
->given($driver = $this->createDriver()) |
150
|
|
|
->then() |
151
|
|
|
->array($driver->excludePaths()) |
152
|
|
|
->hasSize(4) |
153
|
|
|
; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Test getAllClassNames method. |
158
|
|
|
*/ |
159
|
|
|
public function testGetAllClassNames() |
160
|
|
|
{ |
161
|
|
|
parent::testGetAllClassNames(); |
162
|
|
|
|
163
|
|
|
$this |
164
|
|
|
->given($driver = $this->createDriver()) |
165
|
|
|
->when($classNames = $driver->getAllClassNames()) |
166
|
|
|
->and($classNames = $driver->getAllClassNames()) |
167
|
|
|
->then() |
168
|
|
|
->array($classNames) |
169
|
|
|
->hasSize(4) |
170
|
|
|
; |
171
|
|
|
|
172
|
|
|
$this |
173
|
|
|
->given($driver = $this->createEmptyDriver()) |
174
|
|
|
->then() |
175
|
|
|
->exception(function () use ($driver) { |
176
|
|
|
$driver->getAllClassNames(); |
177
|
|
|
})->isInstanceOf(MappingException::class); |
178
|
|
|
|
179
|
|
|
$this |
180
|
|
|
->given($driver = $this->createDriverWithInvalidPaths()) |
181
|
|
|
->then() |
182
|
|
|
->exception(function () use ($driver) { |
183
|
|
|
$driver->getAllClassNames(); |
184
|
|
|
})->isInstanceOf(MappingException::class); |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|
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.