atoum / atoum

The modern, simple and intuitive PHP unit testing framework.
http://atoum.org
Other
1.45k stars 147 forks source link

Add shortcut to (un)orphanize/shunt a mock method #212

Closed marmotz closed 11 years ago

marmotz commented 11 years ago

Is it possible to add shortcut like this:

$mock = \mock\My\Mock;
// ... tests and other stuf...
$this->calling($mock)->orphanize('myMethod');
// shortcut to $this->calling($mock)->myMethod = function() {};

And, why not add also:

$this->calling($mock)->unorphanize('myMethod');

I use $this->calling() syntax, but if you want to create/use an other one... :) I use orphanize as method name, but if you want to use shunt or an other one... :)

mageekguy commented 11 years ago

All orphanized, shunted and overloaded methods was reset after mock class generation, so i think that your proposal is useless (see https://github.com/atoum/atoum/blob/master/classes/mock/generator.php#L197 for more informations).

marmotz commented 11 years ago

As written in my 2nd comment of my 1st code block, the purpose is to create a shortcut to $this->calling($mock)->myMethod = function() {}, not to shunt a future generated mock but to shunt a method to an existing mock for the next test to run.

mageekguy commented 11 years ago

Oh sorry for the mistake. It's not technically possible to do that because the mocked class can have a method with name orphanize or unorphanize. However, you can replace $this->calling($mock)->myMethod = function() {} by $this->calling($mock)->myMethod = null.

mageekguy commented 11 years ago

So, you want something like $this->calling($mock)->myMethod->doNothing() ? And you want to be able to do something like $this->calling($mock)->myMethod->doSomething() ? So you can be happy because it's now possible since commit 3ecffa80cff4c8bbfa21a39160d79f4349248dec!