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',
|
2011-12-29 05:05:54 +04:00
|
|
|
'Doctrine\Tests\Models\CMS\CmsArticle',
|
|
|
|
'Doctrine\Tests\Models\CMS\CmsEmail',
|
2010-02-07 15:36:30 +03:00
|
|
|
);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-06-19 00:47:21 +04:00
|
|
|
try {
|
|
|
|
$this->schemaTool->createSchema($classMetadata);
|
|
|
|
} catch(\Exception $e) {
|
|
|
|
// was already created
|
|
|
|
}
|
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());
|
2011-06-19 00:47:21 +04:00
|
|
|
$sql = array_filter($sql, function($sql) { return strpos($sql, 'DROP') === false; });
|
2011-12-20 01:56:19 +04:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|