Skip to content
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

Merged
merged 3 commits into from
Jan 17, 2017

Conversation

davedevelopment
Copy link
Collaborator

Not sure what people think about this, it just gets away from using strings for method names...

$mock->shouldReceive()->foo("bar")->andReturn(123);

@@ -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)
Copy link
Contributor

@GrahamCampbell GrahamCampbell May 17, 2016

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 ;)

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 75.416% when pulling 8eae1a0 on davedevelopment:alternative-syntax into ad31ff9 on padraic:master.

@davedevelopment
Copy link
Collaborator Author

<?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();

@davedevelopment
Copy link
Collaborator Author

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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 75.039% when pulling 27fd287 on davedevelopment:alternative-syntax into ad31ff9 on padraic:master.

@usox
Copy link

usox commented Aug 9, 2016

+1
A bit late but I would really prefer having real methods instead of dealing with method names a string-parameters.

@davedevelopment davedevelopment changed the title WIP: Alternative shouldReceive syntax Alternative shouldReceive syntax Jan 17, 2017
Slightly academic, but removes ambiguity from Builder GoF pattern
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 75.509% when pulling 2e4373e on davedevelopment:alternative-syntax into b4617ef on padraic:master.

@davedevelopment davedevelopment merged commit 2ff6984 into mockery:master Jan 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants