-
Notifications
You must be signed in to change notification settings - Fork 17
Support for argument expectations in Stubs #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ class StubMarshaler | |
|
||
private $methodValue; | ||
|
||
private $methodArguments = null; | ||
|
||
public function __construct(InvocationOrder $matcher, $value) | ||
{ | ||
$this->methodMatcher = $matcher; | ||
|
@@ -28,4 +30,39 @@ public function getValue() | |
{ | ||
return $this->methodValue; | ||
} | ||
|
||
/** | ||
* @return array|null expected method arguments, null makes it skip the check | ||
*/ | ||
public function getArguments() | ||
{ | ||
return $this->methodArguments; | ||
} | ||
|
||
/** | ||
* Checks if a method is called with the specified arguments | ||
* | ||
* If the method is invoked with different arguments, an exception will be thrown. | ||
* | ||
* ```php | ||
* <?php | ||
* use \Codeception\Stub\Expected; | ||
* | ||
* $user = $this->make('User', [ | ||
* 'setName' => Expected::once()->with('Davert') | ||
* ]); | ||
* $user->setName('Davert'); | ||
* ?> | ||
* ``` | ||
* | ||
* @see \PHPUnit\Framework\MockObject\Builder\InvocationMocker::with | ||
* @param array ...$arguments | ||
* @return StubMarshaler | ||
*/ | ||
public function with(...$arguments) | ||
rbait marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This docblock is a good code documentation, but in order to be visible in documentation pages of https://codeception.com it must be documented elsewhere. There are some examples of using Stub in https://codeception.com/docs/05-UnitTests#Test-Doubles Your new functionality will only be available on PHP 7.2+ with PHPUnit 8.4 or 9, unless this change is merged to 2.x branch too. |
||
{ | ||
$this->methodArguments = $arguments; | ||
|
||
return $this; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.