Skip to content

Commit

Permalink
Document fluent methods as such
Browse files Browse the repository at this point in the history
This will help static analyzers understand calls to these methods
better.
  • Loading branch information
greg0ire authored and sebastianbergmann committed Apr 22, 2020
1 parent 1cc2dcf commit cb13599
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Framework/MockObject/Builder/InvocationMocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ public function __construct(InvocationHandler $handler, Matcher $matcher, Config
$this->configurableMethods = $configurableMethods;
}

/**
* @return $this
*/
public function id($id): self
{
$this->invocationHandler->registerMatcher($id, $this->matcher);

return $this;
}

/**
* @return $this
*/
public function will(Stub $stub): Identity
{
$this->matcher->setStub($stub);
Expand Down Expand Up @@ -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);
Expand All @@ -144,6 +153,8 @@ public function after($id): self

/**
* @throws RuntimeException
*
* @return $this
*/
public function with(...$arguments): self
{
Expand All @@ -158,6 +169,8 @@ public function with(...$arguments): self
* @param array ...$arguments
*
* @throws RuntimeException
*
* @return $this
*/
public function withConsecutive(...$arguments): self
{
Expand All @@ -170,6 +183,8 @@ public function withConsecutive(...$arguments): self

/**
* @throws RuntimeException
*
* @return $this
*/
public function withAnyParameters(): self
{
Expand All @@ -184,6 +199,8 @@ public function withAnyParameters(): self
* @param Constraint|string $constraint
*
* @throws RuntimeException
*
* @return $this
*/
public function method($constraint): self
{
Expand Down
44 changes: 44 additions & 0 deletions src/Framework/MockObject/MockBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -206,6 +208,8 @@ public function setMethods(?array $methods = null): self
* @param string[] $methods
*
* @throws RuntimeException
*
* @return $this
*/
public function onlyMethods(array $methods): self
{
Expand Down Expand Up @@ -250,6 +254,8 @@ public function onlyMethods(array $methods): self
* @param string[] $methods
*
* @throws RuntimeException
*
* @return $this
*/
public function addMethods(array $methods): self
{
Expand Down Expand Up @@ -303,6 +309,8 @@ public function setMethodsExcept(array $methods = []): self

/**
* Specifies the arguments for the constructor.
*
* @return $this
*/
public function setConstructorArgs(array $args): self
{
Expand All @@ -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
{
Expand All @@ -323,6 +333,8 @@ public function setMockClassName(string $name): self

/**
* Disables the invocation of the original constructor.
*
* @return $this
*/
public function disableOriginalConstructor(): self
{
Expand All @@ -333,6 +345,8 @@ public function disableOriginalConstructor(): self

/**
* Enables the invocation of the original constructor.
*
* @return $this
*/
public function enableOriginalConstructor(): self
{
Expand All @@ -343,6 +357,8 @@ public function enableOriginalConstructor(): self

/**
* Disables the invocation of the original clone constructor.
*
* @return $this
*/
public function disableOriginalClone(): self
{
Expand All @@ -353,6 +369,8 @@ public function disableOriginalClone(): self

/**
* Enables the invocation of the original clone constructor.
*
* @return $this
*/
public function enableOriginalClone(): self
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -383,6 +405,8 @@ public function enableAutoload(): self

/**
* Disables the cloning of arguments passed to mocked methods.
*
* @return $this
*/
public function disableArgumentCloning(): self
{
Expand All @@ -393,6 +417,8 @@ public function disableArgumentCloning(): self

/**
* Enables the cloning of arguments passed to mocked methods.
*
* @return $this
*/
public function enableArgumentCloning(): self
{
Expand All @@ -403,6 +429,8 @@ public function enableArgumentCloning(): self

/**
* Enables the invocation of the original methods.
*
* @return $this
*/
public function enableProxyingToOriginalMethods(): self
{
Expand All @@ -413,6 +441,8 @@ public function enableProxyingToOriginalMethods(): self

/**
* Disables the invocation of the original methods.
*
* @return $this
*/
public function disableProxyingToOriginalMethods(): self
{
Expand All @@ -424,6 +454,8 @@ public function disableProxyingToOriginalMethods(): self

/**
* Sets the proxy target.
*
* @return $this
*/
public function setProxyTarget(object $object): self
{
Expand All @@ -432,27 +464,39 @@ public function setProxyTarget(object $object): self
return $this;
}

/**
* @return $this
*/
public function allowMockingUnknownTypes(): self
{
$this->allowMockingUnknownTypes = true;

return $this;
}

/**
* @return $this
*/
public function disallowMockingUnknownTypes(): self
{
$this->allowMockingUnknownTypes = false;

return $this;
}

/**
* @return $this
*/
public function enableAutoReturnValueGeneration(): self
{
$this->returnValueGeneration = true;

return $this;
}

/**
* @return $this
*/
public function disableAutoReturnValueGeneration(): self
{
$this->returnValueGeneration = false;
Expand Down

0 comments on commit cb13599

Please sign in to comment.