Open
Description
Q | A |
---|---|
PHPUnit version | 9.5.18 |
PHP version | 8.1.2 |
Installation Method | PHAR |
Summary
When assertEqualsCanonicalizing()
is utilized the assertion result display will crash when one of the array elements, which is presented in the diff, is not castable to string.
Current behavior
When test is run the testing framework crashes with, at-first confusing, error message:
1) FooTest::testFoo
Object of class stdClass could not be converted to int
How to reproduce
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class FooTest extends TestCase
{
public function testFoo(): void
{
$data = [
'one' => 123,
'two' => new \stdClass(),
];
$copy = $data;
$copy['one'] = 1234;
$this->assertEqualsCanonicalizing($data, $copy);
}
}
Expected behavior
The diff should handle such cases properly and display e.g. object ID, similarly to how e.g. assertSame()
does it:
1) FooTest::testFoo
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
Array &0 (
- 'one' => 123
+ 'one' => 1234
'two' => stdClass Object &000000000000000d0000000000000000 ()
)
Activity