ouzo
ouzo copied to clipboard
[Mock] Mocking magic methods
trafficstars
Let's look at this example:
class Magic
{
public function __call($name, $arguments)
{
if (Strings::contains($name, 'Id')) {
return 'some user find by id';
}
if (Strings::contains($name, 'Login')) {
return 'some user find by login';
}
return null;
}
}
I call method e.g.:
$magic = new Magick();
$magic->findById(); // result: some user find by id
Now I want to mock this method:
/**
* @test
*/
public function shouldMockMagic()
{
//given
$mock = Mock::create('\Tests\Magic');
//when
$byId = Mock::when($mock)->findById()->thenReturn("mocked");
//then
$this->assertEquals('mocked', $byId);
}
Now it's not possible. Maybe this will be a nice feature? What do you think?