2009-08-21 22:13:22 +04:00
< ? php
2009-09-05 13:22:34 +04:00
namespace Doctrine\Tests\ORM\Functional\SchemaTool ;
use Doctrine\ORM\Tools\SchemaTool ,
Doctrine\ORM\Mapping\ClassMetadata ;
require_once __DIR__ . '/../../../TestInit.php' ;
class PostgreSqlSchemaToolTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp () {
parent :: setUp ();
if ( $this -> _em -> getConnection () -> getDatabasePlatform () -> getName () !== 'postgresql' ) {
$this -> markTestSkipped ( 'The ' . __CLASS__ . ' requires the use of postgresql.' );
}
}
2009-12-11 03:56:47 +03:00
public function testPostgresMetadataSequenceIncrementedBy10 ()
{
$address = $this -> _em -> getClassMetadata ( 'Doctrine\Tests\Models\CMS\CmsAddress' );
$this -> assertEquals ( 10 , $address -> sequenceGeneratorDefinition [ 'allocationSize' ]);
}
2009-09-05 13:22:34 +04:00
public function testGetCreateSchemaSql ()
{
$classes = array (
$this -> _em -> getClassMetadata ( 'Doctrine\Tests\Models\CMS\CmsAddress' ),
$this -> _em -> getClassMetadata ( 'Doctrine\Tests\Models\CMS\CmsUser' ),
$this -> _em -> getClassMetadata ( 'Doctrine\Tests\Models\CMS\CmsPhonenumber' ),
);
$tool = new SchemaTool ( $this -> _em );
$sql = $tool -> getCreateSchemaSql ( $classes );
2009-12-11 03:56:47 +03:00
$this -> assertEquals ( count ( $sql ), 11 );
2009-09-05 13:22:34 +04:00
2010-05-01 05:57:58 +04:00
$this -> assertEquals ( " CREATE TABLE cms_addresses (id INT NOT NULL, user_id INT DEFAULT NULL, country VARCHAR(50) NOT NULL, zip VARCHAR(50) NOT NULL, city VARCHAR(50) NOT NULL, PRIMARY KEY(id)) " , $sql [ 0 ]);
2009-12-11 03:56:47 +03:00
$this -> assertEquals ( " CREATE TABLE cms_users (id INT NOT NULL, status VARCHAR(50) NOT NULL, username VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) " , $sql [ 1 ]);
$this -> assertEquals ( " CREATE UNIQUE INDEX cms_users_username_uniq ON cms_users (username) " , $sql [ 2 ]);
2010-02-04 22:25:37 +03:00
$this -> assertEquals ( " CREATE TABLE cms_users_groups (user_id INT NOT NULL, group_id INT NOT NULL, PRIMARY KEY(user_id, group_id)) " , $sql [ 3 ]);
2009-12-11 03:56:47 +03:00
$this -> assertEquals ( " CREATE TABLE cms_phonenumbers (phonenumber VARCHAR(50) NOT NULL, user_id INT DEFAULT NULL, PRIMARY KEY(phonenumber)) " , $sql [ 4 ]);
$this -> assertEquals ( " CREATE SEQUENCE cms_addresses_id_seq INCREMENT BY 10 MINVALUE 1 START 1 " , $sql [ 5 ]);
$this -> assertEquals ( " CREATE SEQUENCE cms_users_id_seq INCREMENT BY 10 MINVALUE 1 START 1 " , $sql [ 6 ]);
$this -> assertEquals ( " ALTER TABLE cms_addresses ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE " , $sql [ 7 ]);
$this -> assertEquals ( " ALTER TABLE cms_users_groups ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE " , $sql [ 8 ]);
$this -> assertEquals ( " ALTER TABLE cms_users_groups ADD FOREIGN KEY (group_id) REFERENCES cms_groups(id) NOT DEFERRABLE INITIALLY IMMEDIATE " , $sql [ 9 ]);
$this -> assertEquals ( " ALTER TABLE cms_phonenumbers ADD FOREIGN KEY (user_id) REFERENCES cms_users(id) NOT DEFERRABLE INITIALLY IMMEDIATE " , $sql [ 10 ]);
2009-09-05 13:22:34 +04:00
}
public function testGetCreateSchemaSql2 ()
{
$classes = array (
$this -> _em -> getClassMetadata ( 'Doctrine\Tests\Models\Generic\DecimalModel' )
);
$tool = new SchemaTool ( $this -> _em );
$sql = $tool -> getCreateSchemaSql ( $classes );
$this -> assertEquals ( 2 , count ( $sql ));
2010-02-26 22:39:12 +03:00
$this -> assertEquals ( 'CREATE TABLE decimal_model (id INT NOT NULL, "decimal" NUMERIC(5, 2) NOT NULL, "high_scale" NUMERIC(14, 4) NOT NULL, PRIMARY KEY(id))' , $sql [ 0 ]);
2009-12-11 03:56:47 +03:00
$this -> assertEquals ( " CREATE SEQUENCE decimal_model_id_seq INCREMENT BY 10 MINVALUE 1 START 1 " , $sql [ 1 ]);
2009-09-05 13:22:34 +04:00
}
public function testGetCreateSchemaSql3 ()
{
$classes = array (
$this -> _em -> getClassMetadata ( 'Doctrine\Tests\Models\Generic\BooleanModel' )
);
$tool = new SchemaTool ( $this -> _em );
$sql = $tool -> getCreateSchemaSql ( $classes );
$this -> assertEquals ( 2 , count ( $sql ));
$this -> assertEquals ( " CREATE TABLE boolean_model (id INT NOT NULL, booleanField BOOLEAN NOT NULL, PRIMARY KEY(id)) " , $sql [ 0 ]);
2009-12-11 03:56:47 +03:00
$this -> assertEquals ( " CREATE SEQUENCE boolean_model_id_seq INCREMENT BY 10 MINVALUE 1 START 1 " , $sql [ 1 ]);
2009-09-05 13:22:34 +04:00
}
}