2010-02-07 15:36:30 +03:00
|
|
|
<?php
|
|
|
|
|
2010-07-04 15:17:26 +04:00
|
|
|
namespace Doctrine\Tests\ORM\Functional\SchemaTool;
|
2010-02-07 15:36:30 +03:00
|
|
|
|
|
|
|
use Doctrine\ORM\Tools;
|
|
|
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../../../TestInit.php';
|
|
|
|
|
2010-07-04 15:17:26 +04:00
|
|
|
/**
|
|
|
|
* WARNING: This test should be run as last test! It can affect others very easily!
|
|
|
|
*/
|
2010-02-07 15:36:30 +03:00
|
|
|
class DDC214Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
2010-11-16 23:31:54 +03:00
|
|
|
private $classes = array();
|
|
|
|
private $schemaTool = null;
|
|
|
|
|
2010-02-07 15:36:30 +03:00
|
|
|
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.');
|
|
|
|
}
|
2010-11-16 23:31:54 +03:00
|
|
|
$this->schemaTool = new Tools\SchemaTool($this->_em);
|
2010-02-07 15:36:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-214
|
|
|
|
*/
|
|
|
|
public function testCmsAddressModel()
|
|
|
|
{
|
2010-11-16 23:31:54 +03:00
|
|
|
$this->classes = array(
|
2010-02-07 15:36:30 +03:00
|
|
|
'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'
|
|
|
|
);
|
|
|
|
|
2010-11-16 23:31:54 +03:00
|
|
|
$this->assertCreatedSchemaNeedsNoUpdates($this->classes);
|
2010-02-07 15:36:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-214
|
|
|
|
*/
|
|
|
|
public function testCompanyModel()
|
|
|
|
{
|
2010-11-16 23:31:54 +03:00
|
|
|
$this->classes = array(
|
2010-02-07 15:36:30 +03:00
|
|
|
'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'
|
|
|
|
);
|
|
|
|
|
2010-11-16 23:31:54 +03:00
|
|
|
$this->assertCreatedSchemaNeedsNoUpdates($this->classes);
|
2010-02-07 15:36:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function assertCreatedSchemaNeedsNoUpdates($classes)
|
|
|
|
{
|
|
|
|
$classMetadata = array();
|
|
|
|
foreach ($classes AS $class) {
|
|
|
|
$classMetadata[] = $this->_em->getClassMetadata($class);
|
|
|
|
}
|
|
|
|
|
2010-11-16 23:31:54 +03:00
|
|
|
$this->schemaTool->dropDatabase();
|
|
|
|
$this->schemaTool->createSchema($classMetadata);
|
2010-02-07 15:36:30 +03:00
|
|
|
|
|
|
|
$sm = $this->_em->getConnection()->getSchemaManager();
|
|
|
|
|
|
|
|
$fromSchema = $sm->createSchema();
|
2010-11-16 23:31:54 +03:00
|
|
|
$toSchema = $this->schemaTool->getSchemaFromMetadata($classMetadata);
|
2010-02-07 15:36:30 +03:00
|
|
|
|
|
|
|
$comparator = new \Doctrine\DBAL\Schema\Comparator();
|
|
|
|
$schemaDiff = $comparator->compare($fromSchema, $toSchema);
|
|
|
|
|
|
|
|
$sql = $schemaDiff->toSql($this->_em->getConnection()->getDatabasePlatform());
|
2010-11-16 23:31:54 +03:00
|
|
|
$this->assertEquals(0, count($sql), "SQL: " . implode(PHP_EOL, $sql));
|
2010-02-07 15:36:30 +03:00
|
|
|
}
|
|
|
|
}
|