Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[failing test] inheritance same property name #935

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions tests/Fixtures/Inheritance/ChildClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

/*
* Copyright 2016 Johannes M. Schmitt <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace JMS\Serializer\Tests\Fixtures\Inheritance;

use JMS\Serializer\Annotation as Serializer;

class ChildClass extends ParentClass
{
/** @Serializer\SerializedName("bar") */
private $a = 'c';

public function __construct($a1, $a2)
{
$this->a = $a1;
parent::__construct($a2);
}
}
34 changes: 34 additions & 0 deletions tests/Fixtures/Inheritance/ParentClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/*
* Copyright 2016 Johannes M. Schmitt <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace JMS\Serializer\Tests\Fixtures\Inheritance;

use JMS\Serializer\Annotation as Serializer;

class ParentClass
{
/** @Serializer\SerializedName("foo") */
private $a;

public function __construct($a)
{
$this->a = $a;
}
}
19 changes: 19 additions & 0 deletions tests/Serializer/BaseSerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
use JMS\Serializer\Tests\Fixtures\GroupsObject;
use JMS\Serializer\Tests\Fixtures\GroupsUser;
use JMS\Serializer\Tests\Fixtures\IndexedCommentsBlogPost;
use JMS\Serializer\Tests\Fixtures\Inheritance\ChildClass;
use JMS\Serializer\Tests\Fixtures\InitializedBlogPostConstructor;
use JMS\Serializer\Tests\Fixtures\InitializedObjectConstructor;
use JMS\Serializer\Tests\Fixtures\InlineChild;
Expand Down Expand Up @@ -136,6 +137,24 @@ abstract class BaseSerializationTest extends \PHPUnit\Framework\TestCase
protected $objectConstructor;
protected $accessorStrategy;

public function testInheritanceSameProprietyName()/* The :void return type declaration that should be here would cause a BC issue */
{
$object = new ChildClass('b', 'c');

self::assertEquals(
$this->getContent('inheritance_same_prop_name'),
$this->serialize($object)
);

if ($this->hasDeserializer()) {
self::assertEquals(
$object,
$this->deserialize($this->getContent('inheritance_same_prop_name'))
);
}
}


public function testSerializeNullArray()
{
$arr = ['foo' => 'bar', 'baz' => null, null];
Expand Down
1 change: 1 addition & 0 deletions tests/Serializer/JsonSerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ protected function getContent($key)
$outputs['maxdepth_skippabe_object'] = '{"a":{"xxx":"yyy"}}';
$outputs['array_objects_nullable'] = '[]';
$outputs['type_casting'] = '{"as_string":"8"}';
$outputs['inheritance_same_prop_name'] = '{"foo":"b", "bar":"c"}';
}

if (!isset($outputs[$key])) {
Expand Down
5 changes: 5 additions & 0 deletions tests/Serializer/xml/inheritance_same_prop_name.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<result>
<foo><![CDATA[b]]></foo>
<bar><![CDATA[c]]></bar>
</result>