ouzo icon indicating copy to clipboard operation
ouzo copied to clipboard

[Mock] Mocking magic methods

Open piotrooo opened this issue 10 years ago • 0 comments
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?

piotrooo avatar Jan 29 '15 19:01 piotrooo