So I have class name Verify which calls SMS vendor to verify the otp. Now I am writing http tests in Laravel.
How can I write the HTTP tests so that when that route is executed mock Verify is called not the real implementation.
So I have class name Verify which calls SMS vendor to verify the otp. Now I am writing http tests in Laravel.
How can I write the HTTP tests so that when that route is executed mock Verify is called not the real implementation.
It's hard to give an exact answer without seeing some of your implementation, including the test and the class being tested, but one thing to check is that after you've created your mock, you need to bind it into the service container.
Here's a rough example, knowing nothing about the class or its methods:
$mock = Mockery::mock(Verify::class);
$mock->shouldReceive('verify')
->once()
->andReturn(true);
App::instance(Verify::class, $mock);
Then make sure that wherever you create and use the Verify class, you retrieve an instance out of the service container.
$verify = App::make(Verify::class);
// instead of $verify = new Verify();
At that point you should have the mock instance during your tests, and not the real class. More information on binding and the service container in general can be found in the documentation, and on Laracasts