by wvenable · 13y ago · 0 comments
Parody\Mime::create('Vendor\Class\Project')
-> onCall('method') -> expect('argument one') -> give('response one')
-> onCall('method') -> expect('argument two') -> give('response two')
-> resolve();
When one could just use anonymous functions to give the same result with less API-as-code. Parody\Mime::create('Vendor\Class\Project')
-> onCall('method', function($param) {
if ($param == 'argument one') return 'response one';
if ($param == 'argument two') return 'response two';
) -> resolve();
This is more flexible, less code for the framework, and easier to learn.Parody\Mime::create('App\Text') -> onCall('create') -> expect('WTF' . DS . 'Yo') -> give(function($mime) { return $mime -> onCall('underscorize') -> give('wtf' . DS . 'yo') -> resolve(); });
https://github.com/dotink/inKWellToo/blob/master/external/te...
It's difficult to tell if you are only referring to the passing of the original Mime as an argument... which if you are, I presume is more a limitation of documentation. While it may be clever, it's a pretty standard use of callbacks to have arguments passed to them that may be useful inside.
A mocked class stands in for the original class. All the methods are stubs. Sometimes you need to provide functionality for the stub methods. Isn't it most logical to use a function to provide a stub method's body?
It's my opinion that all the stuff PHPUnit unit does with mocks (and JUnit as it's based on) is because Java didn't have anonymous functions. So you had to call methods to essentially construct code for the stub method body. But if you can provide actual code than all that API is unnecessary.