2017-06-01 17:56:34 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2016 Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\DB;
|
|
|
|
|
2018-07-19 11:28:52 +03:00
|
|
|
use Doctrine\DBAL\Platforms\OraclePlatform;
|
|
|
|
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
|
2018-07-18 11:42:32 +03:00
|
|
|
use Doctrine\DBAL\Schema\Column;
|
|
|
|
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
|
|
|
|
use Doctrine\DBAL\Schema\Index;
|
2017-06-01 17:56:34 +03:00
|
|
|
use Doctrine\DBAL\Schema\Schema;
|
2018-10-10 11:45:10 +03:00
|
|
|
use Doctrine\DBAL\Schema\SchemaException;
|
2018-07-18 11:42:32 +03:00
|
|
|
use Doctrine\DBAL\Schema\Sequence;
|
|
|
|
use Doctrine\DBAL\Schema\Table;
|
2017-06-01 17:56:34 +03:00
|
|
|
use OC\DB\Connection;
|
|
|
|
use OC\DB\MigrationService;
|
2017-06-09 17:45:12 +03:00
|
|
|
use OC\DB\SchemaWrapper;
|
2017-06-01 17:56:34 +03:00
|
|
|
use OCP\IDBConnection;
|
2017-06-09 17:45:12 +03:00
|
|
|
use OCP\Migration\IMigrationStep;
|
2017-06-01 17:56:34 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class MigrationsTest
|
|
|
|
*
|
|
|
|
* @package Test\DB
|
|
|
|
*/
|
|
|
|
class MigrationsTest extends \Test\TestCase {
|
|
|
|
|
|
|
|
/** @var MigrationService | \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $migrationService;
|
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject | IDBConnection $db */
|
|
|
|
private $db;
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2017-06-01 17:56:34 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->db = $this->createMock(Connection::class);
|
|
|
|
$this->db->expects($this->any())->method('getPrefix')->willReturn('test_oc_');
|
|
|
|
$this->migrationService = new MigrationService('testing', $this->db);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetters() {
|
|
|
|
$this->assertEquals('testing', $this->migrationService->getApp());
|
2017-06-09 17:45:12 +03:00
|
|
|
$this->assertEquals(\OC::$SERVERROOT . '/apps/testing/lib/Migration', $this->migrationService->getMigrationsDirectory());
|
|
|
|
$this->assertEquals('OCA\Testing\Migration', $this->migrationService->getMigrationsNamespace());
|
2017-06-01 17:56:34 +03:00
|
|
|
$this->assertEquals('test_oc_migrations', $this->migrationService->getMigrationsTableName());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCore() {
|
|
|
|
$this->migrationService = new MigrationService('core', $this->db);
|
|
|
|
|
|
|
|
$this->assertEquals('core', $this->migrationService->getApp());
|
|
|
|
$this->assertEquals(\OC::$SERVERROOT . '/core/Migrations', $this->migrationService->getMigrationsDirectory());
|
2017-07-05 16:46:25 +03:00
|
|
|
$this->assertEquals('OC\Core\Migrations', $this->migrationService->getMigrationsNamespace());
|
2017-06-01 17:56:34 +03:00
|
|
|
$this->assertEquals('test_oc_migrations', $this->migrationService->getMigrationsTableName());
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2017-06-01 17:56:34 +03:00
|
|
|
public function testExecuteUnknownStep() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
$this->expectExceptionMessage('Version 20170130180000 is unknown.');
|
|
|
|
|
2017-06-01 17:56:34 +03:00
|
|
|
$this->migrationService->executeStep('20170130180000');
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2017-06-01 17:56:34 +03:00
|
|
|
public function testUnknownApp() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->expectExceptionMessage('App not found');
|
|
|
|
|
2017-06-01 17:56:34 +03:00
|
|
|
$migrationService = new MigrationService('unknown-bloody-app', $this->db);
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2017-06-01 17:56:34 +03:00
|
|
|
public function testExecuteStepWithUnknownClass() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->expectExceptionMessage('Migration step \'X\' is unknown');
|
|
|
|
|
2017-06-01 17:56:34 +03:00
|
|
|
$this->migrationService = $this->getMockBuilder(MigrationService::class)
|
|
|
|
->setMethods(['findMigrations'])
|
|
|
|
->setConstructorArgs(['testing', $this->db])
|
|
|
|
->getMock();
|
|
|
|
$this->migrationService->expects($this->any())->method('findMigrations')->willReturn(
|
|
|
|
['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A']
|
|
|
|
);
|
|
|
|
$this->migrationService->executeStep('20170130180000');
|
|
|
|
}
|
|
|
|
|
2017-06-09 17:45:12 +03:00
|
|
|
public function testExecuteStepWithSchemaChange() {
|
2017-06-01 17:56:34 +03:00
|
|
|
|
|
|
|
$schema = $this->createMock(Schema::class);
|
2017-06-09 17:45:12 +03:00
|
|
|
$this->db->expects($this->any())
|
|
|
|
->method('createSchema')
|
|
|
|
->willReturn($schema);
|
|
|
|
|
|
|
|
$this->db->expects($this->once())
|
|
|
|
->method('migrateToSchema');
|
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
$wrappedSchema = $this->createMock(Schema::class);
|
2018-10-10 11:45:10 +03:00
|
|
|
$wrappedSchema->expects($this->once())
|
2018-07-18 11:42:32 +03:00
|
|
|
->method('getTables')
|
|
|
|
->willReturn([]);
|
|
|
|
$wrappedSchema->expects($this->once())
|
|
|
|
->method('getSequences')
|
2018-10-10 11:45:10 +03:00
|
|
|
->willReturn([]);
|
2018-07-18 11:42:32 +03:00
|
|
|
|
2017-06-09 17:45:12 +03:00
|
|
|
$schemaResult = $this->createMock(SchemaWrapper::class);
|
|
|
|
$schemaResult->expects($this->once())
|
|
|
|
->method('getWrappedSchema')
|
2018-07-18 11:42:32 +03:00
|
|
|
->willReturn($wrappedSchema);
|
2017-06-09 17:45:12 +03:00
|
|
|
|
|
|
|
$step = $this->createMock(IMigrationStep::class);
|
|
|
|
$step->expects($this->at(0))
|
|
|
|
->method('preSchemaChange');
|
|
|
|
$step->expects($this->at(1))
|
|
|
|
->method('changeSchema')
|
|
|
|
->willReturn($schemaResult);
|
|
|
|
$step->expects($this->at(2))
|
|
|
|
->method('postSchemaChange');
|
2017-06-01 17:56:34 +03:00
|
|
|
|
|
|
|
$this->migrationService = $this->getMockBuilder(MigrationService::class)
|
|
|
|
->setMethods(['createInstance'])
|
|
|
|
->setConstructorArgs(['testing', $this->db])
|
|
|
|
->getMock();
|
2017-06-09 17:45:12 +03:00
|
|
|
|
|
|
|
$this->migrationService->expects($this->any())
|
|
|
|
->method('createInstance')
|
|
|
|
->with('20170130180000')
|
|
|
|
->willReturn($step);
|
2017-06-01 17:56:34 +03:00
|
|
|
$this->migrationService->executeStep('20170130180000');
|
|
|
|
}
|
|
|
|
|
2017-06-09 17:45:12 +03:00
|
|
|
public function testExecuteStepWithoutSchemaChange() {
|
2017-06-01 17:56:34 +03:00
|
|
|
|
2017-06-09 17:45:12 +03:00
|
|
|
$schema = $this->createMock(Schema::class);
|
|
|
|
$this->db->expects($this->any())
|
|
|
|
->method('createSchema')
|
|
|
|
->willReturn($schema);
|
|
|
|
|
|
|
|
$this->db->expects($this->never())
|
|
|
|
->method('migrateToSchema');
|
|
|
|
|
|
|
|
$step = $this->createMock(IMigrationStep::class);
|
|
|
|
$step->expects($this->at(0))
|
|
|
|
->method('preSchemaChange');
|
|
|
|
$step->expects($this->at(1))
|
|
|
|
->method('changeSchema')
|
|
|
|
->willReturn(null);
|
|
|
|
$step->expects($this->at(2))
|
|
|
|
->method('postSchemaChange');
|
2017-06-01 17:56:34 +03:00
|
|
|
|
|
|
|
$this->migrationService = $this->getMockBuilder(MigrationService::class)
|
|
|
|
->setMethods(['createInstance'])
|
|
|
|
->setConstructorArgs(['testing', $this->db])
|
|
|
|
->getMock();
|
2017-06-09 17:45:12 +03:00
|
|
|
|
|
|
|
$this->migrationService->expects($this->any())
|
|
|
|
->method('createInstance')
|
|
|
|
->with('20170130180000')
|
|
|
|
->willReturn($step);
|
2017-06-01 17:56:34 +03:00
|
|
|
$this->migrationService->executeStep('20170130180000');
|
|
|
|
}
|
|
|
|
|
2017-06-09 17:45:12 +03:00
|
|
|
public function dataGetMigration() {
|
|
|
|
return [
|
|
|
|
['current', '20170130180001'],
|
|
|
|
['prev', '20170130180000'],
|
|
|
|
['next', '20170130180002'],
|
|
|
|
['latest', '20170130180003'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataGetMigration
|
|
|
|
* @param string $alias
|
|
|
|
* @param string $expected
|
|
|
|
*/
|
|
|
|
public function testGetMigration($alias, $expected) {
|
2017-06-01 17:56:34 +03:00
|
|
|
$this->migrationService = $this->getMockBuilder(MigrationService::class)
|
|
|
|
->setMethods(['getMigratedVersions', 'findMigrations'])
|
|
|
|
->setConstructorArgs(['testing', $this->db])
|
|
|
|
->getMock();
|
|
|
|
$this->migrationService->expects($this->any())->method('getMigratedVersions')->willReturn(
|
|
|
|
['20170130180000', '20170130180001']
|
|
|
|
);
|
|
|
|
$this->migrationService->expects($this->any())->method('findMigrations')->willReturn(
|
|
|
|
['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A']
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
['20170130180000', '20170130180001', '20170130180002', '20170130180003'],
|
|
|
|
$this->migrationService->getAvailableVersions());
|
|
|
|
|
2017-06-09 17:45:12 +03:00
|
|
|
$migration = $this->migrationService->getMigration($alias);
|
|
|
|
$this->assertEquals($expected, $migration);
|
2017-06-01 17:56:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMigrate() {
|
|
|
|
$this->migrationService = $this->getMockBuilder(MigrationService::class)
|
|
|
|
->setMethods(['getMigratedVersions', 'findMigrations', 'executeStep'])
|
|
|
|
->setConstructorArgs(['testing', $this->db])
|
|
|
|
->getMock();
|
|
|
|
$this->migrationService->expects($this->any())->method('getMigratedVersions')->willReturn(
|
|
|
|
['20170130180000', '20170130180001']
|
|
|
|
);
|
|
|
|
$this->migrationService->expects($this->any())->method('findMigrations')->willReturn(
|
|
|
|
['20170130180000' => 'X', '20170130180001' => 'Y', '20170130180002' => 'Z', '20170130180003' => 'A']
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
['20170130180000', '20170130180001', '20170130180002', '20170130180003'],
|
|
|
|
$this->migrationService->getAvailableVersions());
|
|
|
|
|
|
|
|
$this->migrationService->expects($this->exactly(2))->method('executeStep')
|
|
|
|
->withConsecutive(['20170130180002'], ['20170130180003']);
|
|
|
|
$this->migrationService->migrate();
|
|
|
|
}
|
2018-07-18 11:42:32 +03:00
|
|
|
|
|
|
|
public function testEnsureOracleIdentifierLengthLimitValid() {
|
|
|
|
$column = $this->createMock(Column::class);
|
|
|
|
$column->expects($this->once())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 30));
|
|
|
|
|
|
|
|
$index = $this->createMock(Index::class);
|
|
|
|
$index->expects($this->once())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 30));
|
|
|
|
|
|
|
|
$foreignKey = $this->createMock(ForeignKeyConstraint::class);
|
|
|
|
$foreignKey->expects($this->once())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 30));
|
|
|
|
|
|
|
|
$table = $this->createMock(Table::class);
|
2018-10-10 11:45:10 +03:00
|
|
|
$table->expects($this->atLeastOnce())
|
2018-07-18 11:42:32 +03:00
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 30));
|
|
|
|
|
|
|
|
$sequence = $this->createMock(Sequence::class);
|
2018-10-10 11:45:10 +03:00
|
|
|
$sequence->expects($this->atLeastOnce())
|
2018-07-18 11:42:32 +03:00
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 30));
|
|
|
|
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getColumns')
|
|
|
|
->willReturn([$column]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getIndexes')
|
|
|
|
->willReturn([$index]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getForeignKeys')
|
|
|
|
->willReturn([$foreignKey]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getPrimaryKey')
|
|
|
|
->willReturn(null);
|
|
|
|
|
|
|
|
$schema = $this->createMock(Schema::class);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getTables')
|
|
|
|
->willReturn([$table]);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getSequences')
|
|
|
|
->willReturn([$sequence]);
|
|
|
|
|
2018-10-10 11:45:10 +03:00
|
|
|
$sourceSchema = $this->createMock(Schema::class);
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('getTable')
|
|
|
|
->willThrowException(new SchemaException());
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('hasSequence')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
|
2018-07-18 11:42:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnsureOracleIdentifierLengthLimitValidWithPrimaryKey() {
|
|
|
|
$index = $this->createMock(Index::class);
|
2018-07-19 11:28:52 +03:00
|
|
|
$index->expects($this->any())
|
2018-07-18 11:42:32 +03:00
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 30));
|
|
|
|
|
|
|
|
$table = $this->createMock(Table::class);
|
2018-07-19 11:28:52 +03:00
|
|
|
$table->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 26));
|
|
|
|
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getColumns')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getIndexes')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getForeignKeys')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getPrimaryKey')
|
|
|
|
->willReturn($index);
|
|
|
|
|
|
|
|
$schema = $this->createMock(Schema::class);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getTables')
|
|
|
|
->willReturn([$table]);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getSequences')
|
|
|
|
->willReturn([]);
|
|
|
|
|
2018-10-10 11:45:10 +03:00
|
|
|
$sourceSchema = $this->createMock(Schema::class);
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('getTable')
|
|
|
|
->willThrowException(new SchemaException());
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('hasSequence')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
|
2018-07-19 11:28:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testEnsureOracleIdentifierLengthLimitValidWithPrimaryKeyDefault() {
|
|
|
|
$defaultName = 'PRIMARY';
|
|
|
|
if ($this->db->getDatabasePlatform() instanceof PostgreSqlPlatform) {
|
|
|
|
$defaultName = \str_repeat('a', 26) . '_' . \str_repeat('b', 30) . '_seq';
|
|
|
|
} else if ($this->db->getDatabasePlatform() instanceof OraclePlatform) {
|
|
|
|
$defaultName = \str_repeat('a', 26) . '_seq';
|
|
|
|
}
|
|
|
|
|
|
|
|
$index = $this->createMock(Index::class);
|
|
|
|
$index->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn($defaultName);
|
|
|
|
$index->expects($this->any())
|
|
|
|
->method('getColumns')
|
|
|
|
->willReturn([\str_repeat('b', 30)]);
|
|
|
|
|
|
|
|
$table = $this->createMock(Table::class);
|
|
|
|
$table->expects($this->any())
|
2018-07-18 11:42:32 +03:00
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 26));
|
|
|
|
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getColumns')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getIndexes')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getForeignKeys')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getPrimaryKey')
|
|
|
|
->willReturn($index);
|
|
|
|
|
|
|
|
$schema = $this->createMock(Schema::class);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getTables')
|
|
|
|
->willReturn([$table]);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getSequences')
|
|
|
|
->willReturn([]);
|
|
|
|
|
2018-10-10 11:45:10 +03:00
|
|
|
$sourceSchema = $this->createMock(Schema::class);
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('getTable')
|
|
|
|
->willThrowException(new SchemaException());
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('hasSequence')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
|
2018-07-18 11:42:32 +03:00
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
public function testEnsureOracleIdentifierLengthLimitTooLongTableName() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
$table = $this->createMock(Table::class);
|
|
|
|
$table->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 31));
|
|
|
|
|
|
|
|
$schema = $this->createMock(Schema::class);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getTables')
|
|
|
|
->willReturn([$table]);
|
|
|
|
|
2018-10-10 11:45:10 +03:00
|
|
|
$sourceSchema = $this->createMock(Schema::class);
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('getTable')
|
|
|
|
->willThrowException(new SchemaException());
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('hasSequence')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
|
2018-07-18 11:42:32 +03:00
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
public function testEnsureOracleIdentifierLengthLimitTooLongPrimaryWithDefault() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
2018-07-19 11:28:52 +03:00
|
|
|
$defaultName = 'PRIMARY';
|
|
|
|
if ($this->db->getDatabasePlatform() instanceof PostgreSqlPlatform) {
|
|
|
|
$defaultName = \str_repeat('a', 27) . '_' . \str_repeat('b', 30) . '_seq';
|
|
|
|
} else if ($this->db->getDatabasePlatform() instanceof OraclePlatform) {
|
|
|
|
$defaultName = \str_repeat('a', 27) . '_seq';
|
|
|
|
}
|
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
$index = $this->createMock(Index::class);
|
|
|
|
$index->expects($this->any())
|
|
|
|
->method('getName')
|
2018-07-19 11:28:52 +03:00
|
|
|
->willReturn($defaultName);
|
|
|
|
$index->expects($this->any())
|
|
|
|
->method('getColumns')
|
|
|
|
->willReturn([\str_repeat('b', 30)]);
|
2018-07-18 11:42:32 +03:00
|
|
|
|
|
|
|
$table = $this->createMock(Table::class);
|
|
|
|
$table->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 27));
|
|
|
|
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getColumns')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getIndexes')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getForeignKeys')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getPrimaryKey')
|
|
|
|
->willReturn($index);
|
|
|
|
|
|
|
|
$schema = $this->createMock(Schema::class);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getTables')
|
|
|
|
->willReturn([$table]);
|
|
|
|
|
2018-10-10 11:45:10 +03:00
|
|
|
$sourceSchema = $this->createMock(Schema::class);
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('getTable')
|
|
|
|
->willThrowException(new SchemaException());
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('hasSequence')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
|
2018-07-18 11:42:32 +03:00
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
public function testEnsureOracleIdentifierLengthLimitTooLongPrimaryWithName() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
$index = $this->createMock(Index::class);
|
|
|
|
$index->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 31));
|
|
|
|
|
|
|
|
$table = $this->createMock(Table::class);
|
|
|
|
$table->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 26));
|
|
|
|
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getColumns')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getIndexes')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getForeignKeys')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getPrimaryKey')
|
|
|
|
->willReturn($index);
|
|
|
|
|
|
|
|
$schema = $this->createMock(Schema::class);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getTables')
|
|
|
|
->willReturn([$table]);
|
|
|
|
|
2018-10-10 11:45:10 +03:00
|
|
|
$sourceSchema = $this->createMock(Schema::class);
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('getTable')
|
|
|
|
->willThrowException(new SchemaException());
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('hasSequence')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
|
2018-07-18 11:42:32 +03:00
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
public function testEnsureOracleIdentifierLengthLimitTooLongColumnName() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
$column = $this->createMock(Column::class);
|
|
|
|
$column->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 31));
|
|
|
|
|
|
|
|
$table = $this->createMock(Table::class);
|
|
|
|
$table->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 30));
|
|
|
|
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getColumns')
|
|
|
|
->willReturn([$column]);
|
|
|
|
|
|
|
|
$schema = $this->createMock(Schema::class);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getTables')
|
|
|
|
->willReturn([$table]);
|
|
|
|
|
2018-10-10 11:45:10 +03:00
|
|
|
$sourceSchema = $this->createMock(Schema::class);
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('getTable')
|
|
|
|
->willThrowException(new SchemaException());
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('hasSequence')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
|
2018-07-18 11:42:32 +03:00
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
public function testEnsureOracleIdentifierLengthLimitTooLongIndexName() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
$index = $this->createMock(Index::class);
|
|
|
|
$index->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 31));
|
|
|
|
|
|
|
|
$table = $this->createMock(Table::class);
|
|
|
|
$table->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 30));
|
|
|
|
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getColumns')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getIndexes')
|
|
|
|
->willReturn([$index]);
|
|
|
|
|
|
|
|
$schema = $this->createMock(Schema::class);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getTables')
|
|
|
|
->willReturn([$table]);
|
|
|
|
|
2018-10-10 11:45:10 +03:00
|
|
|
$sourceSchema = $this->createMock(Schema::class);
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('getTable')
|
|
|
|
->willThrowException(new SchemaException());
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('hasSequence')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
|
2018-07-18 11:42:32 +03:00
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
public function testEnsureOracleIdentifierLengthLimitTooLongForeignKeyName() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
$foreignKey = $this->createMock(ForeignKeyConstraint::class);
|
|
|
|
$foreignKey->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 31));
|
|
|
|
|
|
|
|
$table = $this->createMock(Table::class);
|
|
|
|
$table->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 30));
|
|
|
|
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getColumns')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getIndexes')
|
|
|
|
->willReturn([]);
|
|
|
|
$table->expects($this->once())
|
|
|
|
->method('getForeignKeys')
|
|
|
|
->willReturn([$foreignKey]);
|
|
|
|
|
|
|
|
$schema = $this->createMock(Schema::class);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getTables')
|
|
|
|
->willReturn([$table]);
|
|
|
|
|
2018-10-10 11:45:10 +03:00
|
|
|
$sourceSchema = $this->createMock(Schema::class);
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('getTable')
|
|
|
|
->willThrowException(new SchemaException());
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('hasSequence')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
|
2018-07-18 11:42:32 +03:00
|
|
|
}
|
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
public function testEnsureOracleIdentifierLengthLimitTooLongSequenceName() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
2018-07-18 11:42:32 +03:00
|
|
|
$sequence = $this->createMock(Sequence::class);
|
|
|
|
$sequence->expects($this->any())
|
|
|
|
->method('getName')
|
|
|
|
->willReturn(\str_repeat('a', 31));
|
|
|
|
|
|
|
|
$schema = $this->createMock(Schema::class);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getTables')
|
|
|
|
->willReturn([]);
|
|
|
|
$schema->expects($this->once())
|
|
|
|
->method('getSequences')
|
|
|
|
->willReturn([$sequence]);
|
|
|
|
|
2018-10-10 11:45:10 +03:00
|
|
|
$sourceSchema = $this->createMock(Schema::class);
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('getTable')
|
|
|
|
->willThrowException(new SchemaException());
|
|
|
|
$sourceSchema->expects($this->any())
|
|
|
|
->method('hasSequence')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$sourceSchema, $schema, 3]);
|
2018-07-18 11:42:32 +03:00
|
|
|
}
|
2017-06-01 17:56:34 +03:00
|
|
|
}
|