-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathPest.php
More file actions
69 lines (55 loc) · 2.5 KB
/
Copy pathPest.php
File metadata and controls
69 lines (55 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
use Anaf\Client;
use Anaf\Contracts\FileContract;
use Anaf\Contracts\Response;
use Anaf\Contracts\TransporterContract;
use Anaf\ValueObjects\ApiKey;
use Anaf\ValueObjects\Transporter\BaseUri;
use Anaf\ValueObjects\Transporter\Headers;
use Anaf\ValueObjects\Transporter\Payload;
use Anaf\ValueObjects\Transporter\QueryParams;
use Psr\Http\Message\ResponseInterface;
function mockClient(string $method, string $resource, Response|ResponseInterface|string|array $response, $methodName = 'requestObject')
{
$transporter = Mockery::mock(TransporterContract::class);
$transporter
->shouldReceive($methodName)
->once()
->withArgs(function (Payload $payload) use ($method, $resource) {
$baseUri = BaseUri::from('webservicesp.anaf.ro');
$headers = Headers::create();
$queryParams = QueryParams::create();
$request = $payload->toRequest($baseUri, $headers, $queryParams);
return $request->getMethod() === $method
&& $request->getUri()->getPath() === $resource;
})->andReturn($response);
return new Client($transporter);
}
function mockAuthorizedClient(string $method, string $resource, Response|ResponseInterface|FileContract|string|array $response, $methodName = 'requestObject')
{
$transporter = Mockery::mock(TransporterContract::class);
$transporter
->shouldReceive($methodName)
->once()
->withArgs(function (Payload $payload) use ($method, $resource) {
$baseUri = BaseUri::from('api.anaf.ro');
$headers = Headers::withAuthorization(ApiKey::from('foo'));
$queryParams = QueryParams::create();
$request = $payload->toRequest($baseUri, $headers, $queryParams);
return $request->getMethod() === $method
&& $request->getUri()->getPath() === $resource;
})->andReturn($response);
return new Client($transporter);
}
function checkStageValue(Client $anafClient, bool $expectedValue): void
{
$transporterReflection = new ReflectionClass($anafClient);
$transporterProperty = $transporterReflection->getProperty('transporter');
$transporterProperty->setAccessible(true);
$transporter = $transporterProperty->getValue($anafClient);
$stagingReflection = new ReflectionClass($transporter);
$stagingProperty = $stagingReflection->getProperty('isStage');
$stagingProperty->setAccessible(true);
$staging = $stagingProperty->getValue($transporter);
expect($staging)->toBe($expectedValue);
}