DDC-3699 - #1387 - simpifying tests, clarifying on test method names
This commit is contained in:
parent
69ef75ff2d
commit
86abbb0e78
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user