Open kaysonwu opened 3 years ago
Alright, here is the correct answer - it is possible with a custom trait 😁 (Laravel 10+, PHP 8.1+; source) but with limitations:
$mock = Mockery::mock(A::class, MockProperties::class);
$mock
->shouldUseProperty('b')
->value(
Mockery::mock(B::class), // or just `new B()`.
);
$mock->a();
Implementation is pretty simple but relies on internals :( Would be nice if Mockery will support something similar out of the box (readonly
and upcoming hooks make getters useless imo). The main difficulty - check if any of methods were called, to mark that property was used. Seems there is no built expectation for this case, and I've no idea how to implement it properly.
Does mockery support mock protected properties? What should I do if I can?