Skip to content

Commit cb13599

Browse files
greg0iresebastianbergmann
authored andcommitted
Document fluent methods as such
This will help static analyzers understand calls to these methods better.
1 parent 1cc2dcf commit cb13599

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/Framework/MockObject/Builder/InvocationMocker.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,19 @@ public function __construct(InvocationHandler $handler, Matcher $matcher, Config
5353
$this->configurableMethods = $configurableMethods;
5454
}
5555

56+
/**
57+
* @return $this
58+
*/
5659
public function id($id): self
5760
{
5861
$this->invocationHandler->registerMatcher($id, $this->matcher);
5962

6063
return $this;
6164
}
6265

66+
/**
67+
* @return $this
68+
*/
6369
public function will(Stub $stub): Identity
6470
{
6571
$this->matcher->setStub($stub);
@@ -135,6 +141,9 @@ public function willThrowException(\Throwable $exception): self
135141
return $this->will($stub);
136142
}
137143

144+
/**
145+
* @return $this
146+
*/
138147
public function after($id): self
139148
{
140149
$this->matcher->setAfterMatchBuilderId($id);
@@ -144,6 +153,8 @@ public function after($id): self
144153

145154
/**
146155
* @throws RuntimeException
156+
*
157+
* @return $this
147158
*/
148159
public function with(...$arguments): self
149160
{
@@ -158,6 +169,8 @@ public function with(...$arguments): self
158169
* @param array ...$arguments
159170
*
160171
* @throws RuntimeException
172+
*
173+
* @return $this
161174
*/
162175
public function withConsecutive(...$arguments): self
163176
{
@@ -170,6 +183,8 @@ public function withConsecutive(...$arguments): self
170183

171184
/**
172185
* @throws RuntimeException
186+
*
187+
* @return $this
173188
*/
174189
public function withAnyParameters(): self
175190
{
@@ -184,6 +199,8 @@ public function withAnyParameters(): self
184199
* @param Constraint|string $constraint
185200
*
186201
* @throws RuntimeException
202+
*
203+
* @return $this
187204
*/
188205
public function method($constraint): self
189206
{

src/Framework/MockObject/MockBuilder.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ public function getMockForTrait(): MockObject
188188
* Specifies the subset of methods to mock. Default is to mock none of them.
189189
*
190190
* @deprecated https://github.com/sebastianbergmann/phpunit/pull/3687
191+
*
192+
* @return $this
191193
*/
192194
public function setMethods(?array $methods = null): self
193195
{
@@ -206,6 +208,8 @@ public function setMethods(?array $methods = null): self
206208
* @param string[] $methods
207209
*
208210
* @throws RuntimeException
211+
*
212+
* @return $this
209213
*/
210214
public function onlyMethods(array $methods): self
211215
{
@@ -250,6 +254,8 @@ public function onlyMethods(array $methods): self
250254
* @param string[] $methods
251255
*
252256
* @throws RuntimeException
257+
*
258+
* @return $this
253259
*/
254260
public function addMethods(array $methods): self
255261
{
@@ -303,6 +309,8 @@ public function setMethodsExcept(array $methods = []): self
303309

304310
/**
305311
* Specifies the arguments for the constructor.
312+
*
313+
* @return $this
306314
*/
307315
public function setConstructorArgs(array $args): self
308316
{
@@ -313,6 +321,8 @@ public function setConstructorArgs(array $args): self
313321

314322
/**
315323
* Specifies the name for the mock class.
324+
*
325+
* @return $this
316326
*/
317327
public function setMockClassName(string $name): self
318328
{
@@ -323,6 +333,8 @@ public function setMockClassName(string $name): self
323333

324334
/**
325335
* Disables the invocation of the original constructor.
336+
*
337+
* @return $this
326338
*/
327339
public function disableOriginalConstructor(): self
328340
{
@@ -333,6 +345,8 @@ public function disableOriginalConstructor(): self
333345

334346
/**
335347
* Enables the invocation of the original constructor.
348+
*
349+
* @return $this
336350
*/
337351
public function enableOriginalConstructor(): self
338352
{
@@ -343,6 +357,8 @@ public function enableOriginalConstructor(): self
343357

344358
/**
345359
* Disables the invocation of the original clone constructor.
360+
*
361+
* @return $this
346362
*/
347363
public function disableOriginalClone(): self
348364
{
@@ -353,6 +369,8 @@ public function disableOriginalClone(): self
353369

354370
/**
355371
* Enables the invocation of the original clone constructor.
372+
*
373+
* @return $this
356374
*/
357375
public function enableOriginalClone(): self
358376
{
@@ -363,6 +381,8 @@ public function enableOriginalClone(): self
363381

364382
/**
365383
* Disables the use of class autoloading while creating the mock object.
384+
*
385+
* @return $this
366386
*/
367387
public function disableAutoload(): self
368388
{
@@ -373,6 +393,8 @@ public function disableAutoload(): self
373393

374394
/**
375395
* Enables the use of class autoloading while creating the mock object.
396+
*
397+
* @return $this
376398
*/
377399
public function enableAutoload(): self
378400
{
@@ -383,6 +405,8 @@ public function enableAutoload(): self
383405

384406
/**
385407
* Disables the cloning of arguments passed to mocked methods.
408+
*
409+
* @return $this
386410
*/
387411
public function disableArgumentCloning(): self
388412
{
@@ -393,6 +417,8 @@ public function disableArgumentCloning(): self
393417

394418
/**
395419
* Enables the cloning of arguments passed to mocked methods.
420+
*
421+
* @return $this
396422
*/
397423
public function enableArgumentCloning(): self
398424
{
@@ -403,6 +429,8 @@ public function enableArgumentCloning(): self
403429

404430
/**
405431
* Enables the invocation of the original methods.
432+
*
433+
* @return $this
406434
*/
407435
public function enableProxyingToOriginalMethods(): self
408436
{
@@ -413,6 +441,8 @@ public function enableProxyingToOriginalMethods(): self
413441

414442
/**
415443
* Disables the invocation of the original methods.
444+
*
445+
* @return $this
416446
*/
417447
public function disableProxyingToOriginalMethods(): self
418448
{
@@ -424,6 +454,8 @@ public function disableProxyingToOriginalMethods(): self
424454

425455
/**
426456
* Sets the proxy target.
457+
*
458+
* @return $this
427459
*/
428460
public function setProxyTarget(object $object): self
429461
{
@@ -432,27 +464,39 @@ public function setProxyTarget(object $object): self
432464
return $this;
433465
}
434466

467+
/**
468+
* @return $this
469+
*/
435470
public function allowMockingUnknownTypes(): self
436471
{
437472
$this->allowMockingUnknownTypes = true;
438473

439474
return $this;
440475
}
441476

477+
/**
478+
* @return $this
479+
*/
442480
public function disallowMockingUnknownTypes(): self
443481
{
444482
$this->allowMockingUnknownTypes = false;
445483

446484
return $this;
447485
}
448486

487+
/**
488+
* @return $this
489+
*/
449490
public function enableAutoReturnValueGeneration(): self
450491
{
451492
$this->returnValueGeneration = true;
452493

453494
return $this;
454495
}
455496

497+
/**
498+
* @return $this
499+
*/
456500
public function disableAutoReturnValueGeneration(): self
457501
{
458502
$this->returnValueGeneration = false;

0 commit comments

Comments
 (0)