@@ -7,49 +7,49 @@ |
||
7 | 7 | |
8 | 8 | class TextContentsMatcher extends TagMatcher { |
9 | 9 | |
10 | - /** |
|
11 | - * @var Matcher|string |
|
12 | - */ |
|
13 | - private $matcher; |
|
14 | - |
|
15 | - /** |
|
16 | - * @param Matcher|string $text |
|
17 | - * |
|
18 | - * @return self |
|
19 | - */ |
|
20 | - public static function havingTextContents( $text ) { |
|
21 | - return new static( $text ); |
|
22 | - } |
|
23 | - |
|
24 | - /** |
|
25 | - * @param Matcher|string $matcher |
|
26 | - */ |
|
27 | - public function __construct( $matcher ) { |
|
28 | - parent::__construct(); |
|
29 | - $this->matcher = $matcher; |
|
30 | - } |
|
31 | - |
|
32 | - public function describeTo( Description $description ) { |
|
33 | - $description->appendText( 'having text contents ' ); |
|
34 | - if ( $this->matcher instanceof Matcher ) { |
|
35 | - $description->appendDescriptionOf( $this->matcher ); |
|
36 | - } else { |
|
37 | - $description->appendValue( $this->matcher ); |
|
38 | - } |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @param \DOMElement $item |
|
43 | - * @param Description $mismatchDescription |
|
44 | - * |
|
45 | - * @return bool |
|
46 | - */ |
|
47 | - protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) { |
|
48 | - if ( $this->matcher instanceof Matcher ) { |
|
49 | - return $this->matcher->matches( $item->textContent ); |
|
50 | - } else { |
|
51 | - return $item->textContent === (string)$this->matcher; |
|
52 | - } |
|
53 | - } |
|
10 | + /** |
|
11 | + * @var Matcher|string |
|
12 | + */ |
|
13 | + private $matcher; |
|
14 | + |
|
15 | + /** |
|
16 | + * @param Matcher|string $text |
|
17 | + * |
|
18 | + * @return self |
|
19 | + */ |
|
20 | + public static function havingTextContents( $text ) { |
|
21 | + return new static( $text ); |
|
22 | + } |
|
23 | + |
|
24 | + /** |
|
25 | + * @param Matcher|string $matcher |
|
26 | + */ |
|
27 | + public function __construct( $matcher ) { |
|
28 | + parent::__construct(); |
|
29 | + $this->matcher = $matcher; |
|
30 | + } |
|
31 | + |
|
32 | + public function describeTo( Description $description ) { |
|
33 | + $description->appendText( 'having text contents ' ); |
|
34 | + if ( $this->matcher instanceof Matcher ) { |
|
35 | + $description->appendDescriptionOf( $this->matcher ); |
|
36 | + } else { |
|
37 | + $description->appendValue( $this->matcher ); |
|
38 | + } |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @param \DOMElement $item |
|
43 | + * @param Description $mismatchDescription |
|
44 | + * |
|
45 | + * @return bool |
|
46 | + */ |
|
47 | + protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) { |
|
48 | + if ( $this->matcher instanceof Matcher ) { |
|
49 | + return $this->matcher->matches( $item->textContent ); |
|
50 | + } else { |
|
51 | + return $item->textContent === (string)$this->matcher; |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | 55 | } |
@@ -8,75 +8,75 @@ |
||
8 | 8 | |
9 | 9 | class ChildElementMatcher extends TypeSafeDiagnosingMatcher { |
10 | 10 | |
11 | - /** |
|
12 | - * @var Matcher|string|null |
|
13 | - */ |
|
14 | - private $matcher; |
|
11 | + /** |
|
12 | + * @var Matcher|string|null |
|
13 | + */ |
|
14 | + private $matcher; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @param Matcher|string|null $elementMatcher |
|
18 | - * |
|
19 | - * @return self |
|
20 | - */ |
|
21 | - public static function havingChild( $elementMatcher = null ) { |
|
22 | - return new static( $elementMatcher ); |
|
23 | - } |
|
16 | + /** |
|
17 | + * @param Matcher|string|null $elementMatcher |
|
18 | + * |
|
19 | + * @return self |
|
20 | + */ |
|
21 | + public static function havingChild( $elementMatcher = null ) { |
|
22 | + return new static( $elementMatcher ); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * @param Matcher|string|null $matcher |
|
27 | - */ |
|
28 | - public function __construct( $matcher = null ) { |
|
29 | - parent::__construct( \DOMNode::class ); |
|
30 | - $this->matcher = $matcher; |
|
31 | - } |
|
25 | + /** |
|
26 | + * @param Matcher|string|null $matcher |
|
27 | + */ |
|
28 | + public function __construct( $matcher = null ) { |
|
29 | + parent::__construct( \DOMNode::class ); |
|
30 | + $this->matcher = $matcher; |
|
31 | + } |
|
32 | 32 | |
33 | - public function describeTo( Description $description ) { |
|
34 | - $description->appendText( 'having child ' ); |
|
35 | - if ( $this->matcher ) { |
|
36 | - if ( $this->matcher instanceof Matcher ) { |
|
37 | - $description->appendDescriptionOf( $this->matcher ); |
|
38 | - } else { |
|
39 | - $description->appendValue( $this->matcher ); |
|
40 | - } |
|
41 | - } |
|
42 | - } |
|
33 | + public function describeTo( Description $description ) { |
|
34 | + $description->appendText( 'having child ' ); |
|
35 | + if ( $this->matcher ) { |
|
36 | + if ( $this->matcher instanceof Matcher ) { |
|
37 | + $description->appendDescriptionOf( $this->matcher ); |
|
38 | + } else { |
|
39 | + $description->appendValue( $this->matcher ); |
|
40 | + } |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param \DOMDocument|\DOMNode $item |
|
46 | - * @param Description $mismatchDescription |
|
47 | - * |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) { |
|
51 | - if ( $item instanceof \DOMDocument ) { |
|
52 | - $item = $item->documentElement->childNodes->item( 0 ); |
|
53 | - /** @var \DOMElement $item */ |
|
54 | - } |
|
55 | - $directChildren = $item->childNodes; |
|
44 | + /** |
|
45 | + * @param \DOMDocument|\DOMNode $item |
|
46 | + * @param Description $mismatchDescription |
|
47 | + * |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + protected function matchesSafelyWithDiagnosticDescription( $item, Description $mismatchDescription ) { |
|
51 | + if ( $item instanceof \DOMDocument ) { |
|
52 | + $item = $item->documentElement->childNodes->item( 0 ); |
|
53 | + /** @var \DOMElement $item */ |
|
54 | + } |
|
55 | + $directChildren = $item->childNodes; |
|
56 | 56 | |
57 | - if ( $directChildren->length === 0 ) { |
|
58 | - $mismatchDescription->appendText( 'having no children' ); |
|
59 | - return false; |
|
60 | - } |
|
57 | + if ( $directChildren->length === 0 ) { |
|
58 | + $mismatchDescription->appendText( 'having no children' ); |
|
59 | + return false; |
|
60 | + } |
|
61 | 61 | |
62 | - if ( !$this->matcher ) { |
|
63 | - return true; |
|
64 | - } |
|
62 | + if ( !$this->matcher ) { |
|
63 | + return true; |
|
64 | + } |
|
65 | 65 | |
66 | - if ( $this->matcher instanceof Matcher ) { |
|
67 | - foreach ( new XmlNodeRecursiveIterator( $directChildren ) as $child ) { |
|
68 | - if ( $this->matcher->matches( $child ) ) { |
|
69 | - return true; |
|
70 | - } |
|
71 | - } |
|
72 | - } else { |
|
73 | - if ( $item->getElementsByTagName( $this->matcher )->length !== 0 ) { |
|
74 | - return true; |
|
75 | - } |
|
76 | - } |
|
66 | + if ( $this->matcher instanceof Matcher ) { |
|
67 | + foreach ( new XmlNodeRecursiveIterator( $directChildren ) as $child ) { |
|
68 | + if ( $this->matcher->matches( $child ) ) { |
|
69 | + return true; |
|
70 | + } |
|
71 | + } |
|
72 | + } else { |
|
73 | + if ( $item->getElementsByTagName( $this->matcher )->length !== 0 ) { |
|
74 | + return true; |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - $mismatchDescription->appendText( 'having no children ' )->appendDescriptionOf( $this->matcher ); |
|
79 | - return false; |
|
80 | - } |
|
78 | + $mismatchDescription->appendText( 'having no children ' )->appendDescriptionOf( $this->matcher ); |
|
79 | + return false; |
|
80 | + } |
|
81 | 81 | |
82 | 82 | } |