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.
Gostei dessa sintaxe. E mocks que implementam interfaces (classes/objetos), tem algum rascunho? Penso em algo assim:
$mock = (new Mock('MockableClass'))([
'sayHelloTo' => function($name = 'Alexandre') {
return "Hello Alexandre";
}
]);
$mock = (new Mock($mockableObject))([
'sayHelloTo' => function($name = 'Alexandre') {
return "Hello Alexandre";
}
]);