-
Notifications
You must be signed in to change notification settings - Fork 7
Convenience method for generates()->returns()
#140
Comments
At the moment, $stub->generates([Recoil::return_('a')], [Recoil::return_('b')]); And is also parallel to other similar methods, e.g. |
Ah, yes of course, and
Maybe we can revisit it once you're using Recoil+PHP 7, it's certainly not a big deal. I'll close for now. |
Reopening for discussion. As discussed externally, this kind of interface currrently seems like the best solution: $stub->generates(
['yieldA', 'yieldB'], 'returnA', // first generator
['yieldC', 'yieldD'], 'returnB' // second generator
); However, this doesn't account for a similar idea with throwing exceptions as the generators "response" / end event. I can think of a few options:
|
@jmalloc thoughts? |
I was initially leaning towards (1), but I could be swayed to (2) by a stiff breeze. The usual caveats apply to squishy input, but because this is only a convenience function and you can always use the extended form if you don't know what kind of value you'll be returning for some reason. |
I'm not sure if we already discussed this or not - but a really common pattern under Recoil / PHP 7 is to use
generates()->returns()
where you simply want a stubbed coroutine to return a specific value.Perhaps we could add a second parameter to
generates()
, which is the return value for PHP 7 generators:generates($values = array(), $returnValue = null)
So usage is imply:
$stub->generates([], new Thing());
Thoughts?
The text was updated successfully, but these errors were encountered: