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