-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an ignore attribute to skip certain properties when necassary
- Loading branch information
1 parent
855b987
commit 1461859
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Tibisoft\AutoTransformer\Attribute; | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY)] | ||
class Ignore | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
test('Test ignore Attribute', function () { | ||
$object = new IgnoreClass(10, 'Willem Turkstra', ['test' => ['something' => 'missing']]); | ||
|
||
$transformer = new \Tibisoft\AutoTransformer\AutoTransformer(); | ||
|
||
/** @var IgnoreClassDTO $dto */ | ||
$dto = $transformer->transform($object, IgnoreClassDTO::class); | ||
|
||
expect($dto->age)->toBe($object->age); | ||
expect($dto->name)->toBe($object->name); | ||
|
||
$refProp = new ReflectionProperty($dto, 'complexArray'); | ||
expect($refProp->isInitialized($dto))->toBe(false); | ||
|
||
}); | ||
|
||
class IgnoreClass | ||
{ | ||
public function __construct( | ||
public int $age, | ||
public string $name, | ||
public array $complexArray, | ||
) | ||
{ | ||
|
||
} | ||
} | ||
|
||
class IgnoreClassDTO | ||
{ | ||
public function __construct( | ||
public int $age, | ||
public string $name, | ||
#[\Tibisoft\AutoTransformer\Attribute\Ignore] | ||
public array $complexArray, | ||
) | ||
{ | ||
|
||
} | ||
} |