zawiszaty / auto-dto
Autogenerate DTO from class
Installs: 45
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/zawiszaty/auto-dto
Requires (Dev)
- phpunit/phpunit: ^8.3
This package is auto-updated.
Last update: 2026-01-06 02:28:25 UTC
README
Generate DTO from class
Example
class FakeObjectDTO extends ObjectDTO { public function __construct(object $class) { parent::__construct($class,FakeClass::class); } } /// OR class FakeArrayDTO extends ArrayDTO { public function __construct(array $params) { parent::__construct($params, FakeClass::class); } }
How to Use
$dateTime = new \DateTime(); $fakeClass = new FakeClass(1, 'test', $dateTime); $fakeDTO = new FakeObjectDTO($fakeClass); $this->assertSame(1, $fakeDTO->id); $this->assertSame('test', $fakeDTO->name); $this->assertSame($dateTime, $fakeDTO->createdAt); /// OR $dateTime = new \DateTime(); $fakeDTO = new FakeArrayDTO([ 'id' => 1, 'name' => 'test', 'createdAt' => $dateTime ]); $this->assertSame(1, $fakeDTO->id); $this->assertSame('test', $fakeDTO->name); $this->assertSame($dateTime, $fakeDTO->createdAt);
And class have the same properties with base class and the same properties value