Skip to content

Commit a53438b

Browse files
committed
add more tests
1 parent 64c059e commit a53438b

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tests/AbstractEntityTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Composite\Entity\Tests;
44

55
use Composite\Entity\AbstractEntity;
6+
use Composite\Entity\Attributes\ListOf;
67
use Composite\Entity\Helpers\DateTimeHelper;
8+
use Composite\Entity\Tests\TestStand\TestEntityWithHydrator;
79
use Composite\Entity\Tests\TestStand\TestSubEntity;
810
use PHPUnit\Framework\Attributes\DataProvider;
911

@@ -254,4 +256,23 @@ public function test_resetChangedColumns(): void
254256

255257
$this->assertEquals(['number' => $entity->number], $entity->getChangedColumns());
256258
}
259+
260+
261+
public function test_jsonSerialize(): void
262+
{
263+
$withHydrator = new TestEntityWithHydrator(str: 'foo', int: 123);
264+
$sub = new TestSubEntity(str: 'bar');
265+
$entity = new class($withHydrator, [$sub]) extends AbstractEntity {
266+
public readonly int $id;
267+
public ?int $nullable = null;
268+
269+
public function __construct(
270+
public TestEntityWithHydrator $column1,
271+
#[ListOf(TestSubEntity::class)]
272+
public array $column2,
273+
) {}
274+
};
275+
$encoded = json_encode($entity);
276+
$this->assertEquals('{"nullable":null,"column1":{"str":"foo","int":123},"column2":[{"str":"bar","number":123}]}', $encoded);
277+
}
257278
}

tests/ColumnBuilderTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,14 @@ public function test_notSupported(AbstractEntity $entity): void
312312
$this->assertTrue(true);
313313
}
314314
}
315+
316+
public function test_virtualProperty(): void
317+
{
318+
$class = new class extends AbstractEntity {
319+
public string $foo {get => 'foo';}
320+
public string $bar = 'bar';
321+
};
322+
$schema = $class::schema();
323+
$this->assertEmpty($schema->getColumn('foo'));
324+
}
315325
}

0 commit comments

Comments
 (0)