You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MigrationsTest.php 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <?php
  2. /**
  3. * Copyright (c) 2016 Thomas Müller <thomas.mueller@tmit.eu>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace Test\DB;
  9. use Doctrine\DBAL\Platforms\OraclePlatform;
  10. use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
  11. use Doctrine\DBAL\Schema\Column;
  12. use Doctrine\DBAL\Schema\ForeignKeyConstraint;
  13. use Doctrine\DBAL\Schema\Index;
  14. use Doctrine\DBAL\Schema\Schema;
  15. use Doctrine\DBAL\Schema\SchemaException;
  16. use Doctrine\DBAL\Schema\Sequence;
  17. use Doctrine\DBAL\Schema\Table;
  18. use Doctrine\DBAL\Types\Type;
  19. use OC\DB\Connection;
  20. use OC\DB\MigrationService;
  21. use OC\DB\SchemaWrapper;
  22. use OCP\IDBConnection;
  23. use OCP\Migration\IMigrationStep;
  24. /**
  25. * Class MigrationsTest
  26. *
  27. * @package Test\DB
  28. */
  29. class MigrationsTest extends \Test\TestCase {
  30. /** @var MigrationService | \PHPUnit\Framework\MockObject\MockObject */
  31. private $migrationService;
  32. /** @var \PHPUnit\Framework\MockObject\MockObject | IDBConnection $db */
  33. private $db;
  34. protected function setUp(): void {
  35. parent::setUp();
  36. $this->db = $this->createMock(Connection::class);
  37. $this->db->expects($this->any())->method('getPrefix')->willReturn('test_oc_');
  38. $this->migrationService = new MigrationService('testing', $this->db);
  39. }
  40. public function testGetters() {
  41. $this->assertEquals('testing', $this->migrationService->getApp());
  42. $this->assertEquals(\OC::$SERVERROOT . '/apps/testing/lib/Migration', $this->migrationService->getMigrationsDirectory());
  43. $this->assertEquals('OCA\Testing\Migration', $this->migrationService->getMigrationsNamespace());
  44. $this->assertEquals('test_oc_migrations', $this->migrationService->getMigrationsTableName());
  45. }
  46. public function testCore() {
  47. $this->migrationService = new MigrationService('core', $this->db);
  48. $this->assertEquals('core', $this->migrationService->getApp());
  49. $this->assertEquals(\OC::$SERVERROOT . '/core/Migrations', $this->migrationService->getMigrationsDirectory());
  50. $this->assertEquals('OC\Core\Migrations', $this->migrationService->getMigrationsNamespace());
  51. $this->assertEquals('test_oc_migrations', $this->migrationService->getMigrationsTableName());
  52. }
  53. public function testExecuteUnknownStep() {
  54. $this->expectException(\InvalidArgumentException::class);
  55. $this->expectExceptionMessage('Version 20170130180000 is unknown.');
  56. $this->migrationService->executeStep('20170130180000');
  57. }
  58. public function testUnknownApp() {
  59. $this->expectException(\Exception::class);
  60. $this->expectExceptionMessage('App not found');
  61. $migrationService = new MigrationService('unknown-bloody-app', $this->db);
  62. }
  63. public function testExecuteStepWithUnknownClass() {
  64. $this->expectException(\Exception::class);
  65. $this->expectExceptionMessage('Migration step \'X\' is unknown');
  66. $this->migrationService = $this->getMockBuilder(MigrationService::class)
  67. ->setMethods(['findMigrations'])
  68. ->setConstructorArgs(['testing', $this->db])
  69. ->getMock();
  70. $this->migrationService->expects($this->any())->method('findMigrations')->willReturn(
  71. ['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A']
  72. );
  73. $this->migrationService->executeStep('20170130180000');
  74. }
  75. public function testExecuteStepWithSchemaChange() {
  76. $schema = $this->createMock(Schema::class);
  77. $this->db->expects($this->any())
  78. ->method('createSchema')
  79. ->willReturn($schema);
  80. $this->db->expects($this->once())
  81. ->method('migrateToSchema');
  82. $wrappedSchema = $this->createMock(Schema::class);
  83. $wrappedSchema->expects($this->once())
  84. ->method('getTables')
  85. ->willReturn([]);
  86. $wrappedSchema->expects($this->once())
  87. ->method('getSequences')
  88. ->willReturn([]);
  89. $schemaResult = $this->createMock(SchemaWrapper::class);
  90. $schemaResult->expects($this->once())
  91. ->method('getWrappedSchema')
  92. ->willReturn($wrappedSchema);
  93. $step = $this->createMock(IMigrationStep::class);
  94. $step->expects($this->at(0))
  95. ->method('preSchemaChange');
  96. $step->expects($this->at(1))
  97. ->method('changeSchema')
  98. ->willReturn($schemaResult);
  99. $step->expects($this->at(2))
  100. ->method('postSchemaChange');
  101. $this->migrationService = $this->getMockBuilder(MigrationService::class)
  102. ->setMethods(['createInstance'])
  103. ->setConstructorArgs(['testing', $this->db])
  104. ->getMock();
  105. $this->migrationService->expects($this->any())
  106. ->method('createInstance')
  107. ->with('20170130180000')
  108. ->willReturn($step);
  109. $this->migrationService->executeStep('20170130180000');
  110. }
  111. public function testExecuteStepWithoutSchemaChange() {
  112. $schema = $this->createMock(Schema::class);
  113. $this->db->expects($this->any())
  114. ->method('createSchema')
  115. ->willReturn($schema);
  116. $this->db->expects($this->never())
  117. ->method('migrateToSchema');
  118. $step = $this->createMock(IMigrationStep::class);
  119. $step->expects($this->at(0))
  120. ->method('preSchemaChange');
  121. $step->expects($this->at(1))
  122. ->method('changeSchema')
  123. ->willReturn(null);
  124. $step->expects($this->at(2))
  125. ->method('postSchemaChange');
  126. $this->migrationService = $this->getMockBuilder(MigrationService::class)
  127. ->setMethods(['createInstance'])
  128. ->setConstructorArgs(['testing', $this->db])
  129. ->getMock();
  130. $this->migrationService->expects($this->any())
  131. ->method('createInstance')
  132. ->with('20170130180000')
  133. ->willReturn($step);
  134. $this->migrationService->executeStep('20170130180000');
  135. }
  136. public function dataGetMigration() {
  137. return [
  138. ['current', '20170130180001'],
  139. ['prev', '20170130180000'],
  140. ['next', '20170130180002'],
  141. ['latest', '20170130180003'],
  142. ];
  143. }
  144. /**
  145. * @dataProvider dataGetMigration
  146. * @param string $alias
  147. * @param string $expected
  148. */
  149. public function testGetMigration($alias, $expected) {
  150. $this->migrationService = $this->getMockBuilder(MigrationService::class)
  151. ->setMethods(['getMigratedVersions', 'findMigrations'])
  152. ->setConstructorArgs(['testing', $this->db])
  153. ->getMock();
  154. $this->migrationService->expects($this->any())->method('getMigratedVersions')->willReturn(
  155. ['20170130180000', '20170130180001']
  156. );
  157. $this->migrationService->expects($this->any())->method('findMigrations')->willReturn(
  158. ['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A']
  159. );
  160. $this->assertEquals(
  161. ['20170130180000', '20170130180001', '20170130180002', '20170130180003'],
  162. $this->migrationService->getAvailableVersions());
  163. $migration = $this->migrationService->getMigration($alias);
  164. $this->assertEquals($expected, $migration);
  165. }
  166. public function testMigrate() {
  167. $this->migrationService = $this->getMockBuilder(MigrationService::class)
  168. ->setMethods(['getMigratedVersions', 'findMigrations', 'executeStep'])
  169. ->setConstructorArgs(['testing', $this->db])
  170. ->getMock();
  171. $this->migrationService->expects($this->any())->method('getMigratedVersions')->willReturn(
  172. ['20170130180000', '20170130180001']
  173. );
  174. $this->migrationService->expects($this->any())->method('findMigrations')->willReturn(
  175. ['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A']
  176. );
  177. $this->assertEquals(
  178. ['20170130180000', '20170130180001', '20170130180002', '20170130180003'],
  179. $this->migrationService->getAvailableVersions());
  180. $this->migrationService->expects($this->exactly(2))->method('executeStep')
  181. ->withConsecutive(['20170130180002'], ['20170130180003']);
  182. $this->migrationService->migrate();
  183. }
  184. public function testEnsureOracleConstraintsValid() {
  185. $column = $this->createMock(Column::class);
  186. $column->expects($this->once())
  187. ->method('getName')
  188. ->willReturn(\str_repeat('a', 30));
  189. $index = $this->createMock(Index::class);
  190. $index->expects($this->once())
  191. ->method('getName')
  192. ->willReturn(\str_repeat('a', 30));
  193. $foreignKey = $this->createMock(ForeignKeyConstraint::class);
  194. $foreignKey->expects($this->once())
  195. ->method('getName')
  196. ->willReturn(\str_repeat('a', 30));
  197. $table = $this->createMock(Table::class);
  198. $table->expects($this->atLeastOnce())
  199. ->method('getName')
  200. ->willReturn(\str_repeat('a', 30));
  201. $sequence = $this->createMock(Sequence::class);
  202. $sequence->expects($this->atLeastOnce())
  203. ->method('getName')
  204. ->willReturn(\str_repeat('a', 30));
  205. $table->expects($this->once())
  206. ->method('getColumns')
  207. ->willReturn([$column]);
  208. $table->expects($this->once())
  209. ->method('getIndexes')
  210. ->willReturn([$index]);
  211. $table->expects($this->once())
  212. ->method('getForeignKeys')
  213. ->willReturn([$foreignKey]);
  214. $table->expects($this->once())
  215. ->method('getPrimaryKey')
  216. ->willReturn(null);
  217. $schema = $this->createMock(Schema::class);
  218. $schema->expects($this->once())
  219. ->method('getTables')
  220. ->willReturn([$table]);
  221. $schema->expects($this->once())
  222. ->method('getSequences')
  223. ->willReturn([$sequence]);
  224. $sourceSchema = $this->createMock(Schema::class);
  225. $sourceSchema->expects($this->any())
  226. ->method('getTable')
  227. ->willThrowException(new SchemaException());
  228. $sourceSchema->expects($this->any())
  229. ->method('hasSequence')
  230. ->willReturn(false);
  231. self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
  232. }
  233. public function testEnsureOracleConstraintsValidWithPrimaryKey() {
  234. $index = $this->createMock(Index::class);
  235. $index->expects($this->any())
  236. ->method('getName')
  237. ->willReturn(\str_repeat('a', 30));
  238. $table = $this->createMock(Table::class);
  239. $table->expects($this->any())
  240. ->method('getName')
  241. ->willReturn(\str_repeat('a', 26));
  242. $table->expects($this->once())
  243. ->method('getColumns')
  244. ->willReturn([]);
  245. $table->expects($this->once())
  246. ->method('getIndexes')
  247. ->willReturn([]);
  248. $table->expects($this->once())
  249. ->method('getForeignKeys')
  250. ->willReturn([]);
  251. $table->expects($this->once())
  252. ->method('getPrimaryKey')
  253. ->willReturn($index);
  254. $schema = $this->createMock(Schema::class);
  255. $schema->expects($this->once())
  256. ->method('getTables')
  257. ->willReturn([$table]);
  258. $schema->expects($this->once())
  259. ->method('getSequences')
  260. ->willReturn([]);
  261. $sourceSchema = $this->createMock(Schema::class);
  262. $sourceSchema->expects($this->any())
  263. ->method('getTable')
  264. ->willThrowException(new SchemaException());
  265. $sourceSchema->expects($this->any())
  266. ->method('hasSequence')
  267. ->willReturn(false);
  268. self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
  269. }
  270. public function testEnsureOracleConstraintsValidWithPrimaryKeyDefault() {
  271. $defaultName = 'PRIMARY';
  272. if ($this->db->getDatabasePlatform() instanceof PostgreSqlPlatform) {
  273. $defaultName = \str_repeat('a', 26) . '_' . \str_repeat('b', 30) . '_seq';
  274. } elseif ($this->db->getDatabasePlatform() instanceof OraclePlatform) {
  275. $defaultName = \str_repeat('a', 26) . '_seq';
  276. }
  277. $index = $this->createMock(Index::class);
  278. $index->expects($this->any())
  279. ->method('getName')
  280. ->willReturn($defaultName);
  281. $index->expects($this->any())
  282. ->method('getColumns')
  283. ->willReturn([\str_repeat('b', 30)]);
  284. $table = $this->createMock(Table::class);
  285. $table->expects($this->any())
  286. ->method('getName')
  287. ->willReturn(\str_repeat('a', 25));
  288. $table->expects($this->once())
  289. ->method('getColumns')
  290. ->willReturn([]);
  291. $table->expects($this->once())
  292. ->method('getIndexes')
  293. ->willReturn([]);
  294. $table->expects($this->once())
  295. ->method('getForeignKeys')
  296. ->willReturn([]);
  297. $table->expects($this->once())
  298. ->method('getPrimaryKey')
  299. ->willReturn($index);
  300. $schema = $this->createMock(Schema::class);
  301. $schema->expects($this->once())
  302. ->method('getTables')
  303. ->willReturn([$table]);
  304. $schema->expects($this->once())
  305. ->method('getSequences')
  306. ->willReturn([]);
  307. $sourceSchema = $this->createMock(Schema::class);
  308. $sourceSchema->expects($this->any())
  309. ->method('getTable')
  310. ->willThrowException(new SchemaException());
  311. $sourceSchema->expects($this->any())
  312. ->method('hasSequence')
  313. ->willReturn(false);
  314. self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
  315. }
  316. public function testEnsureOracleConstraintsTooLongTableName() {
  317. $this->expectException(\InvalidArgumentException::class);
  318. $table = $this->createMock(Table::class);
  319. $table->expects($this->any())
  320. ->method('getName')
  321. ->willReturn(\str_repeat('a', 31));
  322. $schema = $this->createMock(Schema::class);
  323. $schema->expects($this->once())
  324. ->method('getTables')
  325. ->willReturn([$table]);
  326. $sourceSchema = $this->createMock(Schema::class);
  327. $sourceSchema->expects($this->any())
  328. ->method('getTable')
  329. ->willThrowException(new SchemaException());
  330. $sourceSchema->expects($this->any())
  331. ->method('hasSequence')
  332. ->willReturn(false);
  333. self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
  334. }
  335. public function testEnsureOracleConstraintsTooLongPrimaryWithDefault() {
  336. $this->expectException(\InvalidArgumentException::class);
  337. $defaultName = 'PRIMARY';
  338. if ($this->db->getDatabasePlatform() instanceof PostgreSqlPlatform) {
  339. $defaultName = \str_repeat('a', 27) . '_' . \str_repeat('b', 30) . '_seq';
  340. } elseif ($this->db->getDatabasePlatform() instanceof OraclePlatform) {
  341. $defaultName = \str_repeat('a', 27) . '_seq';
  342. }
  343. $index = $this->createMock(Index::class);
  344. $index->expects($this->any())
  345. ->method('getName')
  346. ->willReturn($defaultName);
  347. $index->expects($this->any())
  348. ->method('getColumns')
  349. ->willReturn([\str_repeat('b', 30)]);
  350. $table = $this->createMock(Table::class);
  351. $table->expects($this->any())
  352. ->method('getName')
  353. ->willReturn(\str_repeat('a', 27));
  354. $table->expects($this->once())
  355. ->method('getColumns')
  356. ->willReturn([]);
  357. $table->expects($this->once())
  358. ->method('getIndexes')
  359. ->willReturn([]);
  360. $table->expects($this->once())
  361. ->method('getForeignKeys')
  362. ->willReturn([]);
  363. $table->expects($this->once())
  364. ->method('getPrimaryKey')
  365. ->willReturn($index);
  366. $schema = $this->createMock(Schema::class);
  367. $schema->expects($this->once())
  368. ->method('getTables')
  369. ->willReturn([$table]);
  370. $sourceSchema = $this->createMock(Schema::class);
  371. $sourceSchema->expects($this->any())
  372. ->method('getTable')
  373. ->willThrowException(new SchemaException());
  374. $sourceSchema->expects($this->any())
  375. ->method('hasSequence')
  376. ->willReturn(false);
  377. self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
  378. }
  379. public function testEnsureOracleConstraintsTooLongPrimaryWithName() {
  380. $this->expectException(\InvalidArgumentException::class);
  381. $index = $this->createMock(Index::class);
  382. $index->expects($this->any())
  383. ->method('getName')
  384. ->willReturn(\str_repeat('a', 31));
  385. $table = $this->createMock(Table::class);
  386. $table->expects($this->any())
  387. ->method('getName')
  388. ->willReturn(\str_repeat('a', 26));
  389. $table->expects($this->once())
  390. ->method('getColumns')
  391. ->willReturn([]);
  392. $table->expects($this->once())
  393. ->method('getIndexes')
  394. ->willReturn([]);
  395. $table->expects($this->once())
  396. ->method('getForeignKeys')
  397. ->willReturn([]);
  398. $table->expects($this->once())
  399. ->method('getPrimaryKey')
  400. ->willReturn($index);
  401. $schema = $this->createMock(Schema::class);
  402. $schema->expects($this->once())
  403. ->method('getTables')
  404. ->willReturn([$table]);
  405. $sourceSchema = $this->createMock(Schema::class);
  406. $sourceSchema->expects($this->any())
  407. ->method('getTable')
  408. ->willThrowException(new SchemaException());
  409. $sourceSchema->expects($this->any())
  410. ->method('hasSequence')
  411. ->willReturn(false);
  412. self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
  413. }
  414. public function testEnsureOracleConstraintsTooLongColumnName() {
  415. $this->expectException(\InvalidArgumentException::class);
  416. $column = $this->createMock(Column::class);
  417. $column->expects($this->any())
  418. ->method('getName')
  419. ->willReturn(\str_repeat('a', 31));
  420. $table = $this->createMock(Table::class);
  421. $table->expects($this->any())
  422. ->method('getName')
  423. ->willReturn(\str_repeat('a', 30));
  424. $table->expects($this->once())
  425. ->method('getColumns')
  426. ->willReturn([$column]);
  427. $schema = $this->createMock(Schema::class);
  428. $schema->expects($this->once())
  429. ->method('getTables')
  430. ->willReturn([$table]);
  431. $sourceSchema = $this->createMock(Schema::class);
  432. $sourceSchema->expects($this->any())
  433. ->method('getTable')
  434. ->willThrowException(new SchemaException());
  435. $sourceSchema->expects($this->any())
  436. ->method('hasSequence')
  437. ->willReturn(false);
  438. self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
  439. }
  440. public function testEnsureOracleConstraintsTooLongIndexName() {
  441. $this->expectException(\InvalidArgumentException::class);
  442. $index = $this->createMock(Index::class);
  443. $index->expects($this->any())
  444. ->method('getName')
  445. ->willReturn(\str_repeat('a', 31));
  446. $table = $this->createMock(Table::class);
  447. $table->expects($this->any())
  448. ->method('getName')
  449. ->willReturn(\str_repeat('a', 30));
  450. $table->expects($this->once())
  451. ->method('getColumns')
  452. ->willReturn([]);
  453. $table->expects($this->once())
  454. ->method('getIndexes')
  455. ->willReturn([$index]);
  456. $schema = $this->createMock(Schema::class);
  457. $schema->expects($this->once())
  458. ->method('getTables')
  459. ->willReturn([$table]);
  460. $sourceSchema = $this->createMock(Schema::class);
  461. $sourceSchema->expects($this->any())
  462. ->method('getTable')
  463. ->willThrowException(new SchemaException());
  464. $sourceSchema->expects($this->any())
  465. ->method('hasSequence')
  466. ->willReturn(false);
  467. self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
  468. }
  469. public function testEnsureOracleConstraintsTooLongForeignKeyName() {
  470. $this->expectException(\InvalidArgumentException::class);
  471. $foreignKey = $this->createMock(ForeignKeyConstraint::class);
  472. $foreignKey->expects($this->any())
  473. ->method('getName')
  474. ->willReturn(\str_repeat('a', 31));
  475. $table = $this->createMock(Table::class);
  476. $table->expects($this->any())
  477. ->method('getName')
  478. ->willReturn(\str_repeat('a', 30));
  479. $table->expects($this->once())
  480. ->method('getColumns')
  481. ->willReturn([]);
  482. $table->expects($this->once())
  483. ->method('getIndexes')
  484. ->willReturn([]);
  485. $table->expects($this->once())
  486. ->method('getForeignKeys')
  487. ->willReturn([$foreignKey]);
  488. $schema = $this->createMock(Schema::class);
  489. $schema->expects($this->once())
  490. ->method('getTables')
  491. ->willReturn([$table]);
  492. $sourceSchema = $this->createMock(Schema::class);
  493. $sourceSchema->expects($this->any())
  494. ->method('getTable')
  495. ->willThrowException(new SchemaException());
  496. $sourceSchema->expects($this->any())
  497. ->method('hasSequence')
  498. ->willReturn(false);
  499. self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
  500. }
  501. public function testEnsureOracleConstraintsTooLongSequenceName() {
  502. $this->expectException(\InvalidArgumentException::class);
  503. $sequence = $this->createMock(Sequence::class);
  504. $sequence->expects($this->any())
  505. ->method('getName')
  506. ->willReturn(\str_repeat('a', 31));
  507. $schema = $this->createMock(Schema::class);
  508. $schema->expects($this->once())
  509. ->method('getTables')
  510. ->willReturn([]);
  511. $schema->expects($this->once())
  512. ->method('getSequences')
  513. ->willReturn([$sequence]);
  514. $sourceSchema = $this->createMock(Schema::class);
  515. $sourceSchema->expects($this->any())
  516. ->method('getTable')
  517. ->willThrowException(new SchemaException());
  518. $sourceSchema->expects($this->any())
  519. ->method('hasSequence')
  520. ->willReturn(false);
  521. self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
  522. }
  523. public function testEnsureOracleConstraintsBooleanNotNull() {
  524. $this->expectException(\InvalidArgumentException::class);
  525. $column = $this->createMock(Column::class);
  526. $column->expects($this->any())
  527. ->method('getName')
  528. ->willReturn('aaaa');
  529. $column->expects($this->any())
  530. ->method('getType')
  531. ->willReturn(Type::getType('boolean'));
  532. $column->expects($this->any())
  533. ->method('getNotnull')
  534. ->willReturn(true);
  535. $table = $this->createMock(Table::class);
  536. $table->expects($this->any())
  537. ->method('getName')
  538. ->willReturn(\str_repeat('a', 30));
  539. $table->expects($this->once())
  540. ->method('getColumns')
  541. ->willReturn([$column]);
  542. $schema = $this->createMock(Schema::class);
  543. $schema->expects($this->once())
  544. ->method('getTables')
  545. ->willReturn([$table]);
  546. $sourceSchema = $this->createMock(Schema::class);
  547. $sourceSchema->expects($this->any())
  548. ->method('getTable')
  549. ->willThrowException(new SchemaException());
  550. $sourceSchema->expects($this->any())
  551. ->method('hasSequence')
  552. ->willReturn(false);
  553. self::invokePrivate($this->migrationService, 'ensureOracleConstraints', [$sourceSchema, $schema, 3]);
  554. }
  555. }