diff --git a/PhpUnit/ConfigurationValuesAreInvalidConstraint.php b/PhpUnit/ConfigurationValuesAreInvalidConstraint.php index 14714f4..849995e 100644 --- a/PhpUnit/ConfigurationValuesAreInvalidConstraint.php +++ b/PhpUnit/ConfigurationValuesAreInvalidConstraint.php @@ -65,7 +65,7 @@ private function evaluateException(\Exception $exception, $description, $returnR } return $this->createPhpUnitConstraint() - ->evaluate($exception, $description, $returnResult); + ->evaluate($exception->getMessage(), $description, $returnResult); } private function createPhpUnitConstraint() diff --git a/Tests/PhpUnit/ConfigurationValuesAreInvalidConstraintTest.php b/Tests/PhpUnit/ConfigurationValuesAreInvalidConstraintTest.php index 9ae1237..5edce39 100644 --- a/Tests/PhpUnit/ConfigurationValuesAreInvalidConstraintTest.php +++ b/Tests/PhpUnit/ConfigurationValuesAreInvalidConstraintTest.php @@ -6,6 +6,7 @@ use Matthias\SymfonyConfigTest\Tests\PhpUnit\Fixtures\AlwaysValidConfiguration; use Matthias\SymfonyConfigTest\Tests\PhpUnit\Fixtures\ConfigurationWithRequiredValue; use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; class ConfigurationValuesAreInvalidConstraintTest extends TestCase @@ -82,6 +83,25 @@ public function if_configuration_values_are_invalid_it_matches_when_exception_me $this->assertTrue($constraint->evaluate([[]], '', true)); } + #[Test] + public function the_failure_message_contains_the_actual_exception_message() + { + $constraint = new ConfigurationValuesAreInvalidConstraint( + new ConfigurationWithRequiredValue(), + 'expected message which will not be part of the actual message' + ); + + try { + $constraint->evaluate([[]]); + } catch (ExpectationFailedException $exception) { + $this->assertStringContainsString('required_value', $exception->getMessage()); + + return; + } + + $this->fail('Expected an ExpectationFailedException to be thrown'); + } + #[Test] public function to_string_returns_a_message() {