Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| TestsDefaultWebdavXml | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| shouldDoResponseValidation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| verifyValidResponse | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | namespace Apie\IntegrationTests\Concerns; |
| 3 | |
| 4 | use Apie\IntegrationTests\FixtureUtils; |
| 5 | use PHPUnit\Framework\TestCase; |
| 6 | use Psr\Http\Message\ResponseInterface; |
| 7 | |
| 8 | trait TestsDefaultWebdavXml { |
| 9 | public function shouldDoResponseValidation(): bool |
| 10 | { |
| 11 | return true; |
| 12 | } |
| 13 | |
| 14 | |
| 15 | public function verifyValidResponse(ResponseInterface $response): void |
| 16 | { |
| 17 | $body = $response->getBody(); |
| 18 | // remove <s:stacktrace> because it is not deterministic because of full file path |
| 19 | $body = preg_replace('/<s:stacktrace>.*?<\/s:stacktrace>/s', '', (string) $body); |
| 20 | // remove <s:file> because they are not deterministic because of full file path |
| 21 | $body = preg_replace('/<s:file>.*?<\/s:file>/s', '', (string) $body); |
| 22 | // remove <s:line> because they are not deterministic because of full file path |
| 23 | $body = preg_replace('/<s:line>.*?<\/s:line>/s', '', (string) $body); |
| 24 | |
| 25 | if (!$this->faked) { |
| 26 | TestCase::assertEquals($this->getExpectedStatusCode(), $response->getStatusCode(), 'Body is ' . substr($response->getBody(), 0, 400)); |
| 27 | $fixtureFile = __DIR__ . '/../../fixtures/Webdav/' . $this->getTestName() . '.xml'; |
| 28 | |
| 29 | if (FixtureUtils::shouldOverwriteWebdavFixtures() || !file_exists($fixtureFile)) { |
| 30 | $xmlString = $body; |
| 31 | $dom = new \DOMDocument(); |
| 32 | $dom->preserveWhiteSpace = false; |
| 33 | $dom->formatOutput = true; |
| 34 | $dom->loadXML($xmlString); |
| 35 | file_put_contents($fixtureFile, $dom->saveXML()); |
| 36 | } |
| 37 | TestCase::assertXmlStringEqualsXmlFile($fixtureFile, $body); |
| 38 | } |
| 39 | TestCase::assertEquals('application/xml; charset=utf-8', $response->getHeaderLine('Content-Type')); |
| 40 | } |
| 41 | } |