PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / apimatic / core / tests / Mocking / MockConverter.php
ameliabooking / vendor / apimatic / core / tests / Mocking Last commit date
Authentication 1 year ago Logger 1 year ago Other 1 year ago Response 1 year ago Types 1 year ago MockConverter.php 1 year ago MockHelper.php 1 year ago MockHttpClient.php 1 year ago
MockConverter.php
65 lines
1 <?php
2
3 namespace Core\Tests\Mocking;
4
5 use Core\Tests\Mocking\Other\MockException;
6 use Core\Tests\Mocking\Types\MockApiResponse;
7 use Core\Tests\Mocking\Types\MockContext;
8 use Core\Tests\Mocking\Types\MockCoreResponse;
9 use Core\Tests\Mocking\Types\MockFileWrapper;
10 use Core\Tests\Mocking\Types\MockRequest;
11 use CoreInterfaces\Core\ContextInterface;
12 use CoreInterfaces\Core\Request\RequestInterface;
13 use CoreInterfaces\Core\Response\ResponseInterface;
14 use CoreInterfaces\Sdk\ConverterInterface;
15
16 class MockConverter implements ConverterInterface
17 {
18 public function createApiException(
19 string $message,
20 RequestInterface $request,
21 ?ResponseInterface $response
22 ): MockException {
23 $response = $response == null ? null : $this->createHttpResponse($response);
24 return new MockException($message, $this->createHttpRequest($request), $response);
25 }
26
27 public function createHttpContext(ContextInterface $context): MockContext
28 {
29 return new MockContext(
30 $this->createHttpRequest($context->getRequest()),
31 $this->createHttpResponse($context->getResponse())
32 );
33 }
34
35 public function createHttpRequest(RequestInterface $request): MockRequest
36 {
37 return new MockRequest(
38 $request->getHttpMethod(),
39 $request->getHeaders(),
40 $request->getQueryUrl(),
41 $request->getParameters()
42 );
43 }
44
45 public function createHttpResponse(ResponseInterface $response): MockCoreResponse
46 {
47 return new MockCoreResponse(
48 $response->getStatusCode(),
49 $response->getHeaders(),
50 $response->getRawBody()
51 );
52 }
53
54 public function createApiResponse(ContextInterface $context, $deserializedBody): MockApiResponse
55 {
56 $decodedBody = $context->getResponse()->getBody();
57 return MockApiResponse::createFromContext($decodedBody, $deserializedBody, $this->createHttpContext($context));
58 }
59
60 public function createFileWrapper(string $realFilePath, ?string $mimeType, ?string $filename): MockFileWrapper
61 {
62 return MockFileWrapper::createFromPath($realFilePath, $mimeType, $filename);
63 }
64 }
65