Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / SchemaTool / DDC214Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\SchemaTool;
4
5 use Doctrine\ORM\Tools;
6
7
8 require_once __DIR__ . '/../../../TestInit.php';
9
10 /**
11  * WARNING: This test should be run as last test! It can affect others very easily!
12  */
13 class DDC214Test extends \Doctrine\Tests\OrmFunctionalTestCase
14 {
15     private $classes = array();
16     private $schemaTool = null;
17
18     public function setUp() {
19         parent::setUp();
20
21         $conn = $this->_em->getConnection();
22
23         if (strpos($conn->getDriver()->getName(), "sqlite") !== false) {
24             $this->markTestSkipped('SQLite does not support ALTER TABLE statements.');
25         }
26         $this->schemaTool = new Tools\SchemaTool($this->_em);
27     }
28
29     /**
30      * @group DDC-214
31      */
32     public function testCmsAddressModel()
33     {
34         $this->classes = array(
35             'Doctrine\Tests\Models\CMS\CmsUser',
36             'Doctrine\Tests\Models\CMS\CmsPhonenumber',
37             'Doctrine\Tests\Models\CMS\CmsAddress',
38             'Doctrine\Tests\Models\CMS\CmsGroup',
39             'Doctrine\Tests\Models\CMS\CmsArticle',
40             'Doctrine\Tests\Models\CMS\CmsEmail',
41         );
42
43         $this->assertCreatedSchemaNeedsNoUpdates($this->classes);
44     }
45
46     /**
47      * @group DDC-214
48      */
49     public function testCompanyModel()
50     {
51         $this->classes = array(
52             'Doctrine\Tests\Models\Company\CompanyPerson',
53             'Doctrine\Tests\Models\Company\CompanyEmployee',
54             'Doctrine\Tests\Models\Company\CompanyManager',
55             'Doctrine\Tests\Models\Company\CompanyOrganization',
56             'Doctrine\Tests\Models\Company\CompanyEvent',
57             'Doctrine\Tests\Models\Company\CompanyAuction',
58             'Doctrine\Tests\Models\Company\CompanyRaffle',
59             'Doctrine\Tests\Models\Company\CompanyCar'
60         );
61
62         $this->assertCreatedSchemaNeedsNoUpdates($this->classes);
63     }
64
65     public function assertCreatedSchemaNeedsNoUpdates($classes)
66     {
67         $classMetadata = array();
68         foreach ($classes AS $class) {
69             $classMetadata[] = $this->_em->getClassMetadata($class);
70         }
71
72         try {
73             $this->schemaTool->createSchema($classMetadata);
74         } catch(\Exception $e) {
75             // was already created
76         }
77
78         $sm = $this->_em->getConnection()->getSchemaManager();
79
80         $fromSchema = $sm->createSchema();
81         $toSchema = $this->schemaTool->getSchemaFromMetadata($classMetadata);
82
83         $comparator = new \Doctrine\DBAL\Schema\Comparator();
84         $schemaDiff = $comparator->compare($fromSchema, $toSchema);
85
86         $sql = $schemaDiff->toSql($this->_em->getConnection()->getDatabasePlatform());
87         $sql = array_filter($sql, function($sql) { return strpos($sql, 'DROP') === false; });
88
89         $this->assertEquals(0, count($sql), "SQL: " . implode(PHP_EOL, $sql));
90     }
91 }