-
-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test serializing entity that uses Discriminator and extends some base…
… model class #878
- Loading branch information
kevin
committed
Mar 20, 2020
1 parent
25a829b
commit 2f5073b
Showing
8 changed files
with
162 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace JMS\Serializer\Tests\Fixtures\Discriminator\Serialization; | ||
|
||
use JMS\Serializer\Annotation as JMS; | ||
use ReflectionClass; | ||
use ReflectionException; | ||
|
||
abstract class Entity | ||
{ | ||
/** | ||
* @JMS\Type("int") | ||
* @JMS\Groups({"base"}) | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* Entity constructor. | ||
* @param int $id | ||
*/ | ||
public function __construct($id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* @JMS\VirtualProperty() | ||
* @JMS\SerializedName("entityName") | ||
* @JMS\Groups({"entity.identification"}) | ||
* @throws ReflectionException | ||
*/ | ||
public function getEntityName(): string { | ||
$reflect = new ReflectionClass($this); | ||
return $reflect->getShortName(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/Fixtures/Discriminator/Serialization/ExtendedUser.php
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,28 @@ | ||
<?php | ||
namespace JMS\Serializer\Tests\Fixtures\Discriminator\Serialization; | ||
|
||
use JMS\Serializer\Annotation as JMS; | ||
|
||
class ExtendedUser extends User | ||
{ | ||
/** | ||
* @JMS\Type("string") | ||
* @JMS\Groups({"base"}) | ||
* @var string | ||
*/ | ||
public $extendAttribute; | ||
|
||
/** | ||
* ExtendedUser constructor. | ||
* | ||
* @param int $id | ||
* @param string $name | ||
* @param string $description | ||
* @param string $extendAttribute | ||
*/ | ||
public function __construct($id, $name, $description, $extendAttribute) | ||
{ | ||
parent::__construct($id, $name, $description); | ||
$this->extendAttribute = $extendAttribute; | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
|
||
namespace JMS\Serializer\Tests\Fixtures\Discriminator\Serialization; | ||
|
||
use JMS\Serializer\Annotation as JMS; | ||
|
||
/** | ||
* Class User | ||
* | ||
* @package JMS\Serializer\Tests\Fixtures\Discriminator\Serialization | ||
* @JMS\Discriminator(field = "entityName", | ||
* groups={"entity.identification"}, | ||
* map = { | ||
* "User": "JMS\Serializer\Tests\Fixtures\Discriminator\Serialization\User", | ||
* "ExtendedUser": "JMS\Serializer\Tests\Fixtures\Discriminator\Serialization\ExtendedUser" | ||
* }) | ||
*/ | ||
class User extends Entity | ||
{ | ||
/** | ||
* @JMS\Type("string") | ||
* @JMS\Groups({"base"}) | ||
* @var string | ||
*/ | ||
public $name; | ||
/** | ||
* @JMS\Type("string") | ||
* @JMS\Groups({"base"}) | ||
* @var string | ||
*/ | ||
public $description; | ||
|
||
/** | ||
* User constructor. | ||
* | ||
* @param $id | ||
* @param string $name | ||
* @param string $description | ||
*/ | ||
public function __construct($id, $name, $description) | ||
{ | ||
parent::__construct($id); | ||
$this->name = $name; | ||
$this->description = $description; | ||
} | ||
|
||
|
||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<result> | ||
<entry><![CDATA[User]]></entry> | ||
</result> |
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<result> | ||
<entry> | ||
<entry><![CDATA[User]]></entry> | ||
</entry> | ||
<entry> | ||
<entry><![CDATA[ExtendedUser]]></entry> | ||
</entry> | ||
</result> |
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,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<result> | ||
<entry><![CDATA[ExtendedUser]]></entry> | ||
</result> |