Skip to content

Commit 671dc2a

Browse files
committed
add ProjectFactoryStrategy return;
adjust testcase mocks to fit;
1 parent d8bc5cb commit 671dc2a

File tree

9 files changed

+167
-51
lines changed

9 files changed

+167
-51
lines changed

src/phpDocumentor/Reflection/Php/ProjectFactoryStrategies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(array $strategies)
4444
* @return ProjectFactoryStrategy
4545
* @throws OutOfBoundsException when no matching strategy was found.
4646
*/
47-
public function findMatching($object)
47+
public function findMatching($object): ProjectFactoryStrategy
4848
{
4949
foreach ($this->strategies as $strategy) {
5050
if ($strategy->matches($object)) {

src/phpDocumentor/Reflection/Php/StrategyContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ interface StrategyContainer
2828
* @return ProjectFactoryStrategy
2929
* @throws Exception when no matching strategy was found.
3030
*/
31-
public function findMatching($object);
31+
public function findMatching($object): ProjectFactoryStrategy;
3232
}

tests/unit/phpDocumentor/Reflection/Php/Factory/Class_Test.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use phpDocumentor\Reflection\Php\Class_ as ClassElement;
1919
use phpDocumentor\Reflection\Php\Constant as ConstantElement;
2020
use phpDocumentor\Reflection\Php\Method as MethodElement;
21+
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
2122
use phpDocumentor\Reflection\Php\Property as PropertyElement;
2223
use phpDocumentor\Reflection\Php\StrategyContainer;
2324
use PhpParser\Comment\Doc;
@@ -123,17 +124,22 @@ public function testWithMethodMembers()
123124
{
124125
$method1 = new ClassMethod('MyClass::method1');
125126
$method1Descriptor = new MethodElement(new Fqsen('\MyClass::method1'));
127+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
126128
$containerMock = m::mock(StrategyContainer::class);
127129
$classMock = $this->buildClassMock();
128130
$classMock->shouldReceive('getDocComment')->andReturnNull();
129131
$classMock->stmts = [
130132
$method1,
131133
];
132134

133-
$containerMock->shouldReceive('findMatching->create')
135+
$strategyMock->shouldReceive('create')
134136
->with($method1, $containerMock, null)
135137
->andReturn($method1Descriptor);
136138

139+
$containerMock->shouldReceive('findMatching')
140+
->with($method1)
141+
->andReturn($strategyMock);
142+
137143
/** @var ClassDescriptor $class */
138144
$class = $this->fixture->create($classMock, $containerMock);
139145

@@ -153,17 +159,22 @@ public function testWithPropertyMembers()
153159
$propertyProperty = new PropertyProperty('\MyClass::$property');
154160
$property = new PropertyNode(1, [$propertyProperty]);
155161
$propertyDescriptor = new PropertyElement(new Fqsen('\MyClass::$property'));
162+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
156163
$containerMock = m::mock(StrategyContainer::class);
157164
$classMock = $this->buildClassMock();
158165
$classMock->shouldReceive('getDocComment')->andReturnNull();
159166
$classMock->stmts = [
160167
$property,
161168
];
162169

163-
$containerMock->shouldReceive('findMatching->create')
164-
->with(m::any(), $containerMock, null)
170+
$strategyMock->shouldReceive('create')
171+
->with(m::type(PropertyIterator::class), $containerMock, null)
165172
->andReturn($propertyDescriptor);
166173

174+
$containerMock->shouldReceive('findMatching')
175+
->with(m::type(PropertyIterator::class))
176+
->andReturn($strategyMock);
177+
167178
/** @var ClassElement $class */
168179
$class = $this->fixture->create($classMock, $containerMock);
169180

@@ -210,10 +221,17 @@ public function testWithConstants()
210221
$constant = new ClassConst([$const]);
211222

212223
$result = new ConstantElement(new Fqsen('\Space\MyClass::MY_CONST'));
224+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
213225
$containerMock = m::mock(StrategyContainer::class);
214-
$containerMock->shouldReceive('findMatching->create')
226+
227+
$strategyMock->shouldReceive('create')
215228
->with(m::type(ClassConstantIterator::class), $containerMock, null)
216229
->andReturn($result);
230+
231+
$containerMock->shouldReceive('findMatching')
232+
->with(m::type(ClassConstantIterator::class))
233+
->andReturn($strategyMock);
234+
217235
$classMock = $this->buildClassMock();
218236
$classMock->shouldReceive('getDocComment')->andReturnNull();
219237
$classMock->stmts = [
@@ -242,12 +260,17 @@ public function testCreateWithDocBlock()
242260

243261
$docBlock = new DocBlockElement('');
244262

263+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
245264
$containerMock = m::mock(StrategyContainer::class);
246-
$containerMock->shouldReceive('findMatching->create')
247-
->once()
265+
266+
$strategyMock->shouldReceive('create')
248267
->with($doc, $containerMock, null)
249268
->andReturn($docBlock);
250269

270+
$containerMock->shouldReceive('findMatching')
271+
->with($doc)
272+
->andReturn($strategyMock);
273+
251274
/** @var ClassElement $class */
252275
$class = $this->fixture->create($classMock, $containerMock);
253276

tests/unit/phpDocumentor/Reflection/Php/Factory/FileTest.php

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use phpDocumentor\Reflection\Php\Function_ as FunctionElement;
2323
use phpDocumentor\Reflection\Php\Interface_ as InterfaceElement;
2424
use phpDocumentor\Reflection\Php\NodesFactory;
25+
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
2526
use phpDocumentor\Reflection\Php\StrategyContainer;
2627
use phpDocumentor\Reflection\Php\Trait_ as TraitElement;
2728
use PhpParser\Comment as CommentNode;
@@ -74,13 +75,17 @@ public function testFileWithFunction()
7475
$functionNode,
7576
]
7677
);
77-
78+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
7879
$containerMock = m::mock(StrategyContainer::class);
79-
$containerMock->shouldReceive('findMatching->create')
80-
->once()
80+
81+
$strategyMock->shouldReceive('create')
8182
->with($functionNode, $containerMock, m::any())
8283
->andReturn(new FunctionElement(new Fqsen('\myFunction()')));
8384

85+
$containerMock->shouldReceive('findMatching')
86+
->with($functionNode)
87+
->andReturn($strategyMock);
88+
8489
/** @var FileElement $file */
8590
$file = $this->fixture->create(new SourceFile\LocalFile(__FILE__), $containerMock);
8691

@@ -101,13 +106,17 @@ public function testFileWithClass()
101106
$classNode,
102107
]
103108
);
104-
109+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
105110
$containerMock = m::mock(StrategyContainer::class);
106-
$containerMock->shouldReceive('findMatching->create')
107-
->once()
111+
112+
$strategyMock->shouldReceive('create')
108113
->with($classNode, $containerMock, m::any())
109114
->andReturn(new ClassElement(new Fqsen('\myClass')));
110115

116+
$containerMock->shouldReceive('findMatching')
117+
->with($classNode)
118+
->andReturn($strategyMock);
119+
111120
/** @var FileElement $file */
112121
$file = $this->fixture->create(new SourceFile\LocalFile(__FILE__), $containerMock);
113122

@@ -152,13 +161,17 @@ public function testFileWithInterface()
152161
$interfaceNode,
153162
]
154163
);
155-
164+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
156165
$containerMock = m::mock(StrategyContainer::class);
157-
$containerMock->shouldReceive('findMatching->create')
158-
->once()
166+
167+
$strategyMock->shouldReceive('create')
159168
->with($interfaceNode, $containerMock, m::any())
160169
->andReturn(new InterfaceElement(new Fqsen('\myInterface')));
161170

171+
$containerMock->shouldReceive('findMatching')
172+
->with($interfaceNode)
173+
->andReturn($strategyMock);
174+
162175
/** @var FileElement $file */
163176
$file = $this->fixture->create(new SourceFile\LocalFile(__FILE__), $containerMock);
164177

@@ -179,13 +192,17 @@ public function testFileWithTrait()
179192
$traitNode,
180193
]
181194
);
182-
195+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
183196
$containerMock = m::mock(StrategyContainer::class);
184-
$containerMock->shouldReceive('findMatching->create')
185-
->once()
197+
198+
$strategyMock->shouldReceive('create')
186199
->with($traitNode, $containerMock, m::any())
187200
->andReturn(new TraitElement(new Fqsen('\myTrait')));
188201

202+
$containerMock->shouldReceive('findMatching')
203+
->with($traitNode)
204+
->andReturn($strategyMock);
205+
189206
/** @var FileElement $file */
190207
$file = $this->fixture->create(new SourceFile\LocalFile(__FILE__), $containerMock);
191208

@@ -239,12 +256,17 @@ public function testFileDocBlockWithNamespace()
239256
->with(file_get_contents(__FILE__))
240257
->andReturn([$namespaceNode]);
241258

259+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
242260
$containerMock = m::mock(StrategyContainer::class);
243261

244-
$containerMock->shouldReceive('findMatching->create')
262+
$strategyMock->shouldReceive('create')
245263
->with($docBlockNode, $containerMock, m::any())
246264
->andReturn($docBlockDescriptor);
247265

266+
$containerMock->shouldReceive('findMatching')
267+
->with($docBlockNode)
268+
->andReturn($strategyMock);
269+
248270
/** @var FileElement $file */
249271
$file = $this->fixture->create(new SourceFile\LocalFile(__FILE__), $containerMock);
250272

@@ -266,17 +288,25 @@ public function testFileDocBlockWithClass()
266288
->with(file_get_contents(__FILE__))
267289
->andReturn([$classNode]);
268290

291+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
269292
$containerMock = m::mock(StrategyContainer::class);
270293

271-
$containerMock->shouldReceive('findMatching->create')
294+
$strategyMock->shouldReceive('create')
272295
->once()
273296
->with($classNode, $containerMock, m::any())
274297
->andReturn(new ClassElement(new Fqsen('\myClass')));
298+
$containerMock->shouldReceive('findMatching')
299+
->with($classNode)
300+
->andReturn($strategyMock);
275301

276-
$containerMock->shouldReceive('findMatching->create')
302+
$strategyMock->shouldReceive('create')
277303
->with($docBlockNode, $containerMock, m::any())
278304
->andReturn($docBlockDescriptor);
279305

306+
$containerMock->shouldReceive('findMatching')
307+
->with($docBlockNode)
308+
->andReturn($strategyMock);
309+
280310
/** @var FileElement $file */
281311
$file = $this->fixture->create(new SourceFile\LocalFile(__FILE__), $containerMock);
282312

@@ -299,12 +329,17 @@ public function testFileDocBlockWithComments()
299329
->with(file_get_contents(__FILE__))
300330
->andReturn([$namespaceNode]);
301331

332+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
302333
$containerMock = m::mock(StrategyContainer::class);
303334

304-
$containerMock->shouldReceive('findMatching->create')
335+
$strategyMock->shouldReceive('create')
305336
->with($docBlockNode, $containerMock, m::any())
306337
->andReturn($docBlockDescriptor);
307338

339+
$containerMock->shouldReceive('findMatching')
340+
->with($docBlockNode)
341+
->andReturn($strategyMock);
342+
308343
/** @var FileElement $file */
309344
$file = $this->fixture->create(new SourceFile\LocalFile(__FILE__), $containerMock);
310345

tests/unit/phpDocumentor/Reflection/Php/Factory/Function_Test.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use phpDocumentor\Reflection\DocBlock as DocBlockDescriptor;
1616
use phpDocumentor\Reflection\Fqsen;
1717
use phpDocumentor\Reflection\Php\Argument;
18+
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
1819
use phpDocumentor\Reflection\Php\Function_ as FunctionDescriptor;
1920
use phpDocumentor\Reflection\Php\StrategyContainer;
2021
use phpDocumentor\Reflection\Types\Integer;
@@ -78,12 +79,17 @@ public function testCreateWithParameters()
7879
$functionMock->shouldReceive('getLine')->andReturn(1);
7980
$functionMock->shouldReceive('getReturnType')->andReturnNull();
8081

82+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
8183
$containerMock = m::mock(StrategyContainer::class);
82-
$containerMock->shouldReceive('findMatching->create')
83-
->once()
84+
85+
$strategyMock->shouldReceive('create')
8486
->with('param1', $containerMock, null)
8587
->andReturn(new Argument('param1'));
8688

89+
$containerMock->shouldReceive('findMatching')
90+
->with('param1')
91+
->andReturn($strategyMock);
92+
8793
/** @var FunctionDescriptor $function */
8894
$function = $this->fixture->create($functionMock, $containerMock);
8995

@@ -146,13 +152,17 @@ public function testCreateWithDocBlock()
146152
$functionMock->shouldReceive('getReturnType')->andReturnNull();
147153

148154
$docBlock = new DocBlockDescriptor('');
149-
155+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
150156
$containerMock = m::mock(StrategyContainer::class);
151-
$containerMock->shouldReceive('findMatching->create')
152-
->once()
157+
158+
$strategyMock->shouldReceive('create')
153159
->with($doc, $containerMock, null)
154160
->andReturn($docBlock);
155161

162+
$containerMock->shouldReceive('findMatching')
163+
->with($doc)
164+
->andReturn($strategyMock);
165+
156166
/** @var FunctionDescriptor $function */
157167
$function = $this->fixture->create($functionMock, $containerMock);
158168

tests/unit/phpDocumentor/Reflection/Php/Factory/Interface_Test.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use phpDocumentor\Reflection\Php\Constant as ConstantElement;
1919
use phpDocumentor\Reflection\Php\Interface_ as InterfaceElement;
2020
use phpDocumentor\Reflection\Php\Method as MethodElement;
21+
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
2122
use phpDocumentor\Reflection\Php\StrategyContainer;
2223
use PhpParser\Comment\Doc;
2324
use PhpParser\Node\Const_;
@@ -75,13 +76,17 @@ public function testCreateWithDocBlock()
7576
$interfaceMock->shouldReceive('getDocComment')->andReturn($doc);
7677

7778
$docBlock = new DocBlockElement('');
78-
79+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
7980
$containerMock = m::mock(StrategyContainer::class);
80-
$containerMock->shouldReceive('findMatching->create')
81-
->once()
81+
82+
$strategyMock->shouldReceive('create')
8283
->with($doc, $containerMock, null)
8384
->andReturn($docBlock);
8485

86+
$containerMock->shouldReceive('findMatching')
87+
->with($doc)
88+
->andReturn($strategyMock);
89+
8590
/** @var InterfaceElement $interface */
8691
$interface = $this->fixture->create($interfaceMock, $containerMock);
8792

@@ -95,17 +100,22 @@ public function testWithMethodMembers()
95100
{
96101
$method1 = new ClassMethod('\Space\MyInterface::method1');
97102
$method1Descriptor = new MethodElement(new Fqsen('\Space\MyInterface::method1'));
103+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
98104
$containerMock = m::mock(StrategyContainer::class);
99105
$interfaceMock = $this->buildClassMock();
100106
$interfaceMock->shouldReceive('getDocComment')->andReturnNull();
101107
$interfaceMock->stmts = [
102108
$method1,
103109
];
104110

105-
$containerMock->shouldReceive('findMatching->create')
111+
$strategyMock->shouldReceive('create')
106112
->with($method1, $containerMock, null)
107113
->andReturn($method1Descriptor);
108114

115+
$containerMock->shouldReceive('findMatching')
116+
->with($method1)
117+
->andReturn($strategyMock);
118+
109119
$this->fixture->create($interfaceMock, $containerMock);
110120

111121
/** @var InterfaceElement $interface */
@@ -128,10 +138,17 @@ public function testWithConstants()
128138
$constant = new ClassConst([$const]);
129139

130140
$result = new ConstantElement(new Fqsen('\Space\MyClass::MY_CONST'));
141+
$strategyMock = m::mock(ProjectFactoryStrategy::class);
131142
$containerMock = m::mock(StrategyContainer::class);
132-
$containerMock->shouldReceive('findMatching->create')
143+
144+
$strategyMock->shouldReceive('create')
133145
->with(m::type(ClassConstantIterator::class), $containerMock, null)
134146
->andReturn($result);
147+
148+
$containerMock->shouldReceive('findMatching')
149+
->with(m::type(ClassConstantIterator::class))
150+
->andReturn($strategyMock);
151+
135152
$classMock = $this->buildClassMock();
136153
$classMock->shouldReceive('getDocComment')->andReturnNull();
137154
$classMock->stmts = [

0 commit comments

Comments
 (0)