feat: DTO에 Ignore 추가

This commit is contained in:
2022-05-28 16:12:54 +09:00
parent cb3982e57c
commit 7464629597
3 changed files with 51 additions and 0 deletions
+29
View File
@@ -3,6 +3,7 @@
use sammo\DTO\Attr\Convert;
use sammo\DTO\Attr\DefaultValue;
use sammo\DTO\Attr\DefaultValueGenerator;
use sammo\DTO\Attr\Ignore;
use sammo\DTO\DTO;
use sammo\DTO\Attr\JsonString;
use sammo\DTO\Attr\NullIsUndefined;
@@ -196,6 +197,23 @@ class TypeDefaultValue extends DTO
}
}
class TypeIgnore extends DTO
{
#[Ignore]
public int $c = 100;
#[Ignore]
public $d;
#[Ignore]
public $e;
public function __construct(
public int $a,
public int $b,
) {
$this->d = $a * 2;
}
}
class DTOTest extends PHPUnit\Framework\TestCase
{
public function testBasic()
@@ -436,4 +454,15 @@ class DTOTest extends PHPUnit\Framework\TestCase
$this->assertEquals($testValue, $testType);
}
public function testIgnore(){
$rawType = [
'a' => 1,
'b' => 2,
];
$obj = TypeIgnore::fromArray($rawType);
$testType = $obj->toArray();
$this->assertEquals($rawType, $testType);
}
}