2424abstract class EcomDev_PHPUnit_AbstractConstraint
2525 extends PHPUnit_Framework_Constraint
2626{
27+ /**
28+ * Comparator factory
29+ *
30+ * @var \SebastianBergmann\Comparator\Factory
31+ */
32+ static protected $ _comparatorFactory ;
33+
34+ /**
35+ * String exporter for variables
36+ *
37+ * @var \SebastianBergmann\Exporter\Exporter
38+ */
39+ static protected $ _exporter ;
40+
2741 /**
2842 * List of validation rules for expected value
2943 * It is an associative array with key as type and value
@@ -76,7 +90,7 @@ abstract class EcomDev_PHPUnit_AbstractConstraint
7690 /**
7791 * Comparison failure for nice failure messages
7892 *
79- * @var PHPUnit_Framework_ComparisonFailure
93+ * @var \SebastianBergmann\Comparator\ComparisonFailure
8094 */
8195 protected $ _comparisonFailure = null ;
8296
@@ -128,6 +142,35 @@ public function __construct($type, $expectedValue = null)
128142 $ this ->_expectedValue = $ expectedValue ;
129143 }
130144
145+ /**
146+ * Comparator factory instance
147+ *
148+ * @return \SebastianBergmann\Comparator\Factory
149+ */
150+ public static function getComparatorFactory ()
151+ {
152+ if (self ::$ _comparatorFactory === null ) {
153+ self ::$ _comparatorFactory = new \SebastianBergmann \Comparator \Factory ();
154+ }
155+
156+ return self ::$ _comparatorFactory ;
157+ }
158+
159+ /**
160+ * Exporter instance for variables
161+ *
162+ * @return \SebastianBergmann\Exporter\Exporter
163+ */
164+ public static function getExporter ()
165+ {
166+ if (self ::$ _exporter === null ) {
167+ self ::$ _exporter = new \SebastianBergmann \Exporter \Exporter ();
168+ }
169+
170+ return self ::$ _exporter ;
171+ }
172+
173+
131174 /**
132175 * Set actual value that will be used in the fail message
133176 *
@@ -190,7 +233,7 @@ public function evaluate($other, $description = '', $returnResult = false)
190233 * (non-PHPdoc)
191234 * @see PHPUnit_Framework_Constraint::fail()
192235 */
193- public function fail ($ other , $ description , PHPUnit_Framework_ComparisonFailure $ comparisonFailure = NULL )
236+ public function fail ($ other , $ description , \ SebastianBergmann \ Comparator \ ComparisonFailure $ comparisonFailure = NULL )
194237 {
195238 $ failureDescription = sprintf ('Failed asserting that %s ' , $ this ->failureDescription ($ other ));
196239
@@ -269,12 +312,12 @@ public function exportAsString($value)
269312 if (is_array ($ value ) && preg_match ('/^\d+$/ ' , implode ('' , array_keys ($ value )))) {
270313 $ stringValue = '' ;
271314 foreach ($ value as $ val ) {
272- $ stringValue .= (is_string ($ val ) ? $ val : PHPUnit_Util_Type:: export ($ val )) . "\n" ;
315+ $ stringValue .= (is_string ($ val ) ? $ val : self :: getExporter ()-> export ($ val )) . "\n" ;
273316 }
274317
275318 return $ stringValue ;
276319 } else {
277- return PHPUnit_Util_Type:: export ($ value );
320+ return self :: getExporter ()-> export ($ value );
278321 }
279322 }
280323
@@ -287,7 +330,7 @@ public function exportAsString($value)
287330 */
288331 public function compareValues ($ expectedValue , $ actualValue )
289332 {
290- $ comparatorFactory = PHPUnit_Framework_ComparatorFactory:: getDefaultInstance ();
333+ $ comparatorFactory = self :: getComparatorFactory ();
291334
292335 try {
293336 $ comparator = $ comparatorFactory ->getComparatorFor (
@@ -300,7 +343,7 @@ public function compareValues($expectedValue, $actualValue)
300343 );
301344 }
302345
303- catch (PHPUnit_Framework_ComparisonFailure $ f ) {
346+ catch (\ SebastianBergmann \ Comparator \ ComparisonFailure $ f ) {
304347 $ this ->_comparisonFailure = $ f ;
305348 return false ;
306349 }
@@ -316,7 +359,7 @@ public function compareValues($expectedValue, $actualValue)
316359 * @param mixed $expectedValue
317360 * @param mixed $actualValue
318361 *
319- * @return PHPUnit_Framework_ComparisonFailure
362+ * @return \SebastianBergmann\Comparator\ComparisonFailure
320363 */
321364 public function getComparisonFailure ($ expectedValue , $ actualValue )
322365 {
@@ -326,7 +369,7 @@ public function getComparisonFailure($expectedValue, $actualValue)
326369 return $ failure ;
327370 }
328371
329- return new PHPUnit_Framework_ComparisonFailure (
372+ return new \ SebastianBergmann \ Comparator \ ComparisonFailure (
330373 $ expectedValue ,
331374 $ actualValue ,
332375 $ this ->exportAsString ($ expectedValue ),
0 commit comments