-
Notifications
You must be signed in to change notification settings - Fork 460
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
Alternative shouldReceive syntax #598
Alternative shouldReceive syntax #598
Conversation
@@ -178,10 +179,10 @@ public function mockery_init(\Mockery\Container $container = null, $partialObjec | |||
* @param string $methodName,... one or many methods that are expected to be called in this mock | |||
* @return \Mockery\Expectation | |||
*/ | |||
public function shouldReceive($methodName) | |||
public function shouldReceive($methodName = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
phpdoc needs updating to string|null ;)
<?php
require "vendor/autoload.php";
$mock = Mockery::mock();
$mock->shouldReceive()->foo(123)->andReturn(456);
$mock->shouldNotReceive()->bar(567);
var_dump($mock->foo(123));
$mock->shouldHaveReceived()->foo(123);
$mock->shouldNotHaveReceived()->bar(456);
Mockery::close(); |
Riffing on the same thing, I could leave the old school methods alone and do <?php
require "vendor/autoload.php";
$mock = Mockery::mock();
// $mock->shouldReceive("foo")->with(123)->once()->andReturn(456);
$mock->expect()->foo(123)->andReturn(456);
// $mock->shouldReceive("bar")->with(567)->andReturn(789);
$mock->allow()->bar(567)->andReturn(789); Might collide with some userland code. Not sure what equivalent I'd want to use for the spies. |
+1 |
27fd287
to
f46c074
Compare
Slightly academic, but removes ambiguity from Builder GoF pattern
f46c074
to
2e4373e
Compare
Not sure what people think about this, it just gets away from using strings for method names...