PageRenderTime 53ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/test/testsuite/generator/platform/MysqlPlatformTest.php

https://github.com/1989gaurav/Propel
PHP | 716 lines | 555 code | 70 blank | 91 comment | 0 complexity | 4c72e748a32b96f9df3e38e474709f60 MD5 | raw file
  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. require_once dirname(__FILE__) . '/PlatformTestProvider.php';
  10. require_once dirname(__FILE__) . '/../../../../generator/lib/platform/MysqlPlatform.php';
  11. require_once dirname(__FILE__) . '/../../../../generator/lib/model/Column.php';
  12. require_once dirname(__FILE__) . '/../../../../generator/lib/model/VendorInfo.php';
  13. /**
  14. *
  15. * @package generator.platform
  16. */
  17. class MysqlPlatformTest extends PlatformTestProvider
  18. {
  19. /**
  20. * Get the Platform object for this class
  21. *
  22. * @return Platform
  23. */
  24. protected function getPlatform()
  25. {
  26. return new MysqlPlatform();
  27. }
  28. public function testGetSequenceNameDefault()
  29. {
  30. $table = new Table('foo');
  31. $table->setIdMethod(IDMethod::NATIVE);
  32. $expected = 'foo_SEQ';
  33. $this->assertEquals($expected, $this->getPlatform()->getSequenceName($table));
  34. }
  35. public function testGetSequenceNameCustom()
  36. {
  37. $table = new Table('foo');
  38. $table->setIdMethod(IDMethod::NATIVE);
  39. $idMethodParameter = new IdMethodParameter();
  40. $idMethodParameter->setValue('foo_sequence');
  41. $table->addIdMethodParameter($idMethodParameter);
  42. $table->setIdMethod(IDMethod::NATIVE);
  43. $expected = 'foo_sequence';
  44. $this->assertEquals($expected, $this->getPlatform()->getSequenceName($table));
  45. }
  46. /**
  47. * @dataProvider providerForTestGetAddTablesDDLSchema
  48. */
  49. public function testGetAddTablesDDLSchema($schema)
  50. {
  51. $database = $this->getDatabaseFromSchema($schema);
  52. $expected = <<<EOF
  53. # This is a fix for InnoDB in MySQL >= 4.1.x
  54. # It "suspends judgement" for fkey relationships until are tables are set.
  55. SET FOREIGN_KEY_CHECKS = 0;
  56. -- ---------------------------------------------------------------------
  57. -- x.book
  58. -- ---------------------------------------------------------------------
  59. DROP TABLE IF EXISTS `x`.`book`;
  60. CREATE TABLE `x`.`book`
  61. (
  62. `id` INTEGER NOT NULL AUTO_INCREMENT,
  63. `title` VARCHAR(255) NOT NULL,
  64. `author_id` INTEGER,
  65. PRIMARY KEY (`id`),
  66. INDEX `book_I_1` (`title`),
  67. INDEX `book_FI_1` (`author_id`),
  68. CONSTRAINT `book_FK_1`
  69. FOREIGN KEY (`author_id`)
  70. REFERENCES `y`.`author` (`id`)
  71. ) ENGINE=MyISAM;
  72. -- ---------------------------------------------------------------------
  73. -- y.author
  74. -- ---------------------------------------------------------------------
  75. DROP TABLE IF EXISTS `y`.`author`;
  76. CREATE TABLE `y`.`author`
  77. (
  78. `id` INTEGER NOT NULL AUTO_INCREMENT,
  79. `first_name` VARCHAR(100),
  80. `last_name` VARCHAR(100),
  81. PRIMARY KEY (`id`)
  82. ) ENGINE=MyISAM;
  83. -- ---------------------------------------------------------------------
  84. -- x.book_summary
  85. -- ---------------------------------------------------------------------
  86. DROP TABLE IF EXISTS `x`.`book_summary`;
  87. CREATE TABLE `x`.`book_summary`
  88. (
  89. `id` INTEGER NOT NULL AUTO_INCREMENT,
  90. `book_id` INTEGER NOT NULL,
  91. `summary` TEXT NOT NULL,
  92. PRIMARY KEY (`id`),
  93. INDEX `book_summary_FI_1` (`book_id`),
  94. CONSTRAINT `book_summary_FK_1`
  95. FOREIGN KEY (`book_id`)
  96. REFERENCES `x`.`book` (`id`)
  97. ON DELETE CASCADE
  98. ) ENGINE=MyISAM;
  99. # This restores the fkey checks, after having unset them earlier
  100. SET FOREIGN_KEY_CHECKS = 1;
  101. EOF;
  102. $this->assertEquals($expected, $this->getPlatform()->getAddTablesDDL($database));
  103. }
  104. /**
  105. * @dataProvider providerForTestGetAddTablesDDL
  106. */
  107. public function testGetAddTablesDDL($schema)
  108. {
  109. $database = $this->getDatabaseFromSchema($schema);
  110. $expected = <<<EOF
  111. # This is a fix for InnoDB in MySQL >= 4.1.x
  112. # It "suspends judgement" for fkey relationships until are tables are set.
  113. SET FOREIGN_KEY_CHECKS = 0;
  114. -- ---------------------------------------------------------------------
  115. -- book
  116. -- ---------------------------------------------------------------------
  117. DROP TABLE IF EXISTS `book`;
  118. CREATE TABLE `book`
  119. (
  120. `id` INTEGER NOT NULL AUTO_INCREMENT,
  121. `title` VARCHAR(255) NOT NULL,
  122. `author_id` INTEGER,
  123. PRIMARY KEY (`id`),
  124. INDEX `book_I_1` (`title`),
  125. INDEX `book_FI_1` (`author_id`),
  126. CONSTRAINT `book_FK_1`
  127. FOREIGN KEY (`author_id`)
  128. REFERENCES `author` (`id`)
  129. ) ENGINE=MyISAM;
  130. -- ---------------------------------------------------------------------
  131. -- author
  132. -- ---------------------------------------------------------------------
  133. DROP TABLE IF EXISTS `author`;
  134. CREATE TABLE `author`
  135. (
  136. `id` INTEGER NOT NULL AUTO_INCREMENT,
  137. `first_name` VARCHAR(100),
  138. `last_name` VARCHAR(100),
  139. PRIMARY KEY (`id`)
  140. ) ENGINE=MyISAM;
  141. # This restores the fkey checks, after having unset them earlier
  142. SET FOREIGN_KEY_CHECKS = 1;
  143. EOF;
  144. $this->assertEquals($expected, $this->getPlatform()->getAddTablesDDL($database));
  145. }
  146. /**
  147. * @dataProvider providerForTestGetAddTablesSkipSQLDDL
  148. */
  149. public function testGetAddTablesSkipSQLDDL($schema)
  150. {
  151. $database = $this->getDatabaseFromSchema($schema);
  152. $expected = "
  153. # This is a fix for InnoDB in MySQL >= 4.1.x
  154. # It \"suspends judgement\" for fkey relationships until are tables are set.
  155. SET FOREIGN_KEY_CHECKS = 0;
  156. # This restores the fkey checks, after having unset them earlier
  157. SET FOREIGN_KEY_CHECKS = 1;
  158. ";
  159. $this->assertEquals($expected, $this->getPlatform()->getAddTablesDDL($database));
  160. }
  161. /**
  162. * @dataProvider providerForTestGetAddTableDDLSimplePK
  163. */
  164. public function testGetAddTableDDLSimplePK($schema)
  165. {
  166. $table = $this->getTableFromSchema($schema);
  167. $expected = "
  168. CREATE TABLE `foo`
  169. (
  170. `id` INTEGER NOT NULL AUTO_INCREMENT,
  171. `bar` VARCHAR(255) NOT NULL,
  172. PRIMARY KEY (`id`)
  173. ) ENGINE=MyISAM COMMENT='This is foo table';
  174. ";
  175. $this->assertEquals($expected, $this->getPlatform()->getAddTableDDL($table));
  176. }
  177. /**
  178. * @dataProvider providerForTestGetAddTableDDLCompositePK
  179. */
  180. public function testGetAddTableDDLCompositePK($schema)
  181. {
  182. $table = $this->getTableFromSchema($schema);
  183. $expected = "
  184. CREATE TABLE `foo`
  185. (
  186. `foo` INTEGER NOT NULL,
  187. `bar` INTEGER NOT NULL,
  188. `baz` VARCHAR(255) NOT NULL,
  189. PRIMARY KEY (`foo`,`bar`)
  190. ) ENGINE=MyISAM;
  191. ";
  192. $this->assertEquals($expected, $this->getPlatform()->getAddTableDDL($table));
  193. }
  194. /**
  195. * @dataProvider providerForTestGetAddTableDDLUniqueIndex
  196. */
  197. public function testGetAddTableDDLUniqueIndex($schema)
  198. {
  199. $table = $this->getTableFromSchema($schema);
  200. $expected = "
  201. CREATE TABLE `foo`
  202. (
  203. `id` INTEGER NOT NULL AUTO_INCREMENT,
  204. `bar` INTEGER,
  205. PRIMARY KEY (`id`),
  206. UNIQUE INDEX `foo_U_1` (`bar`)
  207. ) ENGINE=MyISAM;
  208. ";
  209. $this->assertEquals($expected, $this->getPlatform()->getAddTableDDL($table));
  210. }
  211. public function testGetAddTableDDLIndex()
  212. {
  213. $schema = <<<EOF
  214. <database name="test">
  215. <table name="foo">
  216. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  217. <column name="bar" type="INTEGER" />
  218. <index>
  219. <index-column name="bar" />
  220. </index>
  221. </table>
  222. </database>
  223. EOF;
  224. $table = $this->getTableFromSchema($schema);
  225. $expected = "
  226. CREATE TABLE `foo`
  227. (
  228. `id` INTEGER NOT NULL AUTO_INCREMENT,
  229. `bar` INTEGER,
  230. PRIMARY KEY (`id`),
  231. INDEX `foo_I_1` (`bar`)
  232. ) ENGINE=MyISAM;
  233. ";
  234. $this->assertEquals($expected, $this->getPlatform()->getAddTableDDL($table));
  235. }
  236. public function testGetAddTableDDLForeignKey()
  237. {
  238. $schema = <<<EOF
  239. <database name="test">
  240. <table name="foo">
  241. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  242. <column name="bar_id" type="INTEGER" />
  243. <foreign-key foreignTable="bar">
  244. <reference local="bar_id" foreign="id" />
  245. </foreign-key>
  246. </table>
  247. <table name="bar">
  248. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  249. </table>
  250. </database>
  251. EOF;
  252. $table = $this->getTableFromSchema($schema);
  253. $expected = "
  254. CREATE TABLE `foo`
  255. (
  256. `id` INTEGER NOT NULL AUTO_INCREMENT,
  257. `bar_id` INTEGER,
  258. PRIMARY KEY (`id`),
  259. INDEX `foo_FI_1` (`bar_id`),
  260. CONSTRAINT `foo_FK_1`
  261. FOREIGN KEY (`bar_id`)
  262. REFERENCES `bar` (`id`)
  263. ) ENGINE=MyISAM;
  264. ";
  265. $this->assertEquals($expected, $this->getPlatform()->getAddTableDDL($table));
  266. }
  267. public function testGetAddTableDDLForeignKeySkipSql()
  268. {
  269. $schema = <<<EOF
  270. <database name="test">
  271. <table name="foo">
  272. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  273. <column name="bar_id" type="INTEGER" />
  274. <foreign-key foreignTable="bar" skipSql="true">
  275. <reference local="bar_id" foreign="id" />
  276. </foreign-key>
  277. </table>
  278. <table name="bar">
  279. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  280. </table>
  281. </database>
  282. EOF;
  283. $table = $this->getTableFromSchema($schema);
  284. $expected = "
  285. CREATE TABLE `foo`
  286. (
  287. `id` INTEGER NOT NULL AUTO_INCREMENT,
  288. `bar_id` INTEGER,
  289. PRIMARY KEY (`id`),
  290. INDEX `foo_FI_1` (`bar_id`)
  291. ) ENGINE=MyISAM;
  292. ";
  293. $this->assertEquals($expected, $this->getPlatform()->getAddTableDDL($table));
  294. }
  295. public function testGetAddTableDDLEngine()
  296. {
  297. $schema = <<<EOF
  298. <database name="test">
  299. <table name="foo">
  300. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  301. </table>
  302. </database>
  303. EOF;
  304. $platform = new MysqlPlatform();
  305. $platform->setTableEngineKeyword('TYPE');
  306. $platform->setDefaultTableEngine('MEMORY');
  307. $xtad = new XmlToAppData($platform);
  308. $appData = $xtad->parseString($schema);
  309. $table = $appData->getDatabase()->getTable('foo');
  310. $expected = "
  311. CREATE TABLE `foo`
  312. (
  313. `id` INTEGER NOT NULL AUTO_INCREMENT,
  314. PRIMARY KEY (`id`)
  315. ) TYPE=MEMORY;
  316. ";
  317. $this->assertEquals($expected, $platform->getAddTableDDL($table));
  318. }
  319. public function testGetAddTableDDLVendor()
  320. {
  321. $schema = <<<EOF
  322. <database name="test">
  323. <table name="foo">
  324. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  325. <vendor type="mysql">
  326. <parameter name="Engine" value="InnoDB"/>
  327. <parameter name="Charset" value="utf8"/>
  328. </vendor>
  329. </table>
  330. </database>
  331. EOF;
  332. $table = $this->getTableFromSchema($schema);
  333. $expected = "
  334. CREATE TABLE `foo`
  335. (
  336. `id` INTEGER NOT NULL AUTO_INCREMENT,
  337. PRIMARY KEY (`id`)
  338. ) ENGINE=InnoDB CHARACTER SET='utf8';
  339. ";
  340. $this->assertEquals($expected, $this->getPlatform()->getAddTableDDL($table));
  341. }
  342. /**
  343. * @dataProvider providerForTestGetAddTableDDLSchema
  344. */
  345. public function testGetAddTableDDLSchema($schema)
  346. {
  347. $table = $this->getTableFromSchema($schema, 'Woopah.foo');
  348. $expected = "
  349. CREATE TABLE `Woopah`.`foo`
  350. (
  351. `id` INTEGER NOT NULL AUTO_INCREMENT,
  352. `bar` INTEGER,
  353. PRIMARY KEY (`id`)
  354. ) ENGINE=MyISAM;
  355. ";
  356. $this->assertEquals($expected, $this->getPlatform()->getAddTableDDL($table));
  357. }
  358. public function testGetDropTableDDL()
  359. {
  360. $table = new Table('foo');
  361. $expected = "
  362. DROP TABLE IF EXISTS `foo`;
  363. ";
  364. $this->assertEquals($expected, $this->getPlatform()->getDropTableDDL($table));
  365. }
  366. /**
  367. * @dataProvider providerForTestGetAddTableDDLSchema
  368. */
  369. public function testGetDropTableDDLSchema($schema)
  370. {
  371. $table = $this->getTableFromSchema($schema, 'Woopah.foo');
  372. $expected = "
  373. DROP TABLE IF EXISTS `Woopah`.`foo`;
  374. ";
  375. $this->assertEquals($expected, $this->getPlatform()->getDropTableDDL($table));
  376. }
  377. public function testGetColumnDDL()
  378. {
  379. $column = new Column('foo');
  380. $column->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
  381. $column->getDomain()->replaceScale(2);
  382. $column->getDomain()->replaceSize(3);
  383. $column->setNotNull(true);
  384. $column->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
  385. $expected = '`foo` DOUBLE(3,2) DEFAULT 123 NOT NULL';
  386. $this->assertEquals($expected, $this->getPlatform()->getColumnDDL($column));
  387. }
  388. public function testGetColumnDDLCharsetVendor()
  389. {
  390. $column = new Column('foo');
  391. $column->getDomain()->copy($this->getPlatform()->getDomainForType('LONGVARCHAR'));
  392. $vendor = new VendorInfo('mysql');
  393. $vendor->setParameter('Charset', 'greek');
  394. $column->addVendorInfo($vendor);
  395. $expected = '`foo` TEXT CHARACTER SET \'greek\'';
  396. $this->assertEquals($expected, $this->getPlatform()->getColumnDDL($column));
  397. }
  398. public function testGetColumnDDLCharsetCollation()
  399. {
  400. $column = new Column('foo');
  401. $column->getDomain()->copy($this->getPlatform()->getDomainForType('LONGVARCHAR'));
  402. $vendor = new VendorInfo('mysql');
  403. $vendor->setParameter('Collate', 'latin1_german2_ci');
  404. $column->addVendorInfo($vendor);
  405. $expected = '`foo` TEXT COLLATE \'latin1_german2_ci\'';
  406. $this->assertEquals($expected, $this->getPlatform()->getColumnDDL($column));
  407. $column = new Column('foo');
  408. $column->getDomain()->copy($this->getPlatform()->getDomainForType('LONGVARCHAR'));
  409. $vendor = new VendorInfo('mysql');
  410. $vendor->setParameter('Collation', 'latin1_german2_ci');
  411. $column->addVendorInfo($vendor);
  412. $expected = '`foo` TEXT COLLATE \'latin1_german2_ci\'';
  413. $this->assertEquals($expected, $this->getPlatform()->getColumnDDL($column));
  414. }
  415. public function testGetColumnDDLComment()
  416. {
  417. $column = new Column('foo');
  418. $column->getDomain()->copy($this->getPlatform()->getDomainForType('INTEGER'));
  419. $column->setDescription('This is column Foo');
  420. $expected = '`foo` INTEGER COMMENT \'This is column Foo\'';
  421. $this->assertEquals($expected, $this->getPlatform()->getColumnDDL($column));
  422. }
  423. public function testGetColumnDDLCharsetNotNull()
  424. {
  425. $column = new Column('foo');
  426. $column->getDomain()->copy($this->getPlatform()->getDomainForType('LONGVARCHAR'));
  427. $column->setNotNull(true);
  428. $vendor = new VendorInfo('mysql');
  429. $vendor->setParameter('Charset', 'greek');
  430. $column->addVendorInfo($vendor);
  431. $expected = '`foo` TEXT CHARACTER SET \'greek\' NOT NULL';
  432. $this->assertEquals($expected, $this->getPlatform()->getColumnDDL($column));
  433. }
  434. public function testGetColumnDDLCustomSqlType()
  435. {
  436. $column = new Column('foo');
  437. $column->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
  438. $column->getDomain()->replaceScale(2);
  439. $column->getDomain()->replaceSize(3);
  440. $column->setNotNull(true);
  441. $column->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
  442. $column->getDomain()->replaceSqlType('DECIMAL(5,6)');
  443. $expected = '`foo` DECIMAL(5,6) DEFAULT 123 NOT NULL';
  444. $this->assertEquals($expected, $this->getPlatform()->getColumnDDL($column));
  445. }
  446. public function testGetPrimaryKeyDDLSimpleKey()
  447. {
  448. $table = new Table('foo');
  449. $column = new Column('bar');
  450. $column->setPrimaryKey(true);
  451. $table->addColumn($column);
  452. $expected = 'PRIMARY KEY (`bar`)';
  453. $this->assertEquals($expected, $this->getPlatform()->getPrimaryKeyDDL($table));
  454. }
  455. public function testGetPrimaryKeyDDLCompositeKey()
  456. {
  457. $table = new Table('foo');
  458. $column1 = new Column('bar1');
  459. $column1->setPrimaryKey(true);
  460. $table->addColumn($column1);
  461. $column2 = new Column('bar2');
  462. $column2->setPrimaryKey(true);
  463. $table->addColumn($column2);
  464. $expected = 'PRIMARY KEY (`bar1`,`bar2`)';
  465. $this->assertEquals($expected, $this->getPlatform()->getPrimaryKeyDDL($table));
  466. }
  467. /**
  468. * @dataProvider providerForTestPrimaryKeyDDL
  469. */
  470. public function testGetDropPrimaryKeyDDL($table)
  471. {
  472. $expected = "
  473. ALTER TABLE `foo` DROP PRIMARY KEY;
  474. ";
  475. $this->assertEquals($expected, $this->getPlatform()->getDropPrimaryKeyDDL($table));
  476. }
  477. /**
  478. * @dataProvider providerForTestPrimaryKeyDDL
  479. */
  480. public function testGetAddPrimaryKeyDDL($table)
  481. {
  482. $expected = "
  483. ALTER TABLE `foo` ADD PRIMARY KEY (`bar`);
  484. ";
  485. $this->assertEquals($expected, $this->getPlatform()->getAddPrimaryKeyDDL($table));
  486. }
  487. /**
  488. * @dataProvider providerForTestGetIndicesDDL
  489. */
  490. public function testAddIndicesDDL($table)
  491. {
  492. $expected = "
  493. CREATE INDEX `babar` ON `foo` (`bar1`,`bar2`);
  494. CREATE INDEX `foo_index` ON `foo` (`bar1`);
  495. ";
  496. $this->assertEquals($expected, $this->getPLatform()->getAddIndicesDDL($table));
  497. }
  498. /**
  499. * @dataProvider providerForTestGetIndexDDL
  500. */
  501. public function testAddIndexDDL($index)
  502. {
  503. $expected = "
  504. CREATE INDEX `babar` ON `foo` (`bar1`,`bar2`);
  505. ";
  506. $this->assertEquals($expected, $this->getPLatform()->getAddIndexDDL($index));
  507. }
  508. /**
  509. * @dataProvider providerForTestGetIndexDDL
  510. */
  511. public function testDropIndexDDL($index)
  512. {
  513. $expected = "
  514. DROP INDEX `babar` ON `foo`;
  515. ";
  516. $this->assertEquals($expected, $this->getPLatform()->getDropIndexDDL($index));
  517. }
  518. /**
  519. * @dataProvider providerForTestGetIndexDDL
  520. */
  521. public function testGetIndexDDL($index)
  522. {
  523. $expected = 'INDEX `babar` (`bar1`, `bar2`)';
  524. $this->assertEquals($expected, $this->getPLatform()->getIndexDDL($index));
  525. }
  526. public function testGetIndexDDLKeySize()
  527. {
  528. $table = new Table('foo');
  529. $column1 = new Column('bar1');
  530. $column1->getDomain()->copy($this->getPlatform()->getDomainForType('VARCHAR'));
  531. $column1->setSize(5);
  532. $table->addColumn($column1);
  533. $index = new Index('bar_index');
  534. $index->addColumn($column1);
  535. $table->addIndex($index);
  536. $expected = 'INDEX `bar_index` (`bar1`(5))';
  537. $this->assertEquals($expected, $this->getPLatform()->getIndexDDL($index));
  538. }
  539. public function testGetIndexDDLFulltext()
  540. {
  541. $table = new Table('foo');
  542. $column1 = new Column('bar1');
  543. $column1->getDomain()->copy($this->getPlatform()->getDomainForType('LONGVARCHAR'));
  544. $table->addColumn($column1);
  545. $index = new Index('bar_index');
  546. $index->addColumn($column1);
  547. $vendor = new VendorInfo('mysql');
  548. $vendor->setParameter('Index_type', 'FULLTEXT');
  549. $index->addVendorInfo($vendor);
  550. $table->addIndex($index);
  551. $expected = 'FULLTEXT INDEX `bar_index` (`bar1`)';
  552. $this->assertEquals($expected, $this->getPLatform()->getIndexDDL($index));
  553. }
  554. /**
  555. * @dataProvider providerForTestGetUniqueDDL
  556. */
  557. public function testGetUniqueDDL($index)
  558. {
  559. $expected = 'UNIQUE INDEX `babar` (`bar1`, `bar2`)';
  560. $this->assertEquals($expected, $this->getPLatform()->getUniqueDDL($index));
  561. }
  562. /**
  563. * @dataProvider providerForTestGetForeignKeysDDL
  564. */
  565. public function testGetAddForeignKeysDDL($table)
  566. {
  567. $expected = "
  568. ALTER TABLE `foo` ADD CONSTRAINT `foo_bar_FK`
  569. FOREIGN KEY (`bar_id`)
  570. REFERENCES `bar` (`id`)
  571. ON DELETE CASCADE;
  572. ALTER TABLE `foo` ADD CONSTRAINT `foo_baz_FK`
  573. FOREIGN KEY (`baz_id`)
  574. REFERENCES `baz` (`id`)
  575. ON DELETE SET NULL;
  576. ";
  577. $this->assertEquals($expected, $this->getPlatform()->getAddForeignKeysDDL($table));
  578. }
  579. /**
  580. * @dataProvider providerForTestGetForeignKeyDDL
  581. */
  582. public function testGetAddForeignKeyDDL($fk)
  583. {
  584. $expected = "
  585. ALTER TABLE `foo` ADD CONSTRAINT `foo_bar_FK`
  586. FOREIGN KEY (`bar_id`)
  587. REFERENCES `bar` (`id`)
  588. ON DELETE CASCADE;
  589. ";
  590. $this->assertEquals($expected, $this->getPlatform()->getAddForeignKeyDDL($fk));
  591. }
  592. /**
  593. * @dataProvider providerForTestGetForeignKeySkipSqlDDL
  594. */
  595. public function testGetAddForeignKeySkipSqlDDL($fk)
  596. {
  597. $expected = '';
  598. $this->assertEquals($expected, $this->getPlatform()->getAddForeignKeyDDL($fk));
  599. }
  600. /**
  601. * @dataProvider providerForTestGetForeignKeyDDL
  602. */
  603. public function testGetDropForeignKeyDDL($fk)
  604. {
  605. $expected = "
  606. ALTER TABLE `foo` DROP FOREIGN KEY `foo_bar_FK`;
  607. ";
  608. $this->assertEquals($expected, $this->getPLatform()->getDropForeignKeyDDL($fk));
  609. }
  610. /**
  611. * @dataProvider providerForTestGetForeignKeySkipSqlDDL
  612. */
  613. public function testGetDropForeignKeySkipSqlDDL($fk)
  614. {
  615. $expected = '';
  616. $this->assertEquals($expected, $this->getPlatform()->getDropForeignKeyDDL($fk));
  617. }
  618. /**
  619. * @dataProvider providerForTestGetForeignKeyDDL
  620. */
  621. public function testGetForeignKeyDDL($fk)
  622. {
  623. $expected = "CONSTRAINT `foo_bar_FK`
  624. FOREIGN KEY (`bar_id`)
  625. REFERENCES `bar` (`id`)
  626. ON DELETE CASCADE";
  627. $this->assertEquals($expected, $this->getPLatform()->getForeignKeyDDL($fk));
  628. }
  629. /**
  630. * @dataProvider providerForTestGetForeignKeySkipSqlDDL
  631. */
  632. public function testGetForeignKeySkipSqlDDL($fk)
  633. {
  634. $expected = '';
  635. $this->assertEquals($expected, $this->getPlatform()->getForeignKeyDDL($fk));
  636. }
  637. public function testGetCommentBlockDDL()
  638. {
  639. $expected = "
  640. -- ---------------------------------------------------------------------
  641. -- foo bar
  642. -- ---------------------------------------------------------------------
  643. ";
  644. $this->assertEquals($expected, $this->getPLatform()->getCommentBlockDDL('foo bar'));
  645. }
  646. }