@@ 10-36 (lines=27) @@ | ||
7 | use Spatie\Snapshots\Driver; |
|
8 | use Spatie\Snapshots\Exceptions\CantBeSerialized; |
|
9 | ||
10 | class HtmlDriver implements Driver |
|
11 | { |
|
12 | public function serialize($data): string |
|
13 | { |
|
14 | if (! is_string($data)) { |
|
15 | throw new CantBeSerialized('Only strings can be serialized to html'); |
|
16 | } |
|
17 | ||
18 | $domDocument = new DOMDocument('1.0'); |
|
19 | $domDocument->preserveWhiteSpace = false; |
|
20 | $domDocument->formatOutput = true; |
|
21 | ||
22 | @$domDocument->loadHTML($data); // to ignore HTML5 errors |
|
23 | ||
24 | return $domDocument->saveHTML(); |
|
25 | } |
|
26 | ||
27 | public function extension(): string |
|
28 | { |
|
29 | return 'html'; |
|
30 | } |
|
31 | ||
32 | public function match($expected, $actual) |
|
33 | { |
|
34 | Assert::assertEquals($expected, $this->serialize($actual)); |
|
35 | } |
|
36 | } |
|
37 |
@@ 10-36 (lines=27) @@ | ||
7 | use Spatie\Snapshots\Driver; |
|
8 | use Spatie\Snapshots\Exceptions\CantBeSerialized; |
|
9 | ||
10 | class XmlDriver implements Driver |
|
11 | { |
|
12 | public function serialize($data): string |
|
13 | { |
|
14 | if (! is_string($data)) { |
|
15 | throw new CantBeSerialized('Only strings can be serialized to xml'); |
|
16 | } |
|
17 | ||
18 | $domDocument = new DOMDocument('1.0'); |
|
19 | $domDocument->preserveWhiteSpace = false; |
|
20 | $domDocument->formatOutput = true; |
|
21 | ||
22 | $domDocument->loadXML($data); |
|
23 | ||
24 | return $domDocument->saveXML(); |
|
25 | } |
|
26 | ||
27 | public function extension(): string |
|
28 | { |
|
29 | return 'xml'; |
|
30 | } |
|
31 | ||
32 | public function match($expected, $actual) |
|
33 | { |
|
34 | Assert::assertXmlStringEqualsXmlString($expected, $actual); |
|
35 | } |
|
36 | } |
|
37 |