Skip to content

Commit eb88413

Browse files
author
Nil Portugués Calderó
committed
git push origin masterMerge branch 'basz-incorrect-included-property-names'
2 parents de1b42d + 609f792 commit eb88413

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

src/Helpers/DataIncludedHelper.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace NilPortugues\Api\JsonApi\Helpers;
1313

1414
use NilPortugues\Api\JsonApi\JsonApiTransformer;
15+
use NilPortugues\Api\Transformer\Helpers\RecursiveFormatterHelper;
1516
use NilPortugues\Serializer\Serializer;
1617

1718
class DataIncludedHelper
@@ -93,7 +94,8 @@ protected static function addToRelationshipsArray(
9394
) {
9495
foreach ($value as $propertyName => $attribute) {
9596
if (PropertyHelper::isAttributeProperty($mappings, $propertyName, $type)) {
96-
$propertyName = DataAttributesHelper::transformToValidMemberName($propertyName);
97+
98+
$propertyName = DataAttributesHelper::transformToValidMemberName(RecursiveFormatterHelper::camelCaseToUnderscore($propertyName));
9799
if (\array_key_exists(Serializer::MAP_TYPE, $attribute)
98100
&& count(array_values($attribute[Serializer::SCALAR_VALUE])) > 0
99101
&& \array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, array_values($attribute[Serializer::SCALAR_VALUE])[0])) {
@@ -223,7 +225,7 @@ protected static function addRelationshipsToIncludedResources(
223225
) {
224226
foreach ($value as $propertyName => $attribute) {
225227
if (PropertyHelper::isAttributeProperty($mappings, $propertyName, $type)) {
226-
$propertyName = DataAttributesHelper::transformToValidMemberName($propertyName);
228+
$propertyName = DataAttributesHelper::transformToValidMemberName(RecursiveFormatterHelper::camelCaseToUnderscore($propertyName));
227229

228230
if (\is_array($attribute) && \array_key_exists(Serializer::CLASS_IDENTIFIER_KEY, $attribute)) {
229231
$data[$propertyName][JsonApiTransformer::DATA_KEY] = PropertyHelper::setResponseDataTypeAndId(

tests/Behaviour/JsonApiTransformerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function testItWillSerializeToJsonApiAComplexObject()
198198
"accepted_at":"2015-07-19T00:00:00+00:00"
199199
},
200200
"comment":"Have no fear, sers, your king is safe.",
201-
"oneDate" : {
201+
"one_date" : {
202202
"date" : "2015-07-18 12:13:00.000000",
203203
"timezone_type": 1,
204204
"timezone" : "+00:00"

tests/Integrations/Doctrine/AbstractTestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static function setUpBeforeClass()
3333

3434
$newCustomer = new Customer();
3535
$newCustomer->setActive(true);
36-
$newCustomer->setName('Name 1');
36+
$newCustomer->setPersonName('Name 1');
3737
self::$entityManager->persist($newCustomer);
3838

3939
$newPost = new Post();

tests/Integrations/Doctrine/DoctrineTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testSerializeSimpleEntity()
2424
"attributes":{
2525
"active":true,
2626
"id":1,
27-
"name":"Name 1"
27+
"person_name":"Name 1"
2828
},
2929
"links":{
3030
"self":{
@@ -85,7 +85,7 @@ public function testSerializeComplexEntity()
8585
"type":"customer",
8686
"id":"1",
8787
"attributes":{
88-
"name":"Name 1",
88+
"person_name":"Name 1",
8989
"active":true
9090
},
9191
"links":{
@@ -178,7 +178,7 @@ public function testSecondLevelNestingEntitySerialize()
178178
"type":"customer",
179179
"id":"1",
180180
"attributes":{
181-
"name":"Name 1",
181+
"person_name":"Name 1",
182182
"active":true
183183
},
184184
"links":{
@@ -218,7 +218,7 @@ public function testSecondLevelNestingEntitySerialize()
218218
"attributes":{
219219
"comment":"Comment 1",
220220
"parent_id":null,
221-
"parentComment":null
221+
"parent_comment":null
222222
},
223223
"relationships":{
224224
"post":{

tests/Integrations/Doctrine/Entity/Customer.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Customer
1515
/**
1616
* @var string
1717
*/
18-
private $name;
18+
private $personName;
1919

2020
/**
2121
* @var bool
@@ -35,13 +35,13 @@ public function getId()
3535
/**
3636
* Set name.
3737
*
38-
* @param string $name
38+
* @param string $personName
3939
*
4040
* @return Customer
4141
*/
42-
public function setName($name)
42+
public function setPersonName($personName)
4343
{
44-
$this->name = $name;
44+
$this->personName = $personName;
4545

4646
return $this;
4747
}
@@ -51,9 +51,9 @@ public function setName($name)
5151
*
5252
* @return string
5353
*/
54-
public function getName()
54+
public function getPersonName()
5555
{
56-
return $this->name;
56+
return $this->personName;
5757
}
5858

5959
/**

tests/Integrations/Doctrine/yml/Customer.orm.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ NilPortugues\Tests\Api\JsonApi\Integrations\Doctrine\Entity\Customer:
99
generator:
1010
strategy: AUTO
1111
fields:
12-
name:
12+
personName:
1313
type: string
1414
length: 255
1515
active:

0 commit comments

Comments
 (0)