I use Laravel 5.5 and try to mock a public method of an class, which is used inside this class:
class ToTest {
public function filters() {
return 'original';
}
public function callMe() {
return $this->filters();
}
}
This is my Testcode:
public function it_should_call_bla_bla()
{
$mock = $this->mock(ToTest::class);
$mock->shouldReceive('filters')->andReturn('not orignial');
$toTest = app(ToTest::class);
print_r($toTest->callMe());
}
private function mock($class)
{
$mock = Mockery::mock(app($class))->makePartial();
$this->app->instance($class, $mock);
return $mock;
}
$toTest->callMe()
returns original
...
Aucun commentaire:
Enregistrer un commentaire