DDC-3699 - #1387 - simpifying tests, clarifying on test method names
This commit is contained in:
parent
cbfd71cec6
commit
74883e535f
@ -2,90 +2,20 @@
|
|||||||
|
|
||||||
namespace Doctrine\Tests\Models\DDC3699;
|
namespace Doctrine\Tests\Models\DDC3699;
|
||||||
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
/** @Entity @Table(name="ddc3699_child") */
|
||||||
|
|
||||||
/**
|
|
||||||
* @Entity
|
|
||||||
* @Table(name="ddc3699_child")
|
|
||||||
*/
|
|
||||||
class DDC3699Child extends DDC3699Parent
|
class DDC3699Child extends DDC3699Parent
|
||||||
{
|
{
|
||||||
const CLASSNAME = __CLASS__;
|
const CLASSNAME = __CLASS__;
|
||||||
|
|
||||||
/**
|
/** @Id @Column(type="integer") */
|
||||||
* @Id
|
public $id;
|
||||||
* @Column(type="integer")
|
|
||||||
*/
|
|
||||||
protected $id;
|
|
||||||
|
|
||||||
/**
|
/** @Column(type="string") */
|
||||||
* @Column(type="string")
|
public $childField;
|
||||||
*/
|
|
||||||
protected $childField;
|
|
||||||
|
|
||||||
/**
|
/** @OneToOne(targetEntity="DDC3699RelationOne", inversedBy="child") */
|
||||||
* @OneToOne(targetEntity="DDC3699RelationOne", inversedBy="child")
|
public $oneRelation;
|
||||||
*/
|
|
||||||
protected $oneRelation;
|
|
||||||
|
|
||||||
/**
|
/** @OneToMany(targetEntity="DDC3699RelationMany", mappedBy="child") */
|
||||||
* @OneToMany(targetEntity="DDC3699RelationMany", mappedBy="child")
|
public $relations;
|
||||||
*/
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -2,25 +2,11 @@
|
|||||||
|
|
||||||
namespace Doctrine\Tests\Models\DDC3699;
|
namespace Doctrine\Tests\Models\DDC3699;
|
||||||
|
|
||||||
/**
|
/** @MappedSuperclass */
|
||||||
* @MappedSuperclass
|
|
||||||
*/
|
|
||||||
abstract class DDC3699Parent
|
abstract class DDC3699Parent
|
||||||
{
|
{
|
||||||
const CLASSNAME = __CLASS__;
|
const CLASSNAME = __CLASS__;
|
||||||
|
|
||||||
/**
|
/** @Column(type="string") */
|
||||||
* @Column(type="string")
|
public $parentField;
|
||||||
*/
|
|
||||||
protected $parentField;
|
|
||||||
|
|
||||||
public function getParentField()
|
|
||||||
{
|
|
||||||
return $this->parentField;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setParentField($parentField)
|
|
||||||
{
|
|
||||||
$this->parentField = $parentField;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -10,35 +10,9 @@ class DDC3699RelationMany
|
|||||||
{
|
{
|
||||||
const CLASSNAME = __CLASS__;
|
const CLASSNAME = __CLASS__;
|
||||||
|
|
||||||
/**
|
/** @Id @Column(type="integer") */
|
||||||
* @Id
|
public $id;
|
||||||
* @Column(type="integer")
|
|
||||||
*/
|
|
||||||
protected $id;
|
|
||||||
|
|
||||||
/**
|
/** @ManyToOne(targetEntity="DDC3699Child", inversedBy="relations") */
|
||||||
* @ManyToOne(targetEntity="DDC3699Child", inversedBy="relations")
|
public $child;
|
||||||
* @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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -10,34 +10,9 @@ class DDC3699RelationOne
|
|||||||
{
|
{
|
||||||
const CLASSNAME = __CLASS__;
|
const CLASSNAME = __CLASS__;
|
||||||
|
|
||||||
/**
|
/** @Id @Column(type="integer") */
|
||||||
* @Id
|
public $id;
|
||||||
* @Column(type="integer")
|
|
||||||
*/
|
|
||||||
protected $id;
|
|
||||||
|
|
||||||
/**
|
/** @OneToOne(targetEntity="DDC3699Child", mappedBy="oneRelation") */
|
||||||
* @OneToOne(targetEntity="DDC3699Child", mappedBy="oneRelation")
|
public $child;
|
||||||
*/
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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
|
$id = 1;
|
||||||
$child = new DDC3699Child();
|
|
||||||
$child->setId($id);
|
|
||||||
$child->setChildField('childValue');
|
|
||||||
$child->setParentField('parentValue');
|
|
||||||
|
|
||||||
$relation = new $relationClass();
|
$child = new DDC3699Child();
|
||||||
$relation->setId($id);
|
|
||||||
$relation->setChild($child);
|
$child->id = $id;
|
||||||
$child->$relationMethod($relation);
|
$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($relation);
|
||||||
$this->_em->persist($child);
|
$this->_em->persist($child);
|
||||||
$this->_em->flush();
|
$this->_em->flush();
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
// detach
|
// fixtures loaded
|
||||||
$this->_em->detach($relation);
|
/* @var $unManagedChild DDC3699Child */
|
||||||
$this->_em->detach($child);
|
$unManagedChild = $this->_em->find(DDC3699Child::CLASSNAME, $id);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$this->_em->detach($unManagedChild);
|
||||||
* @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);
|
|
||||||
|
|
||||||
// make it managed again
|
// make it managed again
|
||||||
$this->_em->find(DDC3699Child::CLASSNAME, $id);
|
$this->_em->find(DDC3699Child::CLASSNAME, $id);
|
||||||
|
|
||||||
$unmanagedChild->setChildField('modifiedChildValue');
|
$unManagedChild->childField = 'modifiedChildValue';
|
||||||
$unmanagedChild->setParentField('modifiedParentValue');
|
$unManagedChild->parentField = 'modifiedParentValue';
|
||||||
|
|
||||||
$mergedChild = $this->_em->merge($unmanagedChild);
|
/* @var $mergedChild DDC3699Child */
|
||||||
|
$mergedChild = $this->_em->merge($unManagedChild);
|
||||||
|
|
||||||
$this->assertEquals($mergedChild->getChildField(), 'modifiedChildValue');
|
$this->assertSame($mergedChild->childField, 'modifiedChildValue');
|
||||||
$this->assertEquals($mergedChild->getParentField(), 'modifiedParentValue');
|
$this->assertSame($mergedChild->parentField, 'modifiedParentValue');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group DDC-3699
|
* @group DDC-3699
|
||||||
*/
|
*/
|
||||||
public function testMergeParentEntityFieldsMany()
|
public function testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToManyUninitializedAssociations()
|
||||||
{
|
{
|
||||||
$id = 2;
|
$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);
|
$unmanagedChild = $this->_em->find(DDC3699Child::CLASSNAME, $id);
|
||||||
$this->_em->detach($unmanagedChild);
|
$this->_em->detach($unmanagedChild);
|
||||||
|
|
||||||
// make it managed again
|
// make it managed again
|
||||||
$this->_em->find(DDC3699Child::CLASSNAME, $id);
|
$this->_em->find(DDC3699Child::CLASSNAME, $id);
|
||||||
|
|
||||||
$unmanagedChild->setChildField('modifiedChildValue');
|
$unmanagedChild->childField = 'modifiedChildValue';
|
||||||
$unmanagedChild->setParentField('modifiedParentValue');
|
$unmanagedChild->parentField = 'modifiedParentValue';
|
||||||
|
|
||||||
|
/* @var $mergedChild DDC3699Child */
|
||||||
$mergedChild = $this->_em->merge($unmanagedChild);
|
$mergedChild = $this->_em->merge($unmanagedChild);
|
||||||
|
|
||||||
$this->assertEquals($mergedChild->getChildField(), 'modifiedChildValue');
|
$this->assertSame($mergedChild->childField, 'modifiedChildValue');
|
||||||
$this->assertEquals($mergedChild->getParentField(), 'modifiedParentValue');
|
$this->assertSame($mergedChild->parentField, 'modifiedParentValue');
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user