1
0
mirror of synced 2025-02-02 13:31:45 +03:00

DDC-3699 - #1387 - simpifying tests, clarifying on test method names

This commit is contained in:
Marco Pivetta 2015-07-15 21:46:23 +01:00
parent 69ef75ff2d
commit 86abbb0e78
5 changed files with 71 additions and 190 deletions

View File

@ -2,90 +2,20 @@
namespace Doctrine\Tests\Models\DDC3699;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity
* @Table(name="ddc3699_child")
*/
/** @Entity @Table(name="ddc3699_child") */
class DDC3699Child extends DDC3699Parent
{
const CLASSNAME = __CLASS__;
/**
* @Id
* @Column(type="integer")
*/
protected $id;
/** @Id @Column(type="integer") */
public $id;
/**
* @Column(type="string")
*/
protected $childField;
/** @Column(type="string") */
public $childField;
/**
* @OneToOne(targetEntity="DDC3699RelationOne", inversedBy="child")
*/
protected $oneRelation;
/** @OneToOne(targetEntity="DDC3699RelationOne", inversedBy="child") */
public $oneRelation;
/**
* @OneToMany(targetEntity="DDC3699RelationMany", mappedBy="child")
*/
protected $relations;
public function getId()
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
}
public function getChildField()
{
return $this->childField;
}
public function setChildField($childField)
{
$this->childField = $childField;
}
public function getOneRelation()
{
return $this->oneRelation;
}
public function setOneRelation($oneRelation)
{
$this->oneRelation = $oneRelation;
}
public function hasRelation($relation)
{
return $this->relations && $this->relations->contains($relation);
}
public function addRelation($relation)
{
if (!$this->hasRelation($relation)) {
$this->relations[] = $relation;
}
return $this;
}
public function removeRelation($relation)
{
$this->relations->removeElement($relation);
return $this;
}
public function getRelations()
{
return $this->relations;
}
/** @OneToMany(targetEntity="DDC3699RelationMany", mappedBy="child") */
public $relations;
}

View File

@ -2,25 +2,11 @@
namespace Doctrine\Tests\Models\DDC3699;
/**
* @MappedSuperclass
*/
/** @MappedSuperclass */
abstract class DDC3699Parent
{
const CLASSNAME = __CLASS__;
/**
* @Column(type="string")
*/
protected $parentField;
public function getParentField()
{
return $this->parentField;
}
public function setParentField($parentField)
{
$this->parentField = $parentField;
}
/** @Column(type="string") */
public $parentField;
}

View File

@ -10,35 +10,9 @@ class DDC3699RelationMany
{
const CLASSNAME = __CLASS__;
/**
* @Id
* @Column(type="integer")
*/
protected $id;
/** @Id @Column(type="integer") */
public $id;
/**
* @ManyToOne(targetEntity="DDC3699Child", inversedBy="relations")
* @JoinColumn(name="child", referencedColumnName="id")
*/
protected $child;
public function getId()
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
}
public function getChild()
{
return $this->child;
}
public function setChild($child)
{
$this->child = $child;
}
/** @ManyToOne(targetEntity="DDC3699Child", inversedBy="relations") */
public $child;
}

View File

@ -10,34 +10,9 @@ class DDC3699RelationOne
{
const CLASSNAME = __CLASS__;
/**
* @Id
* @Column(type="integer")
*/
protected $id;
/** @Id @Column(type="integer") */
public $id;
/**
* @OneToOne(targetEntity="DDC3699Child", mappedBy="oneRelation")
*/
protected $child;
public function getId()
{
return $this->id;
}
public function setId($id)
{
$this->id = $id;
}
public function getChild()
{
return $this->child;
}
public function setChild($child)
{
$this->child = $child;
}
/** @OneToOne(targetEntity="DDC3699Child", mappedBy="oneRelation") */
public $child;
}

View File

@ -26,71 +26,87 @@ class DDC3597Test extends \Doctrine\Tests\OrmFunctionalTestCase
}
}
private function createChild($id, $relationClass, $relationMethod)
/**
* @group DDC-3699
*/
public function testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToOneUninitializedAssociations()
{
// element in DB
$child = new DDC3699Child();
$child->setId($id);
$child->setChildField('childValue');
$child->setParentField('parentValue');
$id = 1;
$relation = new $relationClass();
$relation->setId($id);
$relation->setChild($child);
$child->$relationMethod($relation);
$child = new DDC3699Child();
$child->id = $id;
$child->childField = 'childValue';
$child->parentField = 'parentValue';
$relation = new DDC3699RelationOne();
$relation->id = $id;
$relation->child = $child ;
$child->oneRelation = $relation;
$this->_em->persist($relation);
$this->_em->persist($child);
$this->_em->flush();
$this->_em->clear();
// detach
$this->_em->detach($relation);
$this->_em->detach($child);
}
// fixtures loaded
/* @var $unManagedChild DDC3699Child */
$unManagedChild = $this->_em->find(DDC3699Child::CLASSNAME, $id);
/**
* @group DDC-3699
*/
public function testMergeParentEntityFieldsOne()
{
$id = 1;
$this->createChild($id, DDC3699RelationOne::CLASSNAME, 'setOneRelation');
$unmanagedChild = $this->_em->find(DDC3699Child::CLASSNAME, $id);
$this->_em->detach($unmanagedChild);
$this->_em->detach($unManagedChild);
// make it managed again
$this->_em->find(DDC3699Child::CLASSNAME, $id);
$unmanagedChild->setChildField('modifiedChildValue');
$unmanagedChild->setParentField('modifiedParentValue');
$unManagedChild->childField = 'modifiedChildValue';
$unManagedChild->parentField = 'modifiedParentValue';
$mergedChild = $this->_em->merge($unmanagedChild);
/* @var $mergedChild DDC3699Child */
$mergedChild = $this->_em->merge($unManagedChild);
$this->assertEquals($mergedChild->getChildField(), 'modifiedChildValue');
$this->assertEquals($mergedChild->getParentField(), 'modifiedParentValue');
$this->assertSame($mergedChild->childField, 'modifiedChildValue');
$this->assertSame($mergedChild->parentField, 'modifiedParentValue');
}
/**
* @group DDC-3699
*/
public function testMergeParentEntityFieldsMany()
public function testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToManyUninitializedAssociations()
{
$id = 2;
$this->createChild($id, DDC3699RelationMany::CLASSNAME, 'addRelation');
$child = new DDC3699Child();
$child->id = $id;
$child->childField = 'childValue';
$child->parentField = 'parentValue';
$relation = new DDC3699RelationMany();
$relation->id = $id;
$relation->child = $child ;
$child->relations[] = $relation;
$this->_em->persist($relation);
$this->_em->persist($child);
$this->_em->flush();
$this->_em->clear();
/* @var $unmanagedChild DDC3699Child */
$unmanagedChild = $this->_em->find(DDC3699Child::CLASSNAME, $id);
$this->_em->detach($unmanagedChild);
// make it managed again
$this->_em->find(DDC3699Child::CLASSNAME, $id);
$unmanagedChild->setChildField('modifiedChildValue');
$unmanagedChild->setParentField('modifiedParentValue');
$unmanagedChild->childField = 'modifiedChildValue';
$unmanagedChild->parentField = 'modifiedParentValue';
/* @var $mergedChild DDC3699Child */
$mergedChild = $this->_em->merge($unmanagedChild);
$this->assertEquals($mergedChild->getChildField(), 'modifiedChildValue');
$this->assertEquals($mergedChild->getParentField(), 'modifiedParentValue');
$this->assertSame($mergedChild->childField, 'modifiedChildValue');
$this->assertSame($mergedChild->parentField, 'modifiedParentValue');
}
}