Skip to content

Commit

Permalink
Add test for __debugInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
compositephp committed Nov 5, 2023
1 parent 9d35a0c commit ea3c3ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/AbstractEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ public function __debugInfo(): array
{
$result = [];
foreach ((new \ReflectionClass($this))->getProperties() as $property) {
if ($property->name === '_initialColumns') {
continue;
}
if (!$property->isInitialized($this)) {
continue;
}
Expand Down
24 changes: 24 additions & 0 deletions tests/AbstractEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composite\Entity\AbstractEntity;
use Composite\Entity\Helpers\DateTimeHelper;
use Composite\Entity\Tests\TestStand\TestSubEntity;

final class AbstractEntityTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -219,4 +220,27 @@ public function __construct(
$loadedEntity = $entity::fromArray($dataArray);
$this->assertEquals($dataArray, $loadedEntity->toArray());
}

public function test_debugInfo(): void
{
$entity = new class extends AbstractEntity {
public int $var1 = 1;
protected int $var2 = 2;
private int $var3 = 3;
public int $var4;
public function __construct(
public TestSubEntity $subEntity = new TestSubEntity(),
) {
}
};
$expected = print_r([
'var1' => 1,
'var2' => 2,
'var3:private' => 3,
'subEntity' => new TestSubEntity(),
], true);

$expected = str_replace('Array', 'Composite\Entity\AbstractEntity@anonymous Object', $expected);
$this->assertEquals($expected, print_r($entity, true));
}
}

0 comments on commit ea3c3ac

Please sign in to comment.