-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix supporting for
?array
type in DTOs without attributes (#245)
- Loading branch information
Showing
13 changed files
with
153 additions
and
59 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
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
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 was deleted.
Oops, something went wrong.
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,32 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of Temporal package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Tests\Unit\DTO\Type\ArrayType; | ||
|
||
use Temporal\Internal\Marshaller\Meta\MarshalArray; | ||
|
||
class ArrayDTO | ||
{ | ||
#[MarshalArray(name: 'foo')] | ||
public array $foo; | ||
|
||
#[MarshalArray(name: 'bar')] | ||
public ?array $bar; | ||
|
||
#[MarshalArray(name: 'baz')] | ||
public ?array $baz; | ||
|
||
public array $autoArray; | ||
|
||
public ?array $nullableFoo; | ||
|
||
public ?array $nullableBar; | ||
} |
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,57 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of Temporal package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Tests\Unit\DTO\Type\ArrayType; | ||
|
||
use Temporal\Tests\Unit\DTO\DTOMarshallingTestCase; | ||
|
||
class ArrayTestCase extends DTOMarshallingTestCase | ||
{ | ||
public function testMarshalling(): void | ||
{ | ||
$dto = new ArrayDTO(); | ||
$dto->foo = ['foo']; | ||
$dto->bar = ['bar']; | ||
$dto->baz = null; | ||
$dto->autoArray = ['foo']; | ||
$dto->nullableFoo = ['bar']; | ||
$dto->nullableBar = null; | ||
|
||
$result = $this->marshal($dto); | ||
$this->assertSame([ | ||
'foo' => ['foo'], | ||
'bar' => ['bar'], | ||
'baz' => null, | ||
'autoArray' => ['foo'], | ||
'nullableFoo' => ['bar'], | ||
'nullableBar' => null, | ||
], $result); | ||
} | ||
|
||
public function testUnmarshalling(): void | ||
{ | ||
$dto = $this->unmarshal([ | ||
'foo' => ['foo'], | ||
'bar' => ['bar'], | ||
'baz' => null, | ||
'autoArray' => ['foo'], | ||
'nullableFoo' => ['bar'], | ||
'nullableBar' => null, | ||
], new ArrayDTO()); | ||
|
||
$this->assertSame(['foo'], $dto->foo); | ||
$this->assertSame(['bar'], $dto->bar); | ||
$this->assertSame(null, $dto->baz); | ||
$this->assertSame(['foo'], $dto->autoArray); | ||
$this->assertSame(['bar'], $dto->nullableFoo); | ||
$this->assertSame(null, $dto->nullableBar); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of Temporal package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Tests\Unit\DTO\Type\EnumType; | ||
|
||
use Temporal\Tests\Unit\DTO\DTOMarshallingTestCase; | ||
|
||
/** | ||
* @requires PHP >= 8.1 | ||
*/ | ||
class EnumTestCase extends DTOMarshallingTestCase | ||
{ | ||
public function testUnmarshalBackedEnum(): void | ||
{ | ||
$dto = $this->unmarshal([ | ||
'scalarEnum' => ScalarEnum::TESTED_ENUM->value, | ||
], new EnumDTO()); | ||
|
||
$this->assertSame(ScalarEnum::TESTED_ENUM, $dto->scalarEnum); | ||
} | ||
|
||
public function testUnmarshalNonBackedEnum(): void | ||
{ | ||
$this->expectError(); | ||
|
||
$this->unmarshal([ | ||
'simpleEnum' => SimpleEnum::TEST->name, | ||
], new EnumDTO()); | ||
} | ||
} |
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