Skip to content

Commit

Permalink
Create a failing test for issue doctrine#5989
Browse files Browse the repository at this point in the history
Field with type=array in a joined inheritance gets overridden by empty array in the hydrator
  • Loading branch information
cvuorinen committed Sep 2, 2016
1 parent 31a0c02 commit 611b735
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/Doctrine/Tests/Models/Issue5989/Issue5989Employee.php
@@ -0,0 +1,27 @@
<?php

namespace Doctrine\Tests\Models\Issue5989;

/**
* @Entity
* @Table(name="issue5989_employees")
*/
class Issue5989Employee extends Issue5989Person
{
/**
* @column(type="array", nullable=true)
*
* @var array
*/
private $tags = [];

public function getTags()
{
return $this->tags;
}

public function setTags(array $tags)
{
$this->tags = $tags;
}
}
27 changes: 27 additions & 0 deletions tests/Doctrine/Tests/Models/Issue5989/Issue5989Manager.php
@@ -0,0 +1,27 @@
<?php

namespace Doctrine\Tests\Models\Issue5989;

/**
* @Entity
* @Table(name="issue5989_managers")
*/
class Issue5989Manager extends Issue5989Employee
{
/**
* @column(type="array", nullable=true)
*
* @var array
*/
private $tags = [];

public function getTags()
{
return $this->tags;
}

public function setTags(array $tags)
{
$this->tags = $tags;
}
}
29 changes: 29 additions & 0 deletions tests/Doctrine/Tests/Models/Issue5989/Issue5989Person.php
@@ -0,0 +1,29 @@
<?php

namespace Doctrine\Tests\Models\Issue5989;

/**
* @Entity
* @Table(name="issue5989_persons")
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({
* "person" = "Issue5989Person",
* "manager" = "Issue5989Manager",
* "employee" = "Issue5989Employee"
* })
*/
class Issue5989Person
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
private $id;

public function getId()
{
return $this->id;
}
}
51 changes: 51 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/Issue5989Test.php
@@ -0,0 +1,51 @@
<?php

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Tests\Models\Issue5989\Issue5989Employee;
use Doctrine\Tests\Models\Issue5989\Issue5989Manager;
use Doctrine\Tests\Models\Issue5989\Issue5989Person;

/**
* @group issue-5989
*/
class Issue5989Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('issue5989');
parent::setUp();
}

public function testArrayTypeHydratedCorrectlyInJoinedInheritance()
{
$manager = new Issue5989Manager();

$managerTags = array('tag2', 'tag3');
$manager->setTags($managerTags);
$this->_em->persist($manager);

$employee = new Issue5989Employee();

$employeeTags = array('tag1', 'tag2');
$employee->setTags($employeeTags);
$this->_em->persist($employee);

$this->_em->flush();

$personId = $employee->getId();
$managerId = $manager->getId();

// clear entity manager so that $repository->find actually fetches them and uses the hydrator
// instead of just returning the existing managed entities
$this->_em->clear();

$repository = $this->_em->getRepository(Issue5989Person::class);

$employee = $repository->find($personId);
$manager = $repository->find($managerId);

static::assertEquals($employeeTags, $employee->getTags());
static::assertEquals($managerTags, $manager->getTags());
}
}
11 changes: 11 additions & 0 deletions tests/Doctrine/Tests/OrmFunctionalTestCase.php
Expand Up @@ -295,6 +295,11 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
'Doctrine\Tests\Models\VersionedManyToOne\Category',
'Doctrine\Tests\Models\VersionedManyToOne\Article',
),
'issue5989' => array(
'Doctrine\Tests\Models\Issue5989\Issue5989Person',
'Doctrine\Tests\Models\Issue5989\Issue5989Employee',
'Doctrine\Tests\Models\Issue5989\Issue5989Manager',
),
);

/**
Expand Down Expand Up @@ -563,6 +568,12 @@ protected function tearDown()
$conn->executeUpdate('DELETE FROM versioned_many_to_one_category');
}

if (isset($this->_usedModelSets['issue5989'])) {
$conn->executeUpdate('DELETE FROM issue5989_persons');
$conn->executeUpdate('DELETE FROM issue5989_employees');
$conn->executeUpdate('DELETE FROM issue5989_managers');
}

$this->_em->clear();
}

Expand Down

0 comments on commit 611b735

Please sign in to comment.