Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC422Test.php
1 <?php
2 namespace Doctrine\Tests\ORM\Functional\Ticket;
3
4 require_once __DIR__ . '/../../../TestInit.php';
5
6 class DDC422Test extends \Doctrine\Tests\OrmFunctionalTestCase
7 {
8     protected function setUp()
9     {
10         parent::setUp();
11         //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
12         $this->_schemaTool->createSchema(array(
13             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Guest'),
14             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Customer'),
15             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC422Contact')
16         ));
17     }
18
19     /**
20      * @group DDC-422
21      */
22     public function testIssue()
23     {
24         $customer = new DDC422Customer;
25         $this->_em->persist($customer);
26         $this->_em->flush();
27         $this->_em->clear();
28
29         $customer = $this->_em->find(get_class($customer), $customer->id);
30
31         $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $customer->contacts);
32         $this->assertFalse($customer->contacts->isInitialized());
33         $contact = new DDC422Contact;
34         $customer->contacts->add($contact);
35         $this->assertTrue($customer->contacts->isDirty());
36         $this->assertFalse($customer->contacts->isInitialized());
37         $this->_em->flush();
38
39         $this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select count(*) from ddc422_customers_contacts"));
40     }
41 }
42
43 /**
44  * @Entity
45  * @InheritanceType("JOINED")
46  * @DiscriminatorColumn(name="discr", type="string")
47  * @DiscriminatorMap({"guest" = "DDC422Guest", "customer" = "DDC422Customer"})
48  */
49 class DDC422Guest {
50     /** @Id @Column(type="integer") @GeneratedValue */
51     public $id;
52 }
53
54 /** @Entity */
55 class DDC422Customer extends DDC422Guest {
56     /**
57      * @ManyToMany(targetEntity="DDC422Contact", cascade={"persist","remove"})
58      * @JoinTable(name="ddc422_customers_contacts",
59      *      joinColumns={@JoinColumn(name="customer_id", referencedColumnName="id", onDelete="cascade" )},
60      *      inverseJoinColumns={@JoinColumn(name="contact_id", referencedColumnName="id", onDelete="cascade" )}
61      *      )
62      */
63     public $contacts;
64
65     public function __construct() {
66         $this->contacts = new \Doctrine\Common\Collections\ArrayCollection;
67     }
68 }
69
70 /** @Entity */
71 class DDC422Contact {
72     /** @Id @Column(type="integer") @GeneratedValue */
73     public $id;
74 }
75