From cb135993b214d87d1cc10359201d23b8ab2057bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Tue, 21 Apr 2020 23:02:40 +0200 Subject: [PATCH] Document fluent methods as such This will help static analyzers understand calls to these methods better. --- .../MockObject/Builder/InvocationMocker.php | 17 +++++++ src/Framework/MockObject/MockBuilder.php | 44 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/src/Framework/MockObject/Builder/InvocationMocker.php b/src/Framework/MockObject/Builder/InvocationMocker.php index 299f3d5a1de..76c08f02389 100644 --- a/src/Framework/MockObject/Builder/InvocationMocker.php +++ b/src/Framework/MockObject/Builder/InvocationMocker.php @@ -53,6 +53,9 @@ public function __construct(InvocationHandler $handler, Matcher $matcher, Config $this->configurableMethods = $configurableMethods; } + /** + * @return $this + */ public function id($id): self { $this->invocationHandler->registerMatcher($id, $this->matcher); @@ -60,6 +63,9 @@ public function id($id): self return $this; } + /** + * @return $this + */ public function will(Stub $stub): Identity { $this->matcher->setStub($stub); @@ -135,6 +141,9 @@ public function willThrowException(\Throwable $exception): self return $this->will($stub); } + /** + * @return $this + */ public function after($id): self { $this->matcher->setAfterMatchBuilderId($id); @@ -144,6 +153,8 @@ public function after($id): self /** * @throws RuntimeException + * + * @return $this */ public function with(...$arguments): self { @@ -158,6 +169,8 @@ public function with(...$arguments): self * @param array ...$arguments * * @throws RuntimeException + * + * @return $this */ public function withConsecutive(...$arguments): self { @@ -170,6 +183,8 @@ public function withConsecutive(...$arguments): self /** * @throws RuntimeException + * + * @return $this */ public function withAnyParameters(): self { @@ -184,6 +199,8 @@ public function withAnyParameters(): self * @param Constraint|string $constraint * * @throws RuntimeException + * + * @return $this */ public function method($constraint): self { diff --git a/src/Framework/MockObject/MockBuilder.php b/src/Framework/MockObject/MockBuilder.php index cacdcaaede5..3eeb36a0b60 100644 --- a/src/Framework/MockObject/MockBuilder.php +++ b/src/Framework/MockObject/MockBuilder.php @@ -188,6 +188,8 @@ public function getMockForTrait(): MockObject * Specifies the subset of methods to mock. Default is to mock none of them. * * @deprecated https://github.com/sebastianbergmann/phpunit/pull/3687 + * + * @return $this */ public function setMethods(?array $methods = null): self { @@ -206,6 +208,8 @@ public function setMethods(?array $methods = null): self * @param string[] $methods * * @throws RuntimeException + * + * @return $this */ public function onlyMethods(array $methods): self { @@ -250,6 +254,8 @@ public function onlyMethods(array $methods): self * @param string[] $methods * * @throws RuntimeException + * + * @return $this */ public function addMethods(array $methods): self { @@ -303,6 +309,8 @@ public function setMethodsExcept(array $methods = []): self /** * Specifies the arguments for the constructor. + * + * @return $this */ public function setConstructorArgs(array $args): self { @@ -313,6 +321,8 @@ public function setConstructorArgs(array $args): self /** * Specifies the name for the mock class. + * + * @return $this */ public function setMockClassName(string $name): self { @@ -323,6 +333,8 @@ public function setMockClassName(string $name): self /** * Disables the invocation of the original constructor. + * + * @return $this */ public function disableOriginalConstructor(): self { @@ -333,6 +345,8 @@ public function disableOriginalConstructor(): self /** * Enables the invocation of the original constructor. + * + * @return $this */ public function enableOriginalConstructor(): self { @@ -343,6 +357,8 @@ public function enableOriginalConstructor(): self /** * Disables the invocation of the original clone constructor. + * + * @return $this */ public function disableOriginalClone(): self { @@ -353,6 +369,8 @@ public function disableOriginalClone(): self /** * Enables the invocation of the original clone constructor. + * + * @return $this */ public function enableOriginalClone(): self { @@ -363,6 +381,8 @@ public function enableOriginalClone(): self /** * Disables the use of class autoloading while creating the mock object. + * + * @return $this */ public function disableAutoload(): self { @@ -373,6 +393,8 @@ public function disableAutoload(): self /** * Enables the use of class autoloading while creating the mock object. + * + * @return $this */ public function enableAutoload(): self { @@ -383,6 +405,8 @@ public function enableAutoload(): self /** * Disables the cloning of arguments passed to mocked methods. + * + * @return $this */ public function disableArgumentCloning(): self { @@ -393,6 +417,8 @@ public function disableArgumentCloning(): self /** * Enables the cloning of arguments passed to mocked methods. + * + * @return $this */ public function enableArgumentCloning(): self { @@ -403,6 +429,8 @@ public function enableArgumentCloning(): self /** * Enables the invocation of the original methods. + * + * @return $this */ public function enableProxyingToOriginalMethods(): self { @@ -413,6 +441,8 @@ public function enableProxyingToOriginalMethods(): self /** * Disables the invocation of the original methods. + * + * @return $this */ public function disableProxyingToOriginalMethods(): self { @@ -424,6 +454,8 @@ public function disableProxyingToOriginalMethods(): self /** * Sets the proxy target. + * + * @return $this */ public function setProxyTarget(object $object): self { @@ -432,6 +464,9 @@ public function setProxyTarget(object $object): self return $this; } + /** + * @return $this + */ public function allowMockingUnknownTypes(): self { $this->allowMockingUnknownTypes = true; @@ -439,6 +474,9 @@ public function allowMockingUnknownTypes(): self return $this; } + /** + * @return $this + */ public function disallowMockingUnknownTypes(): self { $this->allowMockingUnknownTypes = false; @@ -446,6 +484,9 @@ public function disallowMockingUnknownTypes(): self return $this; } + /** + * @return $this + */ public function enableAutoReturnValueGeneration(): self { $this->returnValueGeneration = true; @@ -453,6 +494,9 @@ public function enableAutoReturnValueGeneration(): self return $this; } + /** + * @return $this + */ public function disableAutoReturnValueGeneration(): self { $this->returnValueGeneration = false;