diff --git a/src/Expectation.php b/src/Expectation.php index 71c4a82f..0770e367 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -16,9 +16,11 @@ final class Expectation /** * The expectation value. * + * @readonly + * * @var mixed */ - private $value; + public $value; /** * Creates a new expectation. diff --git a/src/OppositeExpectation.php b/src/OppositeExpectation.php index 4ab4449d..143d35c9 100644 --- a/src/OppositeExpectation.php +++ b/src/OppositeExpectation.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Pest; use PHPUnit\Framework\ExpectationFailedException; +use SebastianBergmann\Exporter\Exporter; /** * @internal @@ -40,7 +41,8 @@ final class OppositeExpectation return $this->original; } - throw new ExpectationFailedException(sprintf('@todo')); + // @phpstan-ignore-next-line + $this->throwExpectationFailedExpection($name, $arguments); } /** @@ -55,6 +57,24 @@ final class OppositeExpectation return $this->original; } - throw new ExpectationFailedException(sprintf('@todo')); + // @phpstan-ignore-next-line + $this->throwExpectationFailedExpection($name); + } + + /** + * Creates a new expectation failed exception + * with a nice readable message. + * + * @param array $arguments + */ + private function throwExpectationFailedExpection(string $name, array $arguments = []): void + { + $exporter = new Exporter(); + + $toString = function ($argument) use ($exporter): string { + return $exporter->shortenedExport($argument); + }; + + throw new ExpectationFailedException(sprintf('Expecting %s not %s %s.', $toString($this->original->value), strtolower((string) preg_replace('/(?