2015-11-25 04:20:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional;
|
|
|
|
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
2016-05-11 02:41:26 +07:00
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
2015-11-25 04:20:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group CascadeRemoveOrderTest
|
|
|
|
*/
|
2016-05-11 02:41:26 +07:00
|
|
|
class CascadeRemoveOrderTest extends OrmFunctionalTestCase
|
2015-11-25 04:20:35 +00:00
|
|
|
{
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$this->_schemaTool->createSchema(
|
|
|
|
[
|
2017-05-31 07:59:04 +02:00
|
|
|
$this->_em->getClassMetadata(CascadeRemoveOrderEntityO::class),
|
|
|
|
$this->_em->getClassMetadata(CascadeRemoveOrderEntityG::class),
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|
2015-11-25 04:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown()
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$this->_schemaTool->dropSchema(
|
|
|
|
[
|
2017-05-31 07:59:04 +02:00
|
|
|
$this->_em->getClassMetadata(CascadeRemoveOrderEntityO::class),
|
|
|
|
$this->_em->getClassMetadata(CascadeRemoveOrderEntityG::class),
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|
2015-11-25 04:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSingle()
|
|
|
|
{
|
|
|
|
$eO = new CascadeRemoveOrderEntityO();
|
|
|
|
$eG = new CascadeRemoveOrderEntityG($eO);
|
|
|
|
|
|
|
|
$this->_em->persist($eO);
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$eOloaded = $this->_em->find(CascadeRemoveOrderEntityO::class, $eO->getId());
|
2015-11-25 04:20:35 +00:00
|
|
|
|
|
|
|
$this->_em->remove($eOloaded);
|
|
|
|
$this->_em->flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMany()
|
|
|
|
{
|
|
|
|
$eO = new CascadeRemoveOrderEntityO();
|
|
|
|
$eG1 = new CascadeRemoveOrderEntityG($eO);
|
|
|
|
$eG2 = new CascadeRemoveOrderEntityG($eO);
|
|
|
|
$eG3 = new CascadeRemoveOrderEntityG($eO);
|
|
|
|
|
|
|
|
$eO->setOneToOneG($eG2);
|
|
|
|
|
|
|
|
$this->_em->persist($eO);
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$eOloaded = $this->_em->find(CascadeRemoveOrderEntityO::class, $eO->getId());
|
2015-11-25 04:20:35 +00:00
|
|
|
|
|
|
|
$this->_em->remove($eOloaded);
|
|
|
|
$this->_em->flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class CascadeRemoveOrderEntityO
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Id @Column(type="integer")
|
|
|
|
* @GeneratedValue
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OneToOne(targetEntity="Doctrine\Tests\ORM\Functional\CascadeRemoveOrderEntityG")
|
|
|
|
* @JoinColumn(nullable=true, onDelete="SET NULL")
|
|
|
|
*/
|
|
|
|
private $oneToOneG;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @OneToMany(
|
|
|
|
* targetEntity="Doctrine\Tests\ORM\Functional\CascadeRemoveOrderEntityG",
|
|
|
|
* mappedBy="ownerO",
|
|
|
|
* cascade={"persist", "remove"}
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
private $oneToManyG;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->oneToManyG = new ArrayCollection();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setOneToOneG(CascadeRemoveOrderEntityG $eG)
|
|
|
|
{
|
|
|
|
$this->oneToOneG = $eG;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOneToOneG()
|
|
|
|
{
|
|
|
|
return $this->oneToOneG;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addOneToManyG(CascadeRemoveOrderEntityG $eG)
|
|
|
|
{
|
|
|
|
$this->oneToManyG->add($eG);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getOneToManyGs()
|
|
|
|
{
|
|
|
|
return $this->oneToManyG->toArray();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class CascadeRemoveOrderEntityG
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Id @Column(type="integer")
|
|
|
|
* @GeneratedValue
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ManyToOne(
|
|
|
|
* targetEntity="Doctrine\Tests\ORM\Functional\CascadeRemoveOrderEntityO",
|
|
|
|
* inversedBy="oneToMany"
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
private $ownerO;
|
|
|
|
|
|
|
|
public function __construct(CascadeRemoveOrderEntityO $eO, $position=1)
|
|
|
|
{
|
|
|
|
$this->position = $position;
|
|
|
|
$this->ownerO= $eO;
|
|
|
|
$this->ownerO->addOneToManyG($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
2016-12-07 23:33:41 +01:00
|
|
|
}
|