diff --git a/src/Assert.php b/src/Assert.php index b962e3e..f02b8c9 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -2087,6 +2087,10 @@ protected static function valueToString($value) return \get_class($value).': '.self::valueToString($value->format('c')); } + if (\function_exists('enum_exists') && \enum_exists(\get_class($value))) { + return \get_class($value).'::'.$value->name; + } + return \get_class($value); } diff --git a/tests/AssertTest.php b/tests/AssertTest.php index ef9b6be..87a1bb1 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -833,6 +833,22 @@ public function testResourceOfTypeCustomMessage(): void Assert::resource(null, 'curl', 'I want a resource of type %2$s. Got: %s'); } + + public function testEnumAssertionErrorMessage(): void + { + $enumIntroductionVersion = 80100; + + if (PHP_VERSION_ID < $enumIntroductionVersion) { + $this->markTestSkipped(sprintf('This test requires php %s or upper.', $enumIntroductionVersion)); + } + + require_once 'DummyEnum.php'; + + $this->expectException('\InvalidArgumentException'); + $this->expectExceptionMessage('Expected null. Got: Webmozart\Assert\Tests\TestEnum::CaseName'); + + Assert::null(TestEnum::CaseName, 'Expected null. Got: %s'); + } } /** diff --git a/tests/DummyEnum.php b/tests/DummyEnum.php new file mode 100644 index 0000000..b4aac28 --- /dev/null +++ b/tests/DummyEnum.php @@ -0,0 +1,9 @@ +