Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
82.35% covered (warning)
82.35%
14 / 17
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
SchemaGraphqlProvider
82.35% covered (warning)
82.35%
14 / 17
50.00% covered (danger)
50.00%
1 / 2
5.14
0.00% covered (danger)
0.00%
0 / 1
 bootstrap
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 verifyValidResponse
78.57% covered (warning)
78.57%
11 / 14
0.00% covered (danger)
0.00%
0 / 1
4.16
1<?php
2namespace Apie\IntegrationTests\Graphql;
3
4use Apie\Common\IntegrationTestLogger;
5use Apie\IntegrationTests\Interfaces\TestApplicationInterface;
6use PHPUnit\Framework\TestCase;
7use Psr\Http\Message\ResponseInterface;
8
9class SchemaGraphqlProvider extends GraphqlProvider
10{
11    private string $key;
12    public function bootstrap(TestApplicationInterface $testApplication): void
13    {
14        $config = $testApplication->getApplicationConfig();
15        $this->key = get_class($testApplication) . ',' . $config->getDatalayerImplementation()->name;
16        parent::bootstrap($testApplication);
17    }
18
19    public function verifyValidResponse(ResponseInterface $response): void
20    {
21        $body = (string) $response->getBody();
22        $statusCode = $response->getStatusCode();
23        if ($statusCode === 500) {
24            IntegrationTestLogger::failTestShowError();
25        }
26        TestCase::assertEquals(200, $statusCode, 'Expect object created, got: ' . $body);
27        if (IntegrationTestLogger::getLoggedException()) {
28            IntegrationTestLogger::failTestShowError($statusCode);
29        }
30        $data = json_decode($body, true);
31        if (isset($data['errors'])) {
32            TestCase::fail('GraphQL errors: ' . json_encode($data['errors'], JSON_PRETTY_PRINT));
33        }
34        $this->expectedResponse = $data;
35        $fixtureFile = __DIR__ . '/../../fixtures/Graphql/Schemas/' . md5($this->key . json_encode($this->graphQlQuery)) . 'Schema.json';
36        file_put_contents($fixtureFile, json_encode($data, JSON_PRETTY_PRINT));
37        parent::verifyValidResponse($response);
38    }
39}