Maybe before the -visit() call do :
$this->app->instance('GuzzleHttp\Client', $guzzle);
I have this controller:
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class SomeController extends Controller
{
protected $guzzle;
public function __construct(\GuzzleHttp\Client $guzzle)
{
$this->guzzle = $guzzle;
}
public function index() {
$url = "api.domain.com/{request()->token}";
$this->guzzle->get($url);
return 'welcome';
}
}
When i try to test the functionality of the index page i of course i want to mock the get method and not actually fire it.
Also i want to make sure that the get method on guzzle has been called with the right url.
This is my test method
/** @test */
public function it_tests_the_index_page()
{
$token = 123456;
$url = "api.domain.com/{$token}";
$guzzle = Mockery::mock(\GuzzleHttp\Client::class);
$guzzle->shouldReceive('get')
->with($url)
->andReturn('OK');
$this->visit("/?token={$token}")
->see('welcome');
}
When i run my test suite; guzzle fire the actual request with fake token i provided not the mocked method and of course the api returns an error because it's an invalid token. I just want to test that it get's the proper url.
Maybe before the -visit() call do :
$this->app->instance('GuzzleHttp\Client', $guzzle);
Please or to participate in this conversation.