Skip to content

Commit

Permalink
git push origin masterMerge branch 'basz-incorrect-included-property-…
Browse files Browse the repository at this point in the history
…names'
  • Loading branch information
Nil Portugués Calderó committed Apr 4, 2017
2 parents de1b42d + 609f792 commit eb88413
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/Helpers/DataIncludedHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])) {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/Behaviour/JsonApiTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/Integrations/Doctrine/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions tests/Integrations/Doctrine/DoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testSerializeSimpleEntity()
"attributes":{
"active":true,
"id":1,
"name":"Name 1"
"person_name":"Name 1"
},
"links":{
"self":{
Expand Down Expand Up @@ -85,7 +85,7 @@ public function testSerializeComplexEntity()
"type":"customer",
"id":"1",
"attributes":{
"name":"Name 1",
"person_name":"Name 1",
"active":true
},
"links":{
Expand Down Expand Up @@ -178,7 +178,7 @@ public function testSecondLevelNestingEntitySerialize()
"type":"customer",
"id":"1",
"attributes":{
"name":"Name 1",
"person_name":"Name 1",
"active":true
},
"links":{
Expand Down Expand Up @@ -218,7 +218,7 @@ public function testSecondLevelNestingEntitySerialize()
"attributes":{
"comment":"Comment 1",
"parent_id":null,
"parentComment":null
"parent_comment":null
},
"relationships":{
"post":{
Expand Down
12 changes: 6 additions & 6 deletions tests/Integrations/Doctrine/Entity/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Customer
/**
* @var string
*/
private $name;
private $personName;

/**
* @var bool
Expand All @@ -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;
}
Expand All @@ -51,9 +51,9 @@ public function setName($name)
*
* @return string
*/
public function getName()
public function getPersonName()
{
return $this->name;
return $this->personName;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Integrations/Doctrine/yml/Customer.orm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ NilPortugues\Tests\Api\JsonApi\Integrations\Doctrine\Entity\Customer:
generator:
strategy: AUTO
fields:
name:
personName:
type: string
length: 255
active:
Expand Down

0 comments on commit eb88413

Please sign in to comment.