Trying to mock an http client that is inside a controller, using phpunit, but it doesn't work



PHP Snippet 1:

$client = resolve(GuzzleWrapper::class);

PHP Snippet 2:

$mockGuzzleClient = Mockery::mock(GuzzleWrapper::class, function (MockInterface $mock){
   $mock->shouldReceive('post')
        ->andReturn(response()->json([$responseData], 200));
});

PHP Snippet 3:

Http::post($uri, $data);

PHP Snippet 4:

Http::fake([
    $uri => Http::response(['your data' => 'response'], 200, []),
]);

PHP Snippet 5:

class ContactController {
    private GuzzleWrapper $client;

    public function __construct(GuzzleWrapper $client)
    {
        $this->client = $client;
    }

    public function addContacts(Request $request)
    {
       ...
       $response = $this->client->post($uri, $data);
       if($response->getStatusCode() != 200) { 
          return response()->json("Problem getting data", 500);
       }
       ...
    }
}