#HTTP fake not working
6 messages · Page 1 of 1 (latest)
The test:
it('should verify a domain successfully', function () {
Event::fake();
Http::preventStrayRequests();
Config::set('cloudflare.msaaq.api_key', 'test-api-key');
Config::set('cloudflare.msaaq.zone_id', 'sample-zone-id');
Http::fake([
'*' => Http::response([
'result' => [
'hostname' => 'test.example.com',
'status' => 'active',
'ssl' => [
'status' => 'active',
],
],
], 200),
]);
$domain = $this->academy->domains()->create([
'cf_zone_id' => 'sample-zone-id',
'cf_hostname_id' => 'sample-hostname-id',
'domain' => 'test.example.com',
'user_id' => $this->user->id,
'status' => 1,
'academy_id' => $this->academy->id,
]);
$this->putJson($this->baseUrl."/$domain->id/verify-activation");
Event::assertDispatched(DomainVerified::class);
Event::assertDispatched(TenantUpdated::class);
expect($domain->refresh()->verified_at->format('H:i:s'))->toBe(now()->format('H:i:s'));
});
The exception :
loudflare\API\Adapter\ResponseException]8;;file:///Users/sezoh/Downloads/Work/Masaaq/msaaq/vendor/cloudflare/sdk/src/Adapter/ResponseException.php#L13\^]8;;\ {#7099
#message: "Could not route to /client/v4/zones/sample-zone-id/custom_hostnames/sample-hostname-id, perhaps your object identifier is invalid?"
#code: 7003
#file: "]8;;file:///Users/sezoh/Downloads/Work/Masaaq/msaaq/vendor/cloudflare/sdk/src/Adapter/ResponseException.php#L38\./vendor/cloudflare/sdk/src/Adapter/ResponseException.php]8;;\"
#line: 38
-previous: GuzzleHttp\Exception\ClientException]8;;file:///Users/sezoh/Downloads/Work/Masaaq/msaaq/vendor/guzzlehttp/guzzle/src/Exception/ClientException.php#L8\^]8;;\ {#11010
#message: """
Client error: `GET https://api.cloudflare.com/client/v4/zones/sample-zone-id/custom_hostnames/sample-hostname-id` resulted in a `404 Not found` response:\n
{"result":null,"success":false,"errors":[{"code":7003,"message":"Could not route to /client/v4/zones/sample-zone-id/cust (truncated...)\n
"""
#code: 404
#file: "]8;;file:///Users/sezoh/Downloads/Work/Masaaq/msaaq/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php#L111\./vendor/guzzlehttp/guzzle/src/Exception/RequestException.php]8;;\"
#line: 111
-request: GuzzleHttp\Psr7\Request]8;;file:///Users/sezoh/Downloads/Work/Masaaq/msaaq/vendor/guzzlehttp/psr7/src/Request.php#L15\^]8;;\ {#9075
-method: "GET"
-requestTarget: null
-uri: GuzzleHttp\Psr7\Uri]8;;file:///Users/sezoh/Downloads/Work/Masaaq/msaaq/vendor/guzzlehttp/psr7/src/Uri.php#L17\^]8;;\ {#9069
-scheme: "https"
-userInfo: ""
-host: "api.cloudflare.com"
-port: null
-path: "/client/v4/zones/sample-zone-id/custom_hostnames/sample-hostname-id"
-query: ""
-fragment: ""
-composedComponents: "https://api.cloudflare.com/client/v4/zones/sample-zone-id/custom_hostnames/sample-hostname-id"
GitHub
PHP library for the Cloudflare v4 API. Contribute to cloudflare/cloudflare-php development by creating an account on GitHub.
aslo mocking api.cloudflare.com not working
Seems to be due to you using a generic php package, vs a laravel specific package. Meaning, the cloudflare package will use its own guzzle client directly, and not laravels http factory, thus using laravels http fake will have zero impact on the packages code, as I assume your endpoint is calling some http method from the package and not writing your own Http factory call. If that is the case, you'd need to mock/fake the package interfaces/methods themselves to get the outcome you want.