Level 5
Check this thread it might help https://github.com/laravel/framework/issues/19450
1 like
Summer Sale! All accounts are 50% off this week.
namespace App;
class Episode
{
public function __construct(public int $id)
{
}
public function save()
{
dump('here');
}
}
TestCase.php:
/** @test */
public function test_save_method()
{
$this->mock(Episode::class, function (MockInterface $m){
$m->shouldReceive('save')->andReturnTrue();
});
app(Episode::class)->save(); //No issue, save() method hicjacked as excepted
// But as soon i pass arguments:
app(Episode::class, ['id' => 2])->save(); //save method called an didnt mocked!
}
I want to mock Episode class, But the problem is when i pass arguments to the class the laravel container doesnt pass the mock object and instead call the real method
I describe in comments, Can anyone tell why is not pass mock object ?
Please or to participate in this conversation.