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