mirror of
https://github.com/pestphp/pest.git
synced 2026-04-20 22:20:17 +02:00
Compare commits
2 Commits
8dd650fd05
...
e63a886f98
| Author | SHA1 | Date | |
|---|---|---|---|
| e63a886f98 | |||
| e601e6df31 |
@ -798,13 +798,11 @@ final readonly class OppositeExpectation
|
|||||||
|
|
||||||
$exporter = Exporter::default();
|
$exporter = Exporter::default();
|
||||||
|
|
||||||
$toString = fn (mixed $argument): string => $exporter->shortenedExport($argument);
|
|
||||||
|
|
||||||
throw new ExpectationFailedException(sprintf(
|
throw new ExpectationFailedException(sprintf(
|
||||||
'Expecting %s not %s %s.',
|
'Expecting %s not %s %s.',
|
||||||
$toString($this->original->value),
|
$exporter->shortenedExport($this->original->value),
|
||||||
strtolower((string) preg_replace('/(?<!\ )[A-Z]/', ' $0', $name)),
|
strtolower((string) preg_replace('/(?<!\ )[A-Z]/', ' $0', $name)),
|
||||||
implode(' ', array_map(fn (mixed $argument): string => $toString($argument), $arguments)),
|
implode(' ', array_map(fn (mixed $argument): string => $exporter->export($argument), $arguments)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -86,4 +86,17 @@ final readonly class Exporter
|
|||||||
|
|
||||||
return (string) preg_replace(array_keys($map), array_values($map), $this->exporter->shortenedExport($value));
|
return (string) preg_replace(array_keys($map), array_values($map), $this->exporter->shortenedExport($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exports a value into a full single-line string without truncation.
|
||||||
|
*/
|
||||||
|
public function export(mixed $value): string
|
||||||
|
{
|
||||||
|
$map = [
|
||||||
|
'#\\\n\s*#' => '',
|
||||||
|
'# Object \(\.{3}\)#' => '',
|
||||||
|
];
|
||||||
|
|
||||||
|
return (string) preg_replace(array_keys($map), array_values($map), $this->exporter->export($value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,3 +14,17 @@ it('throw expectation failed exception with array argument', function (): void {
|
|||||||
|
|
||||||
$expectation->throwExpectationFailedException('toBe', ['bar']);
|
$expectation->throwExpectationFailedException('toBe', ['bar']);
|
||||||
})->throws(ExpectationFailedException::class, "Expecting 'foo' not to be '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.');
|
||||||
|
|||||||
Reference in New Issue
Block a user