Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
TestsDefaultWebdavXml
100.00% covered (success)
100.00%
18 / 18
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%
17 / 17
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', '', $body);
23        // remove <s:line> because they are not deterministic because of full file path
24        $body = preg_replace('/<s:line>.*?<\/s:line>/s', '', $body);
25        $body = str_replace('<s:code>0</s:code>', '', $body);
26
27        if (!$this->faked) {
28            TestCase::assertEquals($this->getExpectedStatusCode(), $response->getStatusCode(), 'Body is ' . substr($response->getBody(), 0, 400));
29            $fixtureFile = __DIR__ . '/../../fixtures/Webdav/' . $this->getTestName() . '.xml';
30        
31            if (FixtureUtils::shouldOverwriteWebdavFixtures() || !file_exists($fixtureFile)) {
32                $xmlString = $body;
33                $dom = new \DOMDocument();
34                $dom->preserveWhiteSpace = false;
35                $dom->formatOutput = true;
36                $dom->loadXML($xmlString);
37                file_put_contents($fixtureFile, $dom->saveXML());
38            }
39            TestCase::assertXmlStringEqualsXmlFile($fixtureFile, $body);
40        }
41        TestCase::assertEquals('application/xml; charset=utf-8', $response->getHeaderLine('Content-Type'));
42    }
43}