diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2024-05-27 13:08:29 +0200 |
commit | 75160b12821f7f4299cce7f0b69c83c1502ae071 (patch) | |
tree | 27e25e4ccaef45f0c58b22831164050d1af1d4db /vendor/myclabs/php-enum/src/PHPUnit/Comparator.php | |
parent | prvi-commit (diff) | |
download | 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.gz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.bz2 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.lz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.xz 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.tar.zst 1ka-75160b12821f7f4299cce7f0b69c83c1502ae071.zip |
Diffstat (limited to '')
-rw-r--r-- | vendor/myclabs/php-enum/src/PHPUnit/Comparator.php | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/myclabs/php-enum/src/PHPUnit/Comparator.php b/vendor/myclabs/php-enum/src/PHPUnit/Comparator.php new file mode 100644 index 0000000..b52fce3 --- /dev/null +++ b/vendor/myclabs/php-enum/src/PHPUnit/Comparator.php @@ -0,0 +1,54 @@ +<?php
+
+namespace MyCLabs\Enum\PHPUnit;
+
+use MyCLabs\Enum\Enum;
+use SebastianBergmann\Comparator\ComparisonFailure;
+
+/**
+ * Use this Comparator to get nice output when using PHPUnit assertEquals() with Enums.
+ *
+ * Add this to your PHPUnit bootstrap PHP file:
+ *
+ * \SebastianBergmann\Comparator\Factory::getInstance()->register(new \MyCLabs\Enum\PHPUnit\Comparator());
+ */
+final class Comparator extends \SebastianBergmann\Comparator\Comparator
+{
+ public function accepts($expected, $actual)
+ {
+ return $expected instanceof Enum && (
+ $actual instanceof Enum || $actual === null
+ );
+ }
+
+ /**
+ * @param Enum $expected
+ * @param Enum|null $actual
+ *
+ * @return void
+ */
+ public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false)
+ {
+ if ($expected->equals($actual)) {
+ return;
+ }
+
+ throw new ComparisonFailure(
+ $expected,
+ $actual,
+ $this->formatEnum($expected),
+ $this->formatEnum($actual),
+ false,
+ 'Failed asserting that two Enums are equal.'
+ );
+ }
+
+ private function formatEnum(Enum $enum = null)
+ {
+ if ($enum === null) {
+ return "null";
+ }
+
+ return get_class($enum)."::{$enum->getKey()}()";
+ }
+}
|