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