-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(php): use strings for request enums + other small fixes (#4741)
- Loading branch information
Showing
724 changed files
with
13,986 additions
and
1,185 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace <%= namespace%>; | ||
|
||
use JsonSerializable; | ||
use PHPUnit\Framework\TestCase; | ||
use <%= coreNamespace%>\SerializableType; | ||
use <%= coreNamespace%>\JsonProperty; | ||
use <%= coreNamespace%>\ArrayType; | ||
|
||
enum Shape: string implements JsonSerializable | ||
{ | ||
case Square = "SQUARE"; | ||
case Circle = "CIRCLE"; | ||
case Triangle = "TRIANGLE"; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function jsonSerialize(): string | ||
{ | ||
return $this->value; | ||
} | ||
} | ||
|
||
class ShapeType extends SerializableType | ||
{ | ||
/** | ||
* @var Shape $shape | ||
*/ | ||
#[JsonProperty('shape')] | ||
public Shape $shape; | ||
|
||
/** | ||
* @var Shape[] $shapes | ||
*/ | ||
#[ArrayType([Shape::class])] | ||
#[JsonProperty('shapes')] | ||
public array $shapes; | ||
|
||
/** | ||
* @param Shape $shape | ||
* @param Shape[] $shapes | ||
*/ | ||
public function __construct( | ||
Shape $shape, | ||
array $shapes, | ||
) { | ||
$this->shape = $shape; | ||
$this->shapes = $shapes; | ||
} | ||
} | ||
|
||
class EnumTest extends TestCase | ||
{ | ||
public function testShapeEnumSerialization(): void | ||
{ | ||
$object = new ShapeType( | ||
Shape::Circle, | ||
[Shape::Square, Shape::Circle, Shape::Triangle] | ||
); | ||
|
||
$expectedJson = json_encode([ | ||
'shape' => 'CIRCLE', | ||
'shapes' => ['SQUARE', 'CIRCLE', 'TRIANGLE'] | ||
], JSON_THROW_ON_ERROR); | ||
|
||
$serializedJson = $object->toJson(); | ||
|
||
$this->assertJsonStringEqualsJsonString($expectedJson, $serializedJson, | ||
'Serialized JSON does not match expected JSON for shape and shapes properties.'); | ||
} | ||
} |
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
Oops, something went wrong.