It's not implemented yet. Just an idea. I'll explain every bit of it:
- Before PHP 5.4 we couldn't do something like
new bla->foo
directly. Now we can do(new bla)->foo
. - Assuming
(new Stub)
returns an instance of Stub and that class implements __invoke, we can automatically chain a invoke call on it, like '(new Stub)()'. This is equivalent to$s = new Stub; $s->__invoke();
. Just a syntactic sugar. - Arrays in PHP 5.4 can be declared as
['foo'=>'bar']
. This is the only argument __invoke from Stub receives. - Closures can be bound dynamically in PHP 5.4, so we could even use $this inside a stub.
- We can read the default parameters from closures using Reflection. That way we could use them as expectations. Executing the function gives us the expected return.
Agora que percebi que tem um fork exatamente com essas minhas indagações, mas com a implementação recebendo a classe a ser "mockada" no metodo __invoke, o que faz mais sentido mesmo.