zawiszaty / auto-dto
There is no license information available for the latest version (v3.0.0) of this package.
Autogenerate DTO from class
v3.0.0
2019-08-05 11:31 UTC
Requires (Dev)
- phpunit/phpunit: ^8.3
This package is auto-updated.
Last update: 2024-09-05 23:43:03 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