mirror of
https://github.com/pestphp/pest.git
synced 2026-04-21 06:27:28 +02:00
When using not() expectations with custom error messages, the message was truncated because throwExpectationFailedException() passed all arguments through shortenedExport() which limits strings to ~40 chars. Uses the full export() method for arguments instead of shortenedExport() so custom error messages are displayed in their entirety. Fixes #1533
31 lines
1.5 KiB
PHP
31 lines
1.5 KiB
PHP
<?php
|
|
|
|
use Pest\Expectations\OppositeExpectation;
|
|
use PHPUnit\Framework\ExpectationFailedException;
|
|
|
|
it('throw expectation failed exception with string argument', function (): void {
|
|
$expectation = new OppositeExpectation(expect('foo'));
|
|
|
|
$expectation->throwExpectationFailedException('toBe', 'bar');
|
|
})->throws(ExpectationFailedException::class, "Expecting 'foo' not to be 'bar'.");
|
|
|
|
it('throw expectation failed exception with array argument', function (): void {
|
|
$expectation = new OppositeExpectation(expect('foo'));
|
|
|
|
$expectation->throwExpectationFailedException('toBe', ['bar']);
|
|
})->throws(ExpectationFailedException::class, "Expecting 'foo' not to be 'bar'.");
|
|
|
|
it('does not truncate long string arguments in error message', function (): void {
|
|
$expectation = new OppositeExpectation(expect('foo'));
|
|
|
|
$longMessage = 'Very long error message. Very long error message. Very long error message.';
|
|
|
|
$expectation->throwExpectationFailedException('toBe', [$longMessage]);
|
|
})->throws(ExpectationFailedException::class, 'Very long error message. Very long error message. Very long error message.');
|
|
|
|
it('does not truncate custom error message when using not()', function (): void {
|
|
$longMessage = 'This is a very detailed custom error message that should not be truncated in the output.';
|
|
|
|
expect(true)->not()->toBeTrue($longMessage);
|
|
})->throws(ExpectationFailedException::class, 'This is a very detailed custom error message that should not be truncated in the output.');
|