Open
Description
Q | A |
---|---|
PHPUnit version | 10.5.20 |
PHP version | 8.1.2-1ubuntu2.17 (cli) |
Installation Method | PHAR |
Summary
When I have long strings in an array that's passed to assertEquals() and the values are not equal, the emitted failure message clips away important part of the string.
How to reproduce
mkdir test && cd test
wget -O phpunit https://phar.phpunit.de/phpunit-10.phar
cat << 'EOF' > UnitTest.php
<?php
class UnitTest extends PHPUnit\Framework\TestCase
{
public function testAssertingArrays()
{
$mock_testresult = array(
0 => "Some short string",
1 => "Some really long string that just keeps going and going and going but contains important clue HERE about why this whole test failed.",
);
$this->assertEquals($mock_testresult, array(), "Expected empty array but got non-empty array.");
}
}
EOF
php phpunit UnitTest.php
Current behavior
PHPUnit 10.5.20 by Sebastian Bergmann and contributors.
Runtime: PHP 8.1.2-1ubuntu2.17
F 1 / 1 (100%)
Time: 00:00.001, Memory: 24.79 MB
There was 1 failure:
1) UnitTest::testAssertingArrays
Expected empty array but got non-empty array.
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
- 0 => 'Some short string'
- 1 => 'Some really long string that ...ailed.'
)
/home/user/test/UnitTest.php:10
FAILURES!
Tests: 1, Assertions: 1, Failures: 1
Expected behavior
Otherwise same but the array offset 1 should show enough of the string to also see the word "HERE".
Additional information
I can see the whole string if I run php phpunit --debug UnitTest.php
instead but the output is so verbose otherwise that it's hard to read. I'd rather see normal output but the whole string, but I couldn't find any documented feature to turn off this kind of string clipping/shortening.
Activity