PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/vendor/propel/test/testsuite/generator/platform/PlatformMigrationTestProvider.php

https://bitbucket.org/bayrock/gw2spidy
PHP | 559 lines | 509 code | 39 blank | 11 comment | 0 complexity | cb38c72fc720aa9afded2cbeef296e26 MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause
  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__) . '/PlatformTestBase.php';
  10. require_once dirname(__FILE__) . '/../../../../generator/lib/model/diff/PropelDatabaseComparator.php';
  11. require_once dirname(__FILE__) . '/../../../../generator/lib/model/diff/PropelTableComparator.php';
  12. require_once dirname(__FILE__) . '/../../../../generator/lib/model/diff/PropelColumnComparator.php';
  13. /**
  14. * provider for platform migration unit tests
  15. * @package generator.platform
  16. */
  17. abstract class PlatformMigrationTestProvider extends PlatformTestBase
  18. {
  19. public function providerForTestGetModifyDatabaseDDL()
  20. {
  21. $schema1 = <<<EOF
  22. <database name="test">
  23. <table name="foo1">
  24. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  25. <column name="blooopoo" type="INTEGER" />
  26. </table>
  27. <table name="foo2">
  28. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  29. <column name="bar" type="INTEGER" />
  30. <column name="baz" type="VARCHAR" size="12" required="true" />
  31. </table>
  32. <table name="foo3">
  33. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  34. <column name="yipee" type="INTEGER" />
  35. </table>
  36. </database>
  37. EOF;
  38. $schema2 = <<<EOF
  39. <database name="test">
  40. <table name="foo2">
  41. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  42. <column name="bar1" type="INTEGER" />
  43. <column name="baz" type="VARCHAR" size="12" required="false" />
  44. <column name="baz3" type="LONGVARCHAR" />
  45. </table>
  46. <table name="foo4">
  47. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  48. <column name="yipee" type="INTEGER" />
  49. </table>
  50. <table name="foo5">
  51. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  52. <column name="lkdjfsh" type="INTEGER" />
  53. <column name="dfgdsgf" type="LONGVARCHAR" />
  54. </table>
  55. </database>
  56. EOF;
  57. $d1 = $this->getDatabaseFromSchema($schema1);
  58. $d2 = $this->getDatabaseFromSchema($schema2);
  59. return array(array(PropelDatabaseComparator::computeDiff($d1, $d2)));
  60. }
  61. public function providerForTestGetRenameTableDDL()
  62. {
  63. return array(array('foo1', 'foo2'));
  64. }
  65. public function providerForTestGetModifyTableDDL()
  66. {
  67. $schema1 = <<<EOF
  68. <database name="test">
  69. <table name="foo">
  70. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  71. <column name="bar" type="INTEGER" />
  72. <column name="baz" type="VARCHAR" size="12" required="true" />
  73. <foreign-key name="foo1_FK_1" foreignTable="foo2">
  74. <reference local="bar" foreign="bar" />
  75. </foreign-key>
  76. <foreign-key name="foo1_FK_2" foreignTable="foo2">
  77. <reference local="baz" foreign="baz" />
  78. </foreign-key>
  79. <index name="bar_FK">
  80. <index-column name="bar"/>
  81. </index>
  82. <index name="bar_baz_FK">
  83. <index-column name="bar"/>
  84. <index-column name="baz"/>
  85. </index>
  86. </table>
  87. <table name="foo2">
  88. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  89. <column name="bar" type="INTEGER" />
  90. <column name="baz" type="VARCHAR" size="12" required="true" />
  91. </table>
  92. </database>
  93. EOF;
  94. $schema2 = <<<EOF
  95. <database name="test">
  96. <table name="foo">
  97. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  98. <column name="bar1" type="INTEGER" />
  99. <column name="baz" type="VARCHAR" size="12" required="false" />
  100. <column name="baz3" type="LONGVARCHAR" />
  101. <foreign-key name="foo1_FK_1" foreignTable="foo2">
  102. <reference local="bar1" foreign="bar" />
  103. </foreign-key>
  104. <index name="bar_FK">
  105. <index-column name="bar1"/>
  106. </index>
  107. <index name="baz_FK">
  108. <index-column name="baz3"/>
  109. </index>
  110. </table>
  111. <table name="foo2">
  112. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  113. <column name="bar" type="INTEGER" />
  114. <column name="baz" type="VARCHAR" size="12" required="true" />
  115. </table>
  116. </database>
  117. EOF;
  118. $t1 = $this->getDatabaseFromSchema($schema1)->getTable('foo');
  119. $t2 = $this->getDatabaseFromSchema($schema2)->getTable('foo');
  120. return array(array(PropelTableComparator::computeDiff($t1,$t2)));
  121. }
  122. public function providerForTestGetModifyTableColumnsDDL()
  123. {
  124. $schema1 = <<<EOF
  125. <database name="test">
  126. <table name="foo">
  127. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  128. <column name="bar" type="INTEGER" />
  129. <column name="baz" type="VARCHAR" size="12" required="true" />
  130. </table>
  131. </database>
  132. EOF;
  133. $schema2 = <<<EOF
  134. <database name="test">
  135. <table name="foo">
  136. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  137. <column name="bar1" type="INTEGER" />
  138. <column name="baz" type="VARCHAR" size="12" required="false" />
  139. <column name="baz3" type="LONGVARCHAR" />
  140. </table>
  141. </database>
  142. EOF;
  143. $t1 = $this->getDatabaseFromSchema($schema1)->getTable('foo');
  144. $t2 = $this->getDatabaseFromSchema($schema2)->getTable('foo');
  145. $tc = new PropelTableComparator();
  146. $tc->setFromTable($t1);
  147. $tc->setToTable($t2);
  148. $tc->compareColumns();
  149. return array(array($tc->getTableDiff()));
  150. }
  151. public function providerForTestGetModifyTablePrimaryKeysDDL()
  152. {
  153. $schema1 = <<<EOF
  154. <database name="test">
  155. <table name="foo">
  156. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  157. <column name="bar" type="INTEGER" />
  158. <column name="baz" type="VARCHAR" size="12" required="true" />
  159. </table>
  160. </database>
  161. EOF;
  162. $schema2 = <<<EOF
  163. <database name="test">
  164. <table name="foo">
  165. <column name="id" primaryKey="true" type="INTEGER" />
  166. <column name="bar" type="INTEGER" primaryKey="true" />
  167. <column name="baz" type="VARCHAR" size="12" required="false" />
  168. </table>
  169. </database>
  170. EOF;
  171. $t1 = $this->getDatabaseFromSchema($schema1)->getTable('foo');
  172. $t2 = $this->getDatabaseFromSchema($schema2)->getTable('foo');
  173. $tc = new PropelTableComparator();
  174. $tc->setFromTable($t1);
  175. $tc->setToTable($t2);
  176. $tc->comparePrimaryKeys();
  177. return array(array($tc->getTableDiff()));
  178. }
  179. public function providerForTestGetModifyTableIndicesDDL()
  180. {
  181. $schema1 = <<<EOF
  182. <database name="test">
  183. <table name="foo">
  184. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  185. <column name="bar" type="INTEGER" />
  186. <column name="baz" type="VARCHAR" size="12" required="true" />
  187. <index name="bar_FK">
  188. <index-column name="bar"/>
  189. </index>
  190. <index name="bar_baz_FK">
  191. <index-column name="bar"/>
  192. <index-column name="baz"/>
  193. </index>
  194. </table>
  195. </database>
  196. EOF;
  197. $schema2 = <<<EOF
  198. <database name="test">
  199. <table name="foo">
  200. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  201. <column name="bar" type="INTEGER" />
  202. <column name="baz" type="VARCHAR" size="12" required="true" />
  203. <index name="bar_baz_FK">
  204. <index-column name="id"/>
  205. <index-column name="bar"/>
  206. <index-column name="baz"/>
  207. </index>
  208. <index name="baz_FK">
  209. <index-column name="baz"/>
  210. </index>
  211. </table>
  212. </database>
  213. EOF;
  214. $t1 = $this->getDatabaseFromSchema($schema1)->getTable('foo');
  215. $t2 = $this->getDatabaseFromSchema($schema2)->getTable('foo');
  216. $tc = new PropelTableComparator();
  217. $tc->setFromTable($t1);
  218. $tc->setToTable($t2);
  219. $tc->compareIndices();
  220. return array(array($tc->getTableDiff()));
  221. }
  222. public function providerForTestGetModifyTableForeignKeysDDL()
  223. {
  224. $schema1 = <<<EOF
  225. <database name="test">
  226. <table name="foo1">
  227. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  228. <column name="bar" type="INTEGER" />
  229. <column name="baz" type="VARCHAR" size="12" required="true" />
  230. <foreign-key name="foo1_FK_1" foreignTable="foo2">
  231. <reference local="bar" foreign="bar" />
  232. </foreign-key>
  233. <foreign-key name="foo1_FK_2" foreignTable="foo2">
  234. <reference local="bar" foreign="bar" />
  235. <reference local="baz" foreign="baz" />
  236. </foreign-key>
  237. </table>
  238. <table name="foo2">
  239. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  240. <column name="bar" type="INTEGER" />
  241. <column name="baz" type="VARCHAR" size="12" required="true" />
  242. </table>
  243. </database>
  244. EOF;
  245. $schema2 = <<<EOF
  246. <database name="test">
  247. <table name="foo1">
  248. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  249. <column name="bar" type="INTEGER" />
  250. <column name="baz" type="VARCHAR" size="12" required="true" />
  251. <foreign-key name="foo1_FK_2" foreignTable="foo2">
  252. <reference local="bar" foreign="bar" />
  253. <reference local="id" foreign="id" />
  254. </foreign-key>
  255. <foreign-key name="foo1_FK_3" foreignTable="foo2">
  256. <reference local="baz" foreign="baz" />
  257. </foreign-key>
  258. </table>
  259. <table name="foo2">
  260. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  261. <column name="bar" type="INTEGER" />
  262. <column name="baz" type="VARCHAR" size="12" required="true" />
  263. </table>
  264. </database>
  265. EOF;
  266. $t1 = $this->getDatabaseFromSchema($schema1)->getTable('foo1');
  267. $t2 = $this->getDatabaseFromSchema($schema2)->getTable('foo1');
  268. $tc = new PropelTableComparator();
  269. $tc->setFromTable($t1);
  270. $tc->setToTable($t2);
  271. $tc->compareForeignKeys();
  272. return array(array($tc->getTableDiff()));
  273. }
  274. public function providerForTestGetModifyTableForeignKeysSkipSqlDDL()
  275. {
  276. $schema1 = <<<EOF
  277. <database name="test">
  278. <table name="foo1">
  279. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  280. <column name="bar" type="INTEGER" />
  281. <foreign-key name="foo1_FK_1" foreignTable="foo2">
  282. <reference local="bar" foreign="bar" />
  283. </foreign-key>
  284. </table>
  285. <table name="foo2">
  286. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  287. <column name="bar" type="INTEGER" />
  288. </table>
  289. </database>
  290. EOF;
  291. $schema2 = <<<EOF
  292. <database name="test">
  293. <table name="foo1">
  294. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  295. <column name="bar" type="INTEGER" />
  296. <foreign-key name="foo1_FK_1" foreignTable="foo2" skipSql="true">
  297. <reference local="bar" foreign="bar" />
  298. </foreign-key>
  299. </table>
  300. <table name="foo2">
  301. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  302. <column name="bar" type="INTEGER" />
  303. </table>
  304. </database>
  305. EOF;
  306. $t1 = $this->getDatabaseFromSchema($schema1)->getTable('foo1');
  307. $t2 = $this->getDatabaseFromSchema($schema2)->getTable('foo1');
  308. $tc = new PropelTableComparator();
  309. $tc->setFromTable($t1);
  310. $tc->setToTable($t2);
  311. $tc->compareForeignKeys();
  312. return array(array($tc->getTableDiff()));
  313. }
  314. public function providerForTestGetModifyTableForeignKeysSkipSql2DDL()
  315. {
  316. $schema1 = <<<EOF
  317. <database name="test">
  318. <table name="foo1">
  319. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  320. <column name="bar" type="INTEGER" />
  321. <foreign-key name="foo1_FK_1" foreignTable="foo2" skipSql="true">
  322. <reference local="bar" foreign="bar" />
  323. </foreign-key>
  324. </table>
  325. <table name="foo2">
  326. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  327. <column name="bar" type="INTEGER" />
  328. </table>
  329. </database>
  330. EOF;
  331. $schema2 = <<<EOF
  332. <database name="test">
  333. <table name="foo1">
  334. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  335. <column name="bar" type="INTEGER" />
  336. </table>
  337. <table name="foo2">
  338. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  339. <column name="bar" type="INTEGER" />
  340. </table>
  341. </database>
  342. EOF;
  343. $t1 = $this->getDatabaseFromSchema($schema1)->getTable('foo1');
  344. $t2 = $this->getDatabaseFromSchema($schema2)->getTable('foo1');
  345. $tc = new PropelTableComparator();
  346. $tc->setFromTable($t1);
  347. $tc->setToTable($t2);
  348. $tc->compareForeignKeys();
  349. return array(array($tc->getTableDiff()));
  350. }
  351. public function providerForTestGetRemoveColumnDDL()
  352. {
  353. $table = new Table('foo');
  354. $column = new Column('bar');
  355. $table->addColumn($column);
  356. return array(array($column));
  357. }
  358. public function providerForTestGetRenameColumnDDL()
  359. {
  360. $t1 = new Table('foo');
  361. $c1 = new Column('bar1');
  362. $c1->getDomain()->setType('DOUBLE');
  363. $c1->getDomain()->setSqlType('DOUBLE');
  364. $c1->getDomain()->replaceSize(2);
  365. $t1->addColumn($c1);
  366. $t2 = new Table('foo');
  367. $c2 = new Column('bar2');
  368. $c2->getDomain()->setType('DOUBLE');
  369. $c2->getDomain()->setSqlType('DOUBLE');
  370. $c2->getDomain()->replaceSize(2);
  371. $t2->addColumn($c2);
  372. return array(array($c1, $c2));
  373. }
  374. public function providerForTestGetModifyColumnDDL()
  375. {
  376. $t1 = new Table('foo');
  377. $c1 = new Column('bar');
  378. $c1->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
  379. $c1->getDomain()->replaceSize(2);
  380. $t1->addColumn($c1);
  381. $t2 = new Table('foo');
  382. $c2 = new Column('bar');
  383. $c2->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
  384. $c2->getDomain()->replaceSize(3);
  385. $t2->addColumn($c2);
  386. return array(array(PropelColumnComparator::computeDiff($c1, $c2)));
  387. }
  388. public function providerForTestGetModifyColumnsDDL()
  389. {
  390. $t1 = new Table('foo');
  391. $c1 = new Column('bar1');
  392. $c1->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
  393. $c1->getDomain()->replaceSize(2);
  394. $t1->addColumn($c1);
  395. $c2 = new Column('bar2');
  396. $c2->getDomain()->setType('INTEGER');
  397. $c2->getDomain()->setSqlType('INTEGER');
  398. $t1->addColumn($c2);
  399. $t2 = new Table('foo');
  400. $c3 = new Column('bar1');
  401. $c3->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
  402. $c3->getDomain()->replaceSize(3);
  403. $t2->addColumn($c3);
  404. $c4 = new Column('bar2');
  405. $c4->getDomain()->setType('INTEGER');
  406. $c4->getDomain()->setSqlType('INTEGER');
  407. $c4->setNotNull(true);
  408. $t2->addColumn($c4);
  409. return array(array(array(
  410. PropelColumnComparator::computeDiff($c1, $c3),
  411. PropelColumnComparator::computeDiff($c2, $c4)
  412. )));
  413. }
  414. public function providerForTestGetAddColumnDDL()
  415. {
  416. $schema = <<<EOF
  417. <database name="test">
  418. <table name="foo">
  419. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  420. <column name="bar" type="INTEGER" />
  421. </table>
  422. </database>
  423. EOF;
  424. $column = $this->getDatabaseFromSchema($schema)->getTable('foo')->getColumn('bar');
  425. return array(array($column));
  426. }
  427. public function providerForTestGetAddColumnsDDL()
  428. {
  429. $schema = <<<EOF
  430. <database name="test">
  431. <table name="foo">
  432. <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
  433. <column name="bar1" type="INTEGER" />
  434. <column name="bar2" type="DOUBLE" scale="2" size="3" default="-1" required="true" />
  435. </table>
  436. </database>
  437. EOF;
  438. $table = $this->getDatabaseFromSchema($schema)->getTable('foo');
  439. return array(array(array($table->getColumn('bar1'), $table->getColumn('bar2'))));
  440. }
  441. public function providerForTestGetModifyColumnRemoveDefaultValueDDL()
  442. {
  443. $t1 = new Table('test');
  444. $c1 = new Column();
  445. $c1->setName('test');
  446. $c1->getDomain()->setType('INTEGER');
  447. $c1->setDefaultValue(0);
  448. $t1->addColumn($c1);
  449. $t2 = new Table('test');
  450. $c2 = new Column();
  451. $c2->setName('test');
  452. $c2->getDomain()->setType('INTEGER');
  453. $t2->addColumn($c2);
  454. return array(array(PropelColumnComparator::computeDiff($c1, $c2)));
  455. }
  456. public function providerForTestGetModifyTableForeignKeysSkipSql3DDL()
  457. {
  458. $schema1 = <<<EOF
  459. <database name="test">
  460. <table name="test">
  461. <column name="test" type="INTEGER" primaryKey="true" autoIncrement="true" required="true" />
  462. <column name="ref_test" type="INTEGER"/>
  463. <foreign-key foreignTable="test2" onDelete="CASCADE" onUpdate="CASCADE" skipSql="true">
  464. <reference local="ref_test" foreign="test" />
  465. </foreign-key>
  466. </table>
  467. <table name="test2">
  468. <column name="test" type="integer" primaryKey="true" />
  469. </table>
  470. </database>
  471. EOF;
  472. $schema2 = <<<EOF
  473. <database name="test">
  474. <table name="test">
  475. <column name="test" type="INTEGER" primaryKey="true" autoIncrement="true" required="true" />
  476. <column name="ref_test" type="INTEGER"/>
  477. </table>
  478. <table name="test2">
  479. <column name="test" type="integer" primaryKey="true" />
  480. </table>
  481. </database>
  482. EOF;
  483. $d1 = $this->getDatabaseFromSchema($schema1);
  484. $d2 = $this->getDatabaseFromSchema($schema2);
  485. $diff = PropelDatabaseComparator::computeDiff($d1, $d2);
  486. return array(array($diff));
  487. }
  488. public function providerForTestGetModifyTableForeignKeysSkipSql4DDL()
  489. {
  490. $schema1 = <<<EOF
  491. <database name="test">
  492. <table name="test">
  493. <column name="test" type="INTEGER" primaryKey="true" autoIncrement="true" required="true" />
  494. <column name="ref_test" type="INTEGER"/>
  495. <foreign-key foreignTable="test2" onDelete="CASCADE" onUpdate="CASCADE" skipSql="true">
  496. <reference local="ref_test" foreign="test" />
  497. </foreign-key>
  498. </table>
  499. <table name="test2">
  500. <column name="test" type="integer" primaryKey="true" />
  501. </table>
  502. </database>
  503. EOF;
  504. $schema2 = <<<EOF
  505. <database name="test">
  506. <table name="test">
  507. <column name="test" type="INTEGER" primaryKey="true" autoIncrement="true" required="true" />
  508. <column name="ref_test" type="INTEGER"/>
  509. </table>
  510. <table name="test2">
  511. <column name="test" type="integer" primaryKey="true" />
  512. </table>
  513. </database>
  514. EOF;
  515. $d1 = $this->getDatabaseFromSchema($schema1);
  516. $d2 = $this->getDatabaseFromSchema($schema2);
  517. $diff = PropelDatabaseComparator::computeDiff($d2, $d1);
  518. return array(array($diff));
  519. }
  520. }