MDL-67673 phpunit: phpunit_constraint_object_is_equal_with_exceptions
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Sun, 2 Aug 2020 08:50:59 +0000 (10:50 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 21 Oct 2020 10:45:59 +0000 (12:45 +0200)
Constraints are now declared final, so we cannot extend them anymore.

Hence, instead of extending PHPUnit\Framework\Constraint\IsEqual we
are just wrapping it into our constraint.

lib/phpunit/classes/constraint_object_is_equal_with_exceptions.php

index 5fa1d25..b468575 100644 (file)
@@ -32,7 +32,7 @@
  * @copyright  2015 Andrew Nicols <andrew@nicols.co.uk>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
  * @copyright  2015 Andrew Nicols <andrew@nicols.co.uk>
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class phpunit_constraint_object_is_equal_with_exceptions extends PHPUnit\Framework\Constraint\IsEqual {
+class phpunit_constraint_object_is_equal_with_exceptions extends PHPUnit\Framework\Constraint\Constraint {
 
     /**
      * @var array $keys The list of exceptions.
 
     /**
      * @var array $keys The list of exceptions.
@@ -44,12 +44,17 @@ class phpunit_constraint_object_is_equal_with_exceptions extends PHPUnit\Framewo
      */
     protected $capturedvalue;
 
      */
     protected $capturedvalue;
 
+    /**
+     * @var \PHPUnit\Framework\Constraint\IsEqual $isequal original constraint to be used internally.
+     */
+    protected $isequal;
+
     /**
      * Override constructor to capture value
      */
     public function __construct($value, float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false,
                                 bool $ignoreCase = false) {
     /**
      * Override constructor to capture value
      */
     public function __construct($value, float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false,
                                 bool $ignoreCase = false) {
-        parent::__construct($value, $delta, $maxDepth, $canonicalize, $ignoreCase);
+        $this->isequal = new \PHPUnit\Framework\Constraint\IsEqual($value, $delta, $maxDepth, $canonicalize, $ignoreCase);
         $this->capturedvalue = $value;
     }
 
         $this->capturedvalue = $value;
     }
 
@@ -93,8 +98,13 @@ class phpunit_constraint_object_is_equal_with_exceptions extends PHPUnit\Framewo
             }
         }
 
             }
         }
 
-        // Run the parent evaluation (isEqual).
-        return parent::evaluate($other, $description, $shouldreturnesult);
+        // Run the IsEqual evaluation.
+        return $this->isequal->evaluate($other, $description, $shouldreturnesult);
+    }
+
+    // \PHPUnit\Framework\Constraint\IsEqual wrapping.
+    public function toString(): string {
+        return $this->isequal->toString();
     }
 
 }
     }
 
 }