3 namespace Doctrine\Tests\ORM\Functional\Ticket;
5 use Doctrine\Common\Collections\ArrayCollection;
7 require_once __DIR__ . '/../../../TestInit.php';
9 class DDC735Test extends \Doctrine\Tests\OrmFunctionalTestCase
11 protected function setUp()
15 $this->_schemaTool->createSchema(array(
16 $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC735Product'),
17 $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC735Review')
19 } catch(\Exception $e) {
24 public function testRemoveElement_AppliesOrphanRemoval()
26 // Create a product and its first review
27 $product = new DDC735Product;
28 $review = new DDC735Review($product);
31 $this->_em->persist($product);
35 $this->assertEquals(1, count($product->getReviews()));
38 $reviewId = $review->getId();
39 $product->removeReview($review);
43 $this->assertEquals(0, count($product->getReviews()), 'count($reviews) should be 0 after removing its only Review');
46 $this->_em->refresh($product);
48 // It should still be 0
49 $this->assertEquals(0, count($product->getReviews()), 'count($reviews) should still be 0 after the refresh');
51 // Review should also not be available anymore
52 $this->assertNull($this->_em->find(__NAMESPACE__.'\DDC735Review', $reviewId));
62 * @Id @Column(type="integer") @GeneratedValue
68 * targetEntity="DDC735Review",
70 * cascade={"persist"},
76 public function __construct()
78 $this->reviews = new ArrayCollection;
81 public function getReviews()
83 return $this->reviews;
86 public function addReview(DDC735Review $review)
88 $this->reviews->add($review);
91 public function removeReview(DDC735Review $review)
93 $this->reviews->removeElement($review);
103 * @Id @Column(type="integer") @GeneratedValue
108 * @ManyToOne(targetEntity="DDC735Product", inversedBy="reviews")
112 public function __construct(DDC735Product $product)
114 $this->product = $product;
115 $product->addReview($this);
118 public function getId()