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