diff --git a/src/Constraints/ContainsSelector.php b/src/Constraints/ContainsSelector.php index 0cd9348..66b8bbf 100644 --- a/src/Constraints/ContainsSelector.php +++ b/src/Constraints/ContainsSelector.php @@ -11,6 +11,8 @@ */ class ContainsSelector extends Constraint { + use ExporterTrait; + /** * @var Selector */ @@ -31,7 +33,7 @@ public function __construct(Selector $selector) */ public function toString(): string { - return 'contains selector ' . $this->exporter()->export($this->selector->getValue()); + return 'contains selector ' . $this->exportValue($this->selector->getValue()); } /** diff --git a/src/Constraints/ElementContainsString.php b/src/Constraints/ElementContainsString.php index ce6e890..9611a63 100644 --- a/src/Constraints/ElementContainsString.php +++ b/src/Constraints/ElementContainsString.php @@ -11,6 +11,8 @@ */ class ElementContainsString extends Constraint { + use ExporterTrait; + /** * A cache of matches that we have checked against. * @@ -56,7 +58,7 @@ public function toString(): string return sprintf( '%s string %s', count($this->matchingElements) >= 2 ? 'contain' : 'contains', - $this->exporter()->export($this->needle) + $this->exportValue($this->needle) ); } @@ -115,7 +117,7 @@ protected function failureDescription($html): string return sprintf( $label, - $this->exporter()->export($this->selector->getValue()), + $this->exportValue($this->selector->getValue()), $this->toString() ); } diff --git a/src/Constraints/ElementMatchesRegExp.php b/src/Constraints/ElementMatchesRegExp.php index 9a4e0e4..c0f005d 100644 --- a/src/Constraints/ElementMatchesRegExp.php +++ b/src/Constraints/ElementMatchesRegExp.php @@ -12,6 +12,8 @@ */ class ElementMatchesRegExp extends ElementContainsString { + use ExporterTrait; + /** * @var string */ @@ -37,7 +39,7 @@ public function toString(): string return sprintf( '%s regular expression %s', count($this->matchingElements) >= 2 ? 'match' : 'matches', - $this->exporter()->export($this->pattern) + $this->exportValue($this->pattern) ); } diff --git a/src/Constraints/ExporterTrait.php b/src/Constraints/ExporterTrait.php new file mode 100644 index 0000000..d50dc3a --- /dev/null +++ b/src/Constraints/ExporterTrait.php @@ -0,0 +1,29 @@ +exporter()->export($value); + } + + return var_export($value, true); + } +} diff --git a/src/Constraints/SelectorCount.php b/src/Constraints/SelectorCount.php index cf3e99e..7d7a443 100644 --- a/src/Constraints/SelectorCount.php +++ b/src/Constraints/SelectorCount.php @@ -11,6 +11,8 @@ */ class SelectorCount extends Constraint { + use ExporterTrait; + /** * @var int */ @@ -41,7 +43,7 @@ public function toString(): string return sprintf( 'contains %d instance(s) of selector %s', $this->count, - $this->exporter()->export($this->selector->getValue()) + $this->exportValue($this->selector->getValue()) ); }