1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Pitchart\Phlunit\Checks; |
5
|
|
|
|
6
|
|
|
use PHPUnit\Framework\Assert; |
7
|
|
|
use Pitchart\Phlunit\Checks\Mixin\TypeCheck; |
8
|
|
|
use Pitchart\Phlunit\Checks\Mixin\WithMessage; |
9
|
|
|
use Pitchart\Phlunit\Constraint\Xml\MatchesSchema; |
10
|
|
|
use Pitchart\Phlunit\Constraint\Xml\XmlUtility; |
11
|
|
|
|
12
|
|
|
class XmlCheck implements FluentCheck |
13
|
|
|
{ |
14
|
|
|
use TypeCheck, WithMessage; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var \DOMDocument |
18
|
|
|
*/ |
19
|
|
|
private $value; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* XmlCheck constructor. |
23
|
|
|
* |
24
|
|
|
* @param string|\DOMDocument $value |
25
|
|
|
*/ |
26
|
7 |
|
public function __construct($value) |
27
|
|
|
{ |
28
|
7 |
|
$this->value = XmlUtility::load($value); |
29
|
7 |
|
} |
30
|
|
|
|
31
|
2 |
|
public function isEqualTo($expected): self |
32
|
|
|
{ |
33
|
2 |
|
Assert::assertXmlStringEqualsXmlString($expected, $this->value, $this->message); |
34
|
2 |
|
return $this; |
35
|
|
|
} |
36
|
|
|
|
37
|
2 |
|
public function isNotEqualTo($expected): self |
38
|
|
|
{ |
39
|
2 |
|
Assert::assertXmlStringNotEqualsXmlString($expected, $this->value, $this->message); |
40
|
2 |
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
2 |
|
public function isEqualToFileContent(string $path): self |
44
|
|
|
{ |
45
|
2 |
|
Assert::assertXmlStringEqualsXmlFile($path, $this->value, $this->message); |
46
|
2 |
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
2 |
|
public function isNotEqualToFileContent(string $path): self |
50
|
|
|
{ |
51
|
2 |
|
Assert::assertXmlStringNotEqualsXmlFile($path, $this->value, $this->message); |
52
|
2 |
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
3 |
|
public function matchesSchema(string $schema): self |
56
|
|
|
{ |
57
|
3 |
|
Assert::assertThat($this->value, new MatchesSchema($schema), $this->message); |
58
|
3 |
|
return $this; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|