SchemaManagerFunctionalTestCase.php 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <?php
  2. namespace Doctrine\Tests\DBAL\Functional\Schema;
  3. use Doctrine\DBAL\Types\Type,
  4. Doctrine\DBAL\Schema\AbstractSchemaManager;
  5. use Doctrine\DBAL\Platforms\AbstractPlatform;
  6. require_once __DIR__ . '/../../../TestInit.php';
  7. class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTestCase
  8. {
  9. /**
  10. * @var \Doctrine\DBAL\Schema\AbstractSchemaManager
  11. */
  12. protected $_sm;
  13. protected function setUp()
  14. {
  15. parent::setUp();
  16. $class = get_class($this);
  17. $e = explode('\\', $class);
  18. $testClass = end($e);
  19. $dbms = strtolower(str_replace('SchemaManagerTest', null, $testClass));
  20. if ($this->_conn->getDatabasePlatform()->getName() !== $dbms) {
  21. $this->markTestSkipped('The ' . $testClass .' requires the use of ' . $dbms);
  22. }
  23. $this->_sm = $this->_conn->getSchemaManager();
  24. }
  25. public function testListSequences()
  26. {
  27. if(!$this->_conn->getDatabasePlatform()->supportsSequences()) {
  28. $this->markTestSkipped($this->_conn->getDriver()->getName().' does not support sequences.');
  29. }
  30. $sequence = new \Doctrine\DBAL\Schema\Sequence('list_sequences_test_seq', 20, 10);
  31. $this->_sm->createSequence($sequence);
  32. $sequences = $this->_sm->listSequences();
  33. $this->assertInternalType('array', $sequences, 'listSequences() should return an array.');
  34. $foundSequence = null;
  35. foreach($sequences AS $sequence) {
  36. $this->assertInstanceOf('Doctrine\DBAL\Schema\Sequence', $sequence, 'Array elements of listSequences() should be Sequence instances.');
  37. if(strtolower($sequence->getName()) == 'list_sequences_test_seq') {
  38. $foundSequence = $sequence;
  39. }
  40. }
  41. $this->assertNotNull($foundSequence, "Sequence with name 'list_sequences_test_seq' was not found.");
  42. $this->assertEquals(20, $foundSequence->getAllocationSize(), "Allocation Size is expected to be 20.");
  43. $this->assertEquals(10, $foundSequence->getInitialValue(), "Initial Value is expected to be 10.");
  44. }
  45. public function testListDatabases()
  46. {
  47. if (!$this->_sm->getDatabasePlatform()->supportsCreateDropDatabase()) {
  48. $this->markTestSkipped('Cannot drop Database client side with this Driver.');
  49. }
  50. $this->_sm->dropAndCreateDatabase('test_create_database');
  51. $databases = $this->_sm->listDatabases();
  52. $databases = \array_map('strtolower', $databases);
  53. $this->assertEquals(true, \in_array('test_create_database', $databases));
  54. }
  55. public function testListTables()
  56. {
  57. $this->createTestTable('list_tables_test');
  58. $tables = $this->_sm->listTables();
  59. $this->assertInternalType('array', $tables);
  60. $this->assertTrue(count($tables) > 0, "List Tables has to find at least one table named 'list_tables_test'.");
  61. $foundTable = false;
  62. foreach ($tables AS $table) {
  63. $this->assertInstanceOf('Doctrine\DBAL\Schema\Table', $table);
  64. if (strtolower($table->getName()) == 'list_tables_test') {
  65. $foundTable = true;
  66. $this->assertTrue($table->hasColumn('id'));
  67. $this->assertTrue($table->hasColumn('test'));
  68. $this->assertTrue($table->hasColumn('foreign_key_test'));
  69. }
  70. }
  71. $this->assertTrue( $foundTable , "The 'list_tables_test' table has to be found.");
  72. }
  73. public function createListTableColumns()
  74. {
  75. $table = new \Doctrine\DBAL\Schema\Table('list_table_columns');
  76. $table->addColumn('id', 'integer', array('notnull' => true));
  77. $table->addColumn('test', 'string', array('length' => 255, 'notnull' => false));
  78. $table->addColumn('foo', 'text', array('notnull' => true));
  79. $table->addColumn('bar', 'decimal', array('precision' => 10, 'scale' => 4, 'notnull' => false));
  80. $table->addColumn('baz1', 'datetime');
  81. $table->addColumn('baz2', 'time');
  82. $table->addColumn('baz3', 'date');
  83. return $table;
  84. }
  85. public function testListTableColumns()
  86. {
  87. $table = $this->createListTableColumns();
  88. $this->_sm->dropAndCreateTable($table);
  89. $columns = $this->_sm->listTableColumns('list_table_columns');
  90. $this->assertArrayHasKey('id', $columns);
  91. $this->assertEquals('id', strtolower($columns['id']->getname()));
  92. $this->assertInstanceOf('Doctrine\DBAL\Types\IntegerType', $columns['id']->gettype());
  93. $this->assertEquals(false, $columns['id']->getunsigned());
  94. $this->assertEquals(true, $columns['id']->getnotnull());
  95. $this->assertEquals(null, $columns['id']->getdefault());
  96. $this->assertInternalType('array', $columns['id']->getPlatformOptions());
  97. $this->assertArrayHasKey('test', $columns);
  98. $this->assertEquals('test', strtolower($columns['test']->getname()));
  99. $this->assertInstanceOf('Doctrine\DBAL\Types\StringType', $columns['test']->gettype());
  100. $this->assertEquals(255, $columns['test']->getlength());
  101. $this->assertEquals(false, $columns['test']->getfixed());
  102. $this->assertEquals(false, $columns['test']->getnotnull());
  103. $this->assertEquals(null, $columns['test']->getdefault());
  104. $this->assertInternalType('array', $columns['test']->getPlatformOptions());
  105. $this->assertEquals('foo', strtolower($columns['foo']->getname()));
  106. $this->assertInstanceOf('Doctrine\DBAL\Types\TextType', $columns['foo']->gettype());
  107. $this->assertEquals(false, $columns['foo']->getunsigned());
  108. $this->assertEquals(false, $columns['foo']->getfixed());
  109. $this->assertEquals(true, $columns['foo']->getnotnull());
  110. $this->assertEquals(null, $columns['foo']->getdefault());
  111. $this->assertInternalType('array', $columns['foo']->getPlatformOptions());
  112. $this->assertEquals('bar', strtolower($columns['bar']->getname()));
  113. $this->assertInstanceOf('Doctrine\DBAL\Types\DecimalType', $columns['bar']->gettype());
  114. $this->assertEquals(null, $columns['bar']->getlength());
  115. $this->assertEquals(10, $columns['bar']->getprecision());
  116. $this->assertEquals(4, $columns['bar']->getscale());
  117. $this->assertEquals(false, $columns['bar']->getunsigned());
  118. $this->assertEquals(false, $columns['bar']->getfixed());
  119. $this->assertEquals(false, $columns['bar']->getnotnull());
  120. $this->assertEquals(null, $columns['bar']->getdefault());
  121. $this->assertInternalType('array', $columns['bar']->getPlatformOptions());
  122. $this->assertEquals('baz1', strtolower($columns['baz1']->getname()));
  123. $this->assertInstanceOf('Doctrine\DBAL\Types\DateTimeType', $columns['baz1']->gettype());
  124. $this->assertEquals(true, $columns['baz1']->getnotnull());
  125. $this->assertEquals(null, $columns['baz1']->getdefault());
  126. $this->assertInternalType('array', $columns['baz1']->getPlatformOptions());
  127. $this->assertEquals('baz2', strtolower($columns['baz2']->getname()));
  128. $this->assertContains($columns['baz2']->gettype()->getName(), array('time', 'date', 'datetime'));
  129. $this->assertEquals(true, $columns['baz2']->getnotnull());
  130. $this->assertEquals(null, $columns['baz2']->getdefault());
  131. $this->assertInternalType('array', $columns['baz2']->getPlatformOptions());
  132. $this->assertEquals('baz3', strtolower($columns['baz3']->getname()));
  133. $this->assertContains($columns['baz2']->gettype()->getName(), array('time', 'date', 'datetime'));
  134. $this->assertEquals(true, $columns['baz3']->getnotnull());
  135. $this->assertEquals(null, $columns['baz3']->getdefault());
  136. $this->assertInternalType('array', $columns['baz3']->getPlatformOptions());
  137. }
  138. public function testDiffListTableColumns()
  139. {
  140. if ($this->_sm->getDatabasePlatform()->getName() == 'oracle') {
  141. $this->markTestSkipped('Does not work with Oracle, since it cannot detect DateTime, Date and Time differenecs (at the moment).');
  142. }
  143. $offlineTable = $this->createListTableColumns();
  144. $onlineTable = $this->_sm->listTableDetails('list_table_columns');
  145. $comparator = new \Doctrine\DBAL\Schema\Comparator();
  146. $diff = $comparator->diffTable($offlineTable, $onlineTable);
  147. $this->assertFalse($diff, "No differences should be detected with the offline vs online schema.");
  148. }
  149. public function testListTableIndexes()
  150. {
  151. $table = $this->getTestTable('list_table_indexes_test');
  152. $table->addUniqueIndex(array('test'), 'test_index_name');
  153. $table->addIndex(array('id', 'test'), 'test_composite_idx');
  154. $this->_sm->createTable($table);
  155. $tableIndexes = $this->_sm->listTableIndexes('list_table_indexes_test');
  156. $this->assertEquals(3, count($tableIndexes));
  157. $this->assertArrayHasKey('primary', $tableIndexes, 'listTableIndexes() has to return a "primary" array key.');
  158. $this->assertEquals(array('id'), array_map('strtolower', $tableIndexes['primary']->getColumns()));
  159. $this->assertTrue($tableIndexes['primary']->isUnique());
  160. $this->assertTrue($tableIndexes['primary']->isPrimary());
  161. $this->assertEquals('test_index_name', $tableIndexes['test_index_name']->getName());
  162. $this->assertEquals(array('test'), array_map('strtolower', $tableIndexes['test_index_name']->getColumns()));
  163. $this->assertTrue($tableIndexes['test_index_name']->isUnique());
  164. $this->assertFalse($tableIndexes['test_index_name']->isPrimary());
  165. $this->assertEquals('test_composite_idx', $tableIndexes['test_composite_idx']->getName());
  166. $this->assertEquals(array('id', 'test'), array_map('strtolower', $tableIndexes['test_composite_idx']->getColumns()));
  167. $this->assertFalse($tableIndexes['test_composite_idx']->isUnique());
  168. $this->assertFalse($tableIndexes['test_composite_idx']->isPrimary());
  169. }
  170. public function testDropAndCreateIndex()
  171. {
  172. $table = $this->getTestTable('test_create_index');
  173. $table->addUniqueIndex(array('test'), 'test');
  174. $this->_sm->dropAndCreateTable($table);
  175. $this->_sm->dropAndCreateIndex($table->getIndex('test'), $table);
  176. $tableIndexes = $this->_sm->listTableIndexes('test_create_index');
  177. $this->assertInternalType('array', $tableIndexes);
  178. $this->assertEquals('test', strtolower($tableIndexes['test']->getName()));
  179. $this->assertEquals(array('test'), array_map('strtolower', $tableIndexes['test']->getColumns()));
  180. $this->assertTrue($tableIndexes['test']->isUnique());
  181. $this->assertFalse($tableIndexes['test']->isPrimary());
  182. }
  183. public function testCreateTableWithForeignKeys()
  184. {
  185. if(!$this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
  186. $this->markTestSkipped('Platform does not support foreign keys.');
  187. }
  188. $tableB = $this->getTestTable('test_foreign');
  189. $this->_sm->dropAndCreateTable($tableB);
  190. $tableA = $this->getTestTable('test_create_fk');
  191. $tableA->addForeignKeyConstraint('test_foreign', array('foreign_key_test'), array('id'));
  192. $this->_sm->dropAndCreateTable($tableA);
  193. $fkTable = $this->_sm->listTableDetails('test_create_fk');
  194. $fkConstraints = $fkTable->getForeignKeys();
  195. $this->assertEquals(1, count($fkConstraints), "Table 'test_create_fk1' has to have one foreign key.");
  196. $fkConstraint = current($fkConstraints);
  197. $this->assertType('\Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkConstraint);
  198. $this->assertEquals('test_foreign', strtolower($fkConstraint->getForeignTableName()));
  199. $this->assertEquals(array('foreign_key_test'), array_map('strtolower', $fkConstraint->getColumns()));
  200. $this->assertEquals(array('id'), array_map('strtolower', $fkConstraint->getForeignColumns()));
  201. $this->assertTrue($fkTable->columnsAreIndexed($fkConstraint->getColumns()), "The columns of a foreign key constraint should always be indexed.");
  202. }
  203. public function testListForeignKeys()
  204. {
  205. if(!$this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) {
  206. $this->markTestSkipped('Does not support foreign key constraints.');
  207. }
  208. $this->createTestTable('test_create_fk1');
  209. $this->createTestTable('test_create_fk2');
  210. $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(
  211. array('foreign_key_test'), 'test_create_fk2', array('id'), 'foreign_key_test_fk', array('onDelete' => 'CASCADE')
  212. );
  213. $this->_sm->createForeignKey($foreignKey, 'test_create_fk1');
  214. $fkeys = $this->_sm->listTableForeignKeys('test_create_fk1');
  215. $this->assertEquals(1, count($fkeys), "Table 'test_create_fk1' has to have one foreign key.");
  216. $this->assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]);
  217. $this->assertEquals(array('foreign_key_test'), array_map('strtolower', $fkeys[0]->getLocalColumns()));
  218. $this->assertEquals(array('id'), array_map('strtolower', $fkeys[0]->getForeignColumns()));
  219. $this->assertEquals('test_create_fk2', strtolower($fkeys[0]->getForeignTableName()));
  220. if($fkeys[0]->hasOption('onDelete')) {
  221. $this->assertEquals('CASCADE', $fkeys[0]->getOption('onDelete'));
  222. }
  223. }
  224. protected function getCreateExampleViewSql()
  225. {
  226. $this->markTestSkipped('No Create Example View SQL was defined for this SchemaManager');
  227. }
  228. public function testCreateSchema()
  229. {
  230. $this->createTestTable('test_table');
  231. $schema = $this->_sm->createSchema();
  232. $this->assertTrue($schema->hasTable('test_table'));
  233. }
  234. public function testAlterTableScenario()
  235. {
  236. if(!$this->_sm->getDatabasePlatform()->supportsAlterTable()) {
  237. $this->markTestSkipped('Alter Table is not supported by this platform.');
  238. }
  239. $this->createTestTable('alter_table');
  240. $this->createTestTable('alter_table_foreign');
  241. $table = $this->_sm->listTableDetails('alter_table');
  242. $this->assertTrue($table->hasColumn('id'));
  243. $this->assertTrue($table->hasColumn('test'));
  244. $this->assertTrue($table->hasColumn('foreign_key_test'));
  245. $this->assertEquals(0, count($table->getForeignKeys()));
  246. $this->assertEquals(1, count($table->getIndexes()));
  247. $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table");
  248. $tableDiff->addedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', Type::getType('integer'));
  249. $tableDiff->removedColumns['test'] = $table->getColumn('test');
  250. $this->_sm->alterTable($tableDiff);
  251. $table = $this->_sm->listTableDetails('alter_table');
  252. $this->assertFalse($table->hasColumn('test'));
  253. $this->assertTrue($table->hasColumn('foo'));
  254. $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table");
  255. $tableDiff->addedIndexes[] = new \Doctrine\DBAL\Schema\Index('foo_idx', array('foo'));
  256. $this->_sm->alterTable($tableDiff);
  257. $table = $this->_sm->listTableDetails('alter_table');
  258. $this->assertEquals(2, count($table->getIndexes()));
  259. $this->assertTrue($table->hasIndex('foo_idx'));
  260. $this->assertEquals(array('foo'), array_map('strtolower', $table->getIndex('foo_idx')->getColumns()));
  261. $this->assertFalse($table->getIndex('foo_idx')->isPrimary());
  262. $this->assertFalse($table->getIndex('foo_idx')->isUnique());
  263. $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table");
  264. $tableDiff->changedIndexes[] = new \Doctrine\DBAL\Schema\Index('foo_idx', array('foo', 'foreign_key_test'));
  265. $this->_sm->alterTable($tableDiff);
  266. $table = $this->_sm->listTableDetails('alter_table');
  267. $this->assertEquals(2, count($table->getIndexes()));
  268. $this->assertTrue($table->hasIndex('foo_idx'));
  269. $this->assertEquals(array('foo', 'foreign_key_test'), array_map('strtolower', $table->getIndex('foo_idx')->getColumns()));
  270. $tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table");
  271. $tableDiff->removedIndexes[] = new \Doctrine\DBAL\Schema\Index('foo_idx', array('foo', 'foreign_key_test'));
  272. $fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('foreign_key_test'), 'alter_table_foreign', array('id'));
  273. $tableDiff->addedForeignKeys[] = $fk;
  274. $this->_sm->alterTable($tableDiff);
  275. $table = $this->_sm->listTableDetails('alter_table');
  276. // dont check for index size here, some platforms automatically add indexes for foreign keys.
  277. $this->assertFalse($table->hasIndex('foo_idx'));
  278. $this->assertEquals(1, count($table->getForeignKeys()));
  279. $fks = $table->getForeignKeys();
  280. $foreignKey = current($fks);
  281. $this->assertEquals('alter_table_foreign', strtolower($foreignKey->getForeignTableName()));
  282. $this->assertEquals(array('foreign_key_test'), array_map('strtolower', $foreignKey->getColumns()));
  283. $this->assertEquals(array('id'), array_map('strtolower', $foreignKey->getForeignColumns()));
  284. }
  285. public function testCreateAndListViews()
  286. {
  287. $this->createTestTable('view_test_table');
  288. $name = "doctrine_test_view";
  289. $sql = "SELECT * FROM view_test_table";
  290. $view = new \Doctrine\DBAL\Schema\View($name, $sql);
  291. $this->_sm->dropAndCreateView($view);
  292. $views = $this->_sm->listViews();
  293. }
  294. public function testAutoincrementDetection()
  295. {
  296. if (!$this->_sm->getDatabasePlatform()->supportsIdentityColumns()) {
  297. $this->markTestSkipped('This test is only supported on platforms that have autoincrement');
  298. }
  299. $table = new \Doctrine\DBAL\Schema\Table('test_autoincrement');
  300. $table->setSchemaConfig($this->_sm->createSchemaConfig());
  301. $table->addColumn('id', 'integer', array('autoincrement' => true));
  302. $table->setPrimaryKey(array('id'));
  303. $this->_sm->createTable($table);
  304. $inferredTable = $this->_sm->listTableDetails('test_autoincrement');
  305. $this->assertTrue($inferredTable->hasColumn('id'));
  306. $this->assertTrue($inferredTable->getColumn('id')->getAutoincrement());
  307. }
  308. /**
  309. * @group DDC-887
  310. */
  311. public function testUpdateSchemaWithForeignKeyRenaming()
  312. {
  313. if (!$this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
  314. $this->markTestSkipped('This test is only supported on platforms that have foreign keys.');
  315. }
  316. $table = new \Doctrine\DBAL\Schema\Table('test_fk_base');
  317. $table->addColumn('id', 'integer');
  318. $table->setPrimaryKey(array('id'));
  319. $tableFK = new \Doctrine\DBAL\Schema\Table('test_fk_rename');
  320. $tableFK->setSchemaConfig($this->_sm->createSchemaConfig());
  321. $tableFK->addColumn('id', 'integer');
  322. $tableFK->addColumn('fk_id', 'integer');
  323. $tableFK->setPrimaryKey(array('id'));
  324. $tableFK->addIndex(array('fk_id'), 'fk_idx');
  325. $tableFK->addForeignKeyConstraint('test_fk_base', array('fk_id'), array('id'));
  326. $this->_sm->createTable($table);
  327. $this->_sm->createTable($tableFK);
  328. $tableFKNew = new \Doctrine\DBAL\Schema\Table('test_fk_rename');
  329. $tableFKNew->setSchemaConfig($this->_sm->createSchemaConfig());
  330. $tableFKNew->addColumn('id', 'integer');
  331. $tableFKNew->addColumn('rename_fk_id', 'integer');
  332. $tableFKNew->setPrimaryKey(array('id'));
  333. $tableFKNew->addIndex(array('rename_fk_id'), 'fk_idx');
  334. $tableFKNew->addForeignKeyConstraint('test_fk_base', array('rename_fk_id'), array('id'));
  335. $c = new \Doctrine\DBAL\Schema\Comparator();
  336. $tableDiff = $c->diffTable($tableFK, $tableFKNew);
  337. $this->_sm->alterTable($tableDiff);
  338. }
  339. /**
  340. * @group DBAL-42
  341. */
  342. public function testGetColumnComment()
  343. {
  344. if (!$this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && !$this->_conn->getDatabasePlatform()->supportsCommentOnStatement()) {
  345. $this->markTestSkipped('Database does not support column comments.');
  346. }
  347. $table = new \Doctrine\DBAL\Schema\Table('column_comment_test');
  348. $table->addColumn('id', 'integer', array('comment' => 'This is a comment'));
  349. $table->setPrimaryKey(array('id'));
  350. $this->_sm->createTable($table);
  351. $columns = $this->_sm->listTableColumns("column_comment_test");
  352. $this->assertEquals(1, count($columns));
  353. $this->assertEquals('This is a comment', $columns['id']->getComment());
  354. }
  355. /**
  356. * @group DBAL-42
  357. */
  358. public function testAutomaticallyAppendCommentOnMarkedColumns()
  359. {
  360. if (!$this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && !$this->_conn->getDatabasePlatform()->supportsCommentOnStatement()) {
  361. $this->markTestSkipped('Database does not support column comments.');
  362. }
  363. $table = new \Doctrine\DBAL\Schema\Table('column_comment_test2');
  364. $table->addColumn('id', 'integer', array('comment' => 'This is a comment'));
  365. $table->addColumn('obj', 'object', array('comment' => 'This is a comment'));
  366. $table->addColumn('arr', 'array', array('comment' => 'This is a comment'));
  367. $table->setPrimaryKey(array('id'));
  368. $this->_sm->createTable($table);
  369. $columns = $this->_sm->listTableColumns("column_comment_test2");
  370. $this->assertEquals(3, count($columns));
  371. $this->assertEquals('This is a comment', $columns['id']->getComment());
  372. $this->assertEquals('This is a comment', $columns['obj']->getComment(), "The Doctrine2 Typehint should be stripped from comment.");
  373. $this->assertInstanceOf('Doctrine\DBAL\Types\ObjectType', $columns['obj']->getType(), "The Doctrine2 should be detected from comment hint.");
  374. $this->assertEquals('This is a comment', $columns['arr']->getComment(), "The Doctrine2 Typehint should be stripped from comment.");
  375. $this->assertInstanceOf('Doctrine\DBAL\Types\ArrayType', $columns['arr']->getType(), "The Doctrine2 should be detected from comment hint.");
  376. }
  377. /**
  378. * @param string $name
  379. * @param array $data
  380. */
  381. protected function createTestTable($name = 'test_table', $data = array())
  382. {
  383. $options = array();
  384. if (isset($data['options'])) {
  385. $options = $data['options'];
  386. }
  387. $table = $this->getTestTable($name, $options);
  388. $this->_sm->dropAndCreateTable($table);
  389. }
  390. protected function getTestTable($name, $options=array())
  391. {
  392. $table = new \Doctrine\DBAL\Schema\Table($name, array(), array(), array(), false, $options);
  393. $table->setSchemaConfig($this->_sm->createSchemaConfig());
  394. $table->addColumn('id', 'integer', array('notnull' => true));
  395. $table->setPrimaryKey(array('id'));
  396. $table->addColumn('test', 'string', array('length' => 255));
  397. $table->addColumn('foreign_key_test', 'integer');
  398. return $table;
  399. }
  400. protected function assertHasTable($tables, $tableName)
  401. {
  402. $foundTable = false;
  403. foreach ($tables AS $table) {
  404. $this->assertInstanceOf('Doctrine\DBAL\Schema\Table', $table, 'No Table instance was found in tables array.');
  405. if (strtolower($table->getName()) == 'list_tables_test_new_name') {
  406. $foundTable = true;
  407. }
  408. }
  409. $this->assertTrue($foundTable, "Could not find new table");
  410. }
  411. }