Reputation: 1
I am trying to run this very simple unit test on laravel model class. The real implementation instead of the mock keeps being called. Can anyone help me understand what’s going wrong.
class MockTest extends \Tests\TestCase
{
/**
* @test
*/
public function simpleMockTest()
{
$mock = Mockery::mock("App\Order[save]");
$mock->shouldReceive('save')->once()->andReturn(5);
$this->app->instance("App\Order", $mock);
$order = new Order();
$this->assertEquals(5, $order->save());
}
}
Upvotes: 0
Views: 1051
Reputation: 383
You're not getting the expected result because $order
is not using the mocked instance of App\Order
.
Using $mock
instead will give you expected result:
{
/**
* @test
*/
public function simpleMockTest()
{
$mock = Mockery::mock("App\Order")
->makePartial();
$mock->shouldReceive('save')->once()->andReturn(5);
$this->app->instance("App\Order", $mock);
$this->assertEquals(5, $mock->save());
}
}```
Upvotes: 1