diff --git a/src/Helpers/DataIncludedHelper.php b/src/Helpers/DataIncludedHelper.php index 200f344..750170c 100644 --- a/src/Helpers/DataIncludedHelper.php +++ b/src/Helpers/DataIncludedHelper.php @@ -12,6 +12,7 @@ namespace NilPortugues\Api\JsonApi\Helpers; use NilPortugues\Api\JsonApi\JsonApiTransformer; +use NilPortugues\Api\Transformer\Helpers\RecursiveFormatterHelper; use NilPortugues\Serializer\Serializer; class DataIncludedHelper @@ -93,7 +94,8 @@ protected static function addToRelationshipsArray( ) { foreach ($value as $propertyName => $attribute) { if (PropertyHelper::isAttributeProperty($mappings, $propertyName, $type)) { - $propertyName = DataAttributesHelper::transformToValidMemberName($propertyName); + + $propertyName = DataAttributesHelper::transformToValidMemberName(RecursiveFormatterHelper::camelCaseToUnderscore($propertyName)); if (\array_key_exists(Serializer::MAP_TYPE, $attribute) && count(array_values($attribute[Serializer::SCALAR_VALUE])) > 0 && \array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, array_values($attribute[Serializer::SCALAR_VALUE])[0])) { @@ -223,7 +225,7 @@ protected static function addRelationshipsToIncludedResources( ) { foreach ($value as $propertyName => $attribute) { if (PropertyHelper::isAttributeProperty($mappings, $propertyName, $type)) { - $propertyName = DataAttributesHelper::transformToValidMemberName($propertyName); + $propertyName = DataAttributesHelper::transformToValidMemberName(RecursiveFormatterHelper::camelCaseToUnderscore($propertyName)); if (\is_array($attribute) && \array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $attribute)) { $data[$propertyName][JsonApiTransformer::DATA_KEY] = PropertyHelper::setResponseDataTypeAndId( diff --git a/tests/Behaviour/JsonApiTransformerTest.php b/tests/Behaviour/JsonApiTransformerTest.php index 7bc0cb8..46ac30d 100644 --- a/tests/Behaviour/JsonApiTransformerTest.php +++ b/tests/Behaviour/JsonApiTransformerTest.php @@ -198,7 +198,7 @@ public function testItWillSerializeToJsonApiAComplexObject() "accepted_at":"2015-07-19T00:00:00+00:00" }, "comment":"Have no fear, sers, your king is safe.", - "oneDate" : { + "one_date" : { "date" : "2015-07-18 12:13:00.000000", "timezone_type": 1, "timezone" : "+00:00" diff --git a/tests/Integrations/Doctrine/AbstractTestCase.php b/tests/Integrations/Doctrine/AbstractTestCase.php index dd4c578..7b46232 100644 --- a/tests/Integrations/Doctrine/AbstractTestCase.php +++ b/tests/Integrations/Doctrine/AbstractTestCase.php @@ -33,7 +33,7 @@ public static function setUpBeforeClass() $newCustomer = new Customer(); $newCustomer->setActive(true); - $newCustomer->setName('Name 1'); + $newCustomer->setPersonName('Name 1'); self::$entityManager->persist($newCustomer); $newPost = new Post(); diff --git a/tests/Integrations/Doctrine/DoctrineTest.php b/tests/Integrations/Doctrine/DoctrineTest.php index d8f1554..35f2edd 100644 --- a/tests/Integrations/Doctrine/DoctrineTest.php +++ b/tests/Integrations/Doctrine/DoctrineTest.php @@ -24,7 +24,7 @@ public function testSerializeSimpleEntity() "attributes":{ "active":true, "id":1, - "name":"Name 1" + "person_name":"Name 1" }, "links":{ "self":{ @@ -85,7 +85,7 @@ public function testSerializeComplexEntity() "type":"customer", "id":"1", "attributes":{ - "name":"Name 1", + "person_name":"Name 1", "active":true }, "links":{ @@ -178,7 +178,7 @@ public function testSecondLevelNestingEntitySerialize() "type":"customer", "id":"1", "attributes":{ - "name":"Name 1", + "person_name":"Name 1", "active":true }, "links":{ @@ -218,7 +218,7 @@ public function testSecondLevelNestingEntitySerialize() "attributes":{ "comment":"Comment 1", "parent_id":null, - "parentComment":null + "parent_comment":null }, "relationships":{ "post":{ diff --git a/tests/Integrations/Doctrine/Entity/Customer.php b/tests/Integrations/Doctrine/Entity/Customer.php index 953abd1..5930893 100644 --- a/tests/Integrations/Doctrine/Entity/Customer.php +++ b/tests/Integrations/Doctrine/Entity/Customer.php @@ -15,7 +15,7 @@ class Customer /** * @var string */ - private $name; + private $personName; /** * @var bool @@ -35,13 +35,13 @@ public function getId() /** * Set name. * - * @param string $name + * @param string $personName * * @return Customer */ - public function setName($name) + public function setPersonName($personName) { - $this->name = $name; + $this->personName = $personName; return $this; } @@ -51,9 +51,9 @@ public function setName($name) * * @return string */ - public function getName() + public function getPersonName() { - return $this->name; + return $this->personName; } /** diff --git a/tests/Integrations/Doctrine/yml/Customer.orm.yml b/tests/Integrations/Doctrine/yml/Customer.orm.yml index 6d7a0a0..fdbe8a9 100644 --- a/tests/Integrations/Doctrine/yml/Customer.orm.yml +++ b/tests/Integrations/Doctrine/yml/Customer.orm.yml @@ -9,7 +9,7 @@ NilPortugues\Tests\Api\JsonApi\Integrations\Doctrine\Entity\Customer: generator: strategy: AUTO fields: - name: + personName: type: string length: 255 active: