From d055997bec715ae8b114e77afab6f1fc39997caf Mon Sep 17 00:00:00 2001 From: David Kartik Date: Sat, 4 Apr 2020 11:20:45 -0700 Subject: [PATCH 1/3] Upgrading to 2.2 in order to support L7. Fixing breaking changes. - adding PHP 7.4 to CI. --- .travis.yml | 1 + composer.json | 12 ++--- src/Configuration/Configuration.php | 2 +- src/Configuration/ConfigurationFactory.php | 6 ++- src/Console/DiffCommand.php | 2 +- src/Console/VersionCommand.php | 2 +- src/Migration.php | 10 +++- src/Migrator.php | 40 ++++++++++---- src/Naming/DefaultNamingStrategy.php | 7 +-- src/Naming/NamingStrategy.php | 4 +- src/Output/SqlBuilder.php | 44 +++++++++------- src/Output/stubs/blank.stub | 2 +- src/Output/stubs/create.stub | 2 +- src/Output/stubs/update.stub | 2 +- src/Schema/Builder.php | 52 ++++++++++--------- src/Schema/Table.php | 47 +++++++++-------- .../ConfigurationFactoryTest.php | 20 +++++++ tests/MigrationTest.php | 50 ++++++++++++++++-- tests/MigratorTest.php | 21 ++++++-- tests/Naming/DefaultNamingStrategyTest.php | 2 +- tests/Output/FileWriterTest.php | 9 +++- 21 files changed, 227 insertions(+), 110 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9c0e3c2..3c34a65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: php php: - 7.2 - 7.3 + - 7.4 cache: directories: diff --git a/composer.json b/composer.json index 1aab9ea..a072242 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ } ], "require": { - "php": "^7.1", - "doctrine/migrations": "~1.8", - "illuminate/config": "^6.0", - "illuminate/contracts": "^6.0", - "illuminate/console": "^6.0", - "laravel-doctrine/orm": "^1.0" + "php": "^7.2", + "doctrine/migrations": "~2.2", + "illuminate/config": "^7.0", + "illuminate/contracts": "^7.0", + "illuminate/console": "^7.0", + "laravel-doctrine/orm": "^1.6" }, "require-dev": { "phpunit/phpunit": "^8.0", diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index 2bd5633..969b985 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -2,7 +2,7 @@ namespace LaravelDoctrine\Migrations\Configuration; -use Doctrine\DBAL\Migrations\Configuration\Configuration as MigrationsConfiguration; +use Doctrine\Migrations\Configuration\Configuration as MigrationsConfiguration; use LaravelDoctrine\Migrations\Naming\NamingStrategy; class Configuration extends MigrationsConfiguration diff --git a/src/Configuration/ConfigurationFactory.php b/src/Configuration/ConfigurationFactory.php index 2e23c91..4ebd4ed 100644 --- a/src/Configuration/ConfigurationFactory.php +++ b/src/Configuration/ConfigurationFactory.php @@ -3,8 +3,10 @@ namespace LaravelDoctrine\Migrations\Configuration; use Doctrine\DBAL\Connection; +use Doctrine\Migrations\Exception\MigrationException; use Illuminate\Config\Repository; use Illuminate\Contracts\Config\Repository as ConfigRepository; +use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Contracts\Container\Container; use LaravelDoctrine\Migrations\Naming\DefaultNamingStrategy; @@ -32,9 +34,11 @@ public function __construct(ConfigRepository $config, Container $container) /** * @param Connection $connection - * @param string $name + * @param string $name * * @return Configuration + * @throws MigrationException + * @throws BindingResolutionException */ public function make(Connection $connection, $name = null) { diff --git a/src/Console/DiffCommand.php b/src/Console/DiffCommand.php index d6b1b6c..6bcd654 100644 --- a/src/Console/DiffCommand.php +++ b/src/Console/DiffCommand.php @@ -3,7 +3,7 @@ namespace LaravelDoctrine\Migrations\Console; use Doctrine\Common\Persistence\ManagerRegistry; -use Doctrine\DBAL\Migrations\Provider\OrmSchemaProvider; +use Doctrine\Migrations\Provider\OrmSchemaProvider; use Doctrine\ORM\EntityManagerInterface; use Illuminate\Console\Command; use LaravelDoctrine\Migrations\Configuration\ConfigurationProvider; diff --git a/src/Console/VersionCommand.php b/src/Console/VersionCommand.php index 01f0b2b..6861bcb 100644 --- a/src/Console/VersionCommand.php +++ b/src/Console/VersionCommand.php @@ -2,7 +2,7 @@ namespace LaravelDoctrine\Migrations\Console; -use Doctrine\DBAL\Migrations\MigrationException; +use Doctrine\Migrations\Exception\MigrationException; use Illuminate\Console\Command; use InvalidArgumentException; use LaravelDoctrine\Migrations\Configuration\Configuration; diff --git a/src/Migration.php b/src/Migration.php index ce0f5ca..4840a90 100644 --- a/src/Migration.php +++ b/src/Migration.php @@ -2,7 +2,10 @@ namespace LaravelDoctrine\Migrations; -use Doctrine\DBAL\Migrations\Migration as DBALMigration; +use Doctrine\Migrations\MigrationRepository; +use Doctrine\Migrations\Migrator as DBALMigration; +use Doctrine\Migrations\Version\Executor; +use Doctrine\Migrations\Version\Factory; use LaravelDoctrine\Migrations\Configuration\Configuration; use LaravelDoctrine\Migrations\Exceptions\ExecutedUnavailableMigrationsException; use LaravelDoctrine\Migrations\Exceptions\MigrationVersionException; @@ -44,7 +47,10 @@ public function __construct(Configuration $configuration, $version = 'latest') */ protected function makeMigration(Configuration $configuration) { - return $this->migration = new DBALMigration($configuration); + $repository = $configuration->getDependencyFactory()->getMigrationRepository(); + $outputWriter = $configuration->getOutputWriter(); + $stopwatch = $configuration->getDependencyFactory()->getStopwatch(); + return $this->migration = new DBALMigration($configuration, $repository, $outputWriter, $stopwatch); } /** diff --git a/src/Migrator.php b/src/Migrator.php index 10f4b72..b31494a 100644 --- a/src/Migrator.php +++ b/src/Migrator.php @@ -2,7 +2,9 @@ namespace LaravelDoctrine\Migrations; -use Doctrine\DBAL\Migrations\Version; +use Doctrine\Migrations\Exception\MigrationException; +use Doctrine\Migrations\MigratorConfiguration; +use Doctrine\Migrations\Version\Version; class Migrator { @@ -11,20 +13,20 @@ class Migrator */ protected $notes = []; - /** - * @param Migration $migration - * @param bool|false $dryRun - * @param bool|false $timeQueries - * @param bool|false $allowNoMigration - */ + /** + * @param Migration $migration + * @param bool|false $dryRun + * @param bool|false $timeQueries + * @param bool|false $allowNoMigration + * @throws MigrationException + */ public function migrate(Migration $migration, $dryRun = false, $timeQueries = false, bool $allowNoMigration = false) { - $migration->getMigration()->setNoMigrationException($allowNoMigration); + $configuration = $this->setConfiguration($dryRun, $timeQueries, $allowNoMigration); $sql = $migration->getMigration()->migrate( $migration->getVersion(), - $dryRun, - $timeQueries + $configuration ); $this->writeNotes($migration, $timeQueries, $sql); @@ -38,7 +40,8 @@ public function migrate(Migration $migration, $dryRun = false, $timeQueries = fa */ public function execute(Version $version, $direction, $dryRun = false, $timeQueries = false) { - $version->execute($direction, $dryRun, $timeQueries); + $configuration = $this->setConfiguration($dryRun, $timeQueries); + $version->execute($direction, $configuration); $verb = $direction === 'down' ? 'Rolled back' : 'Migrated'; @@ -119,4 +122,19 @@ protected function note($versionName, Version $version, $timeQueries = false, $v $this->notes[] = $msg; } + + /** + * @param bool $dryRun + * @param bool $timeQueries + * @param bool $allowNoMigrations + * @return MigratorConfiguration + */ + private function setConfiguration(bool $dryRun = false, bool $timeQueries = false, bool $allowNoMigrations = false) + { + $configuration = new MigratorConfiguration(); + $configuration->setDryRun($dryRun); + $configuration->setTimeAllQueries($timeQueries); + $configuration->setNoMigrationException($allowNoMigrations); + return $configuration; + } } diff --git a/src/Naming/DefaultNamingStrategy.php b/src/Naming/DefaultNamingStrategy.php index 1482ffb..3578c2a 100644 --- a/src/Naming/DefaultNamingStrategy.php +++ b/src/Naming/DefaultNamingStrategy.php @@ -2,8 +2,9 @@ namespace LaravelDoctrine\Migrations\Naming; -use Doctrine\DBAL\Migrations\Finder\MigrationFinderInterface; -use Doctrine\DBAL\Migrations\Finder\RecursiveRegexFinder; +use Doctrine\Migrations\Finder\MigrationDeepFinder; +use Doctrine\Migrations\Finder\MigrationFinder; +use Doctrine\Migrations\Finder\RecursiveRegexFinder; class DefaultNamingStrategy implements NamingStrategy { @@ -30,7 +31,7 @@ public function getClassName($version = null) } /** - * @return MigrationFinderInterface + * @return MigrationDeepFinder */ public function getFinder() { diff --git a/src/Naming/NamingStrategy.php b/src/Naming/NamingStrategy.php index a1b9949..a5aee42 100644 --- a/src/Naming/NamingStrategy.php +++ b/src/Naming/NamingStrategy.php @@ -2,7 +2,7 @@ namespace LaravelDoctrine\Migrations\Naming; -use Doctrine\DBAL\Migrations\Finder\MigrationFinderInterface; +use Doctrine\Migrations\Finder\MigrationFinder; interface NamingStrategy { @@ -21,7 +21,7 @@ public function getFilename($version = null); public function getClassName($version = null); /** - * @return MigrationFinderInterface + * @return MigrationFinder */ public function getFinder(); } diff --git a/src/Output/SqlBuilder.php b/src/Output/SqlBuilder.php index 62639fd..22f2076 100644 --- a/src/Output/SqlBuilder.php +++ b/src/Output/SqlBuilder.php @@ -2,18 +2,20 @@ namespace LaravelDoctrine\Migrations\Output; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Schema\Schema; use LaravelDoctrine\Migrations\Configuration\Configuration; class SqlBuilder { - /** - * @param Configuration $configuration - * @param Schema $from - * @param Schema $to - * - * @return string - */ + /** + * @param Configuration $configuration + * @param Schema $from + * @param Schema $to + * + * @return string + * @throws DBALException + */ public function up(Configuration $configuration, Schema $from, Schema $to) { return $this->build( @@ -22,13 +24,14 @@ public function up(Configuration $configuration, Schema $from, Schema $to) ); } - /** - * @param Configuration $configuration - * @param Schema $from - * @param Schema $to - * - * @return string - */ + /** + * @param Configuration $configuration + * @param Schema $from + * @param Schema $to + * + * @return string + * @throws DBALException + */ public function down(Configuration $configuration, Schema $from, Schema $to) { return $this->build( @@ -37,12 +40,13 @@ public function down(Configuration $configuration, Schema $from, Schema $to) ); } - /** - * @param Configuration $configuration - * @param array $queries - * - * @return string - */ + /** + * @param Configuration $configuration + * @param array $queries + * + * @return string + * @throws DBALException + */ public function build(Configuration $configuration, array $queries = []) { $platform = $configuration->getConnection()->getDatabasePlatform()->getName(); diff --git a/src/Output/stubs/blank.stub b/src/Output/stubs/blank.stub index ab344d3..44c3dc3 100644 --- a/src/Output/stubs/blank.stub +++ b/src/Output/stubs/blank.stub @@ -3,7 +3,7 @@ namespace ; use Doctrine\Migrations\AbstractMigration; -use Doctrine\DBAL\Schema\Schema as Schema; +use Doctrine\Schema\Schema as Schema; class extends AbstractMigration { diff --git a/src/Output/stubs/create.stub b/src/Output/stubs/create.stub index ee081f8..09f28c0 100644 --- a/src/Output/stubs/create.stub +++ b/src/Output/stubs/create.stub @@ -3,7 +3,7 @@ namespace ; use Doctrine\Migrations\AbstractMigration; -use Doctrine\DBAL\Schema\Schema as Schema; +use Doctrine\Schema\Schema as Schema; use LaravelDoctrine\Migrations\Schema\Table; use LaravelDoctrine\Migrations\Schema\Builder; diff --git a/src/Output/stubs/update.stub b/src/Output/stubs/update.stub index 8d31480..f47aaa4 100644 --- a/src/Output/stubs/update.stub +++ b/src/Output/stubs/update.stub @@ -3,7 +3,7 @@ namespace ; use Doctrine\Migrations\AbstractMigration; -use Doctrine\DBAL\Schema\Schema as Schema; +use Doctrine\Schema\Schema as Schema; use LaravelDoctrine\Migrations\Schema\Table; use LaravelDoctrine\Migrations\Schema\Builder; diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index ca11611..3b413fd 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -4,6 +4,7 @@ use Closure; use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\SchemaException; class Builder { @@ -43,7 +44,7 @@ public function create($table, Closure $callback) * @param string $table * @param \Closure $callback * - * @throws \Doctrine\DBAL\Schema\SchemaException + * @throws SchemaException * @return \Doctrine\DBAL\Schema\Table|string */ public function table($table, Closure $callback) @@ -106,27 +107,29 @@ public function hasTable($table) return $this->schema->hasTable($table); } - /** - * Determine if the given table has a given column. - * - * @param string $table - * @param string $column - * - * @return bool - */ + /** + * Determine if the given table has a given column. + * + * @param string $table + * @param string $column + * + * @return bool + * @throws SchemaException + */ public function hasColumn($table, $column) { return $this->schema->getTable($table)->hasColumn($column); } - /** - * Determine if the given table has given columns. - * - * @param string $table - * @param array $columns - * - * @return bool - */ + /** + * Determine if the given table has given columns. + * + * @param string $table + * @param array $columns + * + * @return bool + * @throws SchemaException + */ public function hasColumns($table, array $columns) { $tableColumns = array_map('strtolower', array_keys($this->getColumnListing($table))); @@ -140,13 +143,14 @@ public function hasColumns($table, array $columns) return true; } - /** - * Get the column listing for a given table. - * - * @param string $table - * - * @return array - */ + /** + * Get the column listing for a given table. + * + * @param string $table + * + * @return array + * @throws SchemaException + */ public function getColumnListing($table) { return $this->schema->getTable($table)->getColumns(); diff --git a/src/Schema/Table.php b/src/Schema/Table.php index 291b98b..f12c526 100644 --- a/src/Schema/Table.php +++ b/src/Schema/Table.php @@ -3,6 +3,7 @@ namespace LaravelDoctrine\Migrations\Schema; use Closure; +use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Table as Blueprint; use Doctrine\DBAL\Types\Type; @@ -32,7 +33,7 @@ public function __construct(Blueprint $table, Closure $callback = null) * @param string $column * @param int $length * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function guid($column) { @@ -117,7 +118,7 @@ public function foreign( * * @param string $columnName * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function increments($columnName) { @@ -132,7 +133,7 @@ public function increments($columnName) * * @param string $columnName * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function smallIncrements($columnName) { @@ -147,7 +148,7 @@ public function smallIncrements($columnName) * * @param string $columnName * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function bigIncrements($columnName) { @@ -163,7 +164,7 @@ public function bigIncrements($columnName) * @param string $column * @param int $length * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function string($column, $length = 255) { @@ -175,7 +176,7 @@ public function string($column, $length = 255) * * @param string $column * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function text($column) { @@ -189,7 +190,7 @@ public function text($column) * @param bool $autoIncrement * @param bool $unsigned * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function integer($column, $autoIncrement = false, $unsigned = false) { @@ -203,7 +204,7 @@ public function integer($column, $autoIncrement = false, $unsigned = false) * @param bool $autoIncrement * @param bool $unsigned * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function smallInteger($column, $autoIncrement = false, $unsigned = false) { @@ -217,7 +218,7 @@ public function smallInteger($column, $autoIncrement = false, $unsigned = false) * @param bool $autoIncrement * @param bool $unsigned * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function bigInteger($column, $autoIncrement = false, $unsigned = false) { @@ -230,7 +231,7 @@ public function bigInteger($column, $autoIncrement = false, $unsigned = false) * @param string $column * @param bool $autoIncrement * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function unsignedSmallInteger($column, $autoIncrement = false) { @@ -243,7 +244,7 @@ public function unsignedSmallInteger($column, $autoIncrement = false) * @param string $column * @param bool $autoIncrement * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function unsignedInteger($column, $autoIncrement = false) { @@ -256,7 +257,7 @@ public function unsignedInteger($column, $autoIncrement = false) * @param string $column * @param bool $autoIncrement * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function unsignedBigInteger($column, $autoIncrement = false) { @@ -270,7 +271,7 @@ public function unsignedBigInteger($column, $autoIncrement = false) * @param int $precision * @param int $scale * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function float($column, $precision = 8, $scale = 2) { @@ -284,7 +285,7 @@ public function float($column, $precision = 8, $scale = 2) * @param int $precision * @param int $scale * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function decimal($column, $precision = 8, $scale = 2) { @@ -296,7 +297,7 @@ public function decimal($column, $precision = 8, $scale = 2) * * @param string $column * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function boolean($column) { @@ -308,7 +309,7 @@ public function boolean($column) * * @param string $column * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function json($column) { @@ -320,7 +321,7 @@ public function json($column) * * @param string $column * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function date($column) { @@ -332,7 +333,7 @@ public function date($column) * * @param string $column * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function dateTime($column) { @@ -344,7 +345,7 @@ public function dateTime($column) * * @param string $column * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function dateTimeTz($column) { @@ -356,7 +357,7 @@ public function dateTimeTz($column) * * @param string $column * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function time($column) { @@ -368,7 +369,7 @@ public function time($column) * * @param string $column * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function timestamp($column) { @@ -380,7 +381,7 @@ public function timestamp($column) * * @param string $column * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function timestampTz($column) { @@ -434,7 +435,7 @@ public function softDeletes() * * @param string $column * - * @return \Doctrine\DBAL\Schema\Column + * @return Column */ public function binary($column, $length = 255) { diff --git a/tests/Configuration/ConfigurationFactoryTest.php b/tests/Configuration/ConfigurationFactoryTest.php index 463777f..13c99eb 100644 --- a/tests/Configuration/ConfigurationFactoryTest.php +++ b/tests/Configuration/ConfigurationFactoryTest.php @@ -1,6 +1,8 @@ container = m::mock(Container::class); $this->config = m::mock(Repository::class); $this->connection = m::mock(Connection::class); $this->configuration = m::mock(\Doctrine\DBAL\Configuration::class); + $this->schemaManager = m::mock(AbstractSchemaManager::class); + $this->databasePlatform = m::mock(AbstractPlatform::class); $this->factory = new ConfigurationFactory( $this->config, @@ -55,6 +69,8 @@ protected function setUp(): void public function test_can_make_configuration() { $this->connection->shouldReceive('getConfiguration')->andReturn($this->configuration); + $this->connection->shouldReceive('getSchemaManager')->andReturn($this->schemaManager); + $this->connection->shouldReceive('getDatabasePlatform')->andReturn($this->databasePlatform); $this->config->shouldReceive('get') ->once() @@ -93,6 +109,8 @@ public function test_can_make_configuration() public function test_can_make_configuration_for_custom_entity_manager() { $this->connection->shouldReceive('getConfiguration')->andReturn($this->configuration); + $this->connection->shouldReceive('getSchemaManager')->andReturn($this->schemaManager); + $this->connection->shouldReceive('getDatabasePlatform')->andReturn($this->databasePlatform); $this->config->shouldReceive('has') ->once() @@ -138,6 +156,8 @@ public function test_can_make_configuration_for_custom_entity_manager() public function test_returns_default_configuration_if_not_defined() { $this->connection->shouldReceive('getConfiguration')->andReturn($this->configuration); + $this->connection->shouldReceive('getSchemaManager')->andReturn($this->schemaManager); + $this->connection->shouldReceive('getDatabasePlatform')->andReturn($this->databasePlatform); $this->config->shouldReceive('has') ->once() diff --git a/tests/MigrationTest.php b/tests/MigrationTest.php index b31392b..dff3a1f 100644 --- a/tests/MigrationTest.php +++ b/tests/MigrationTest.php @@ -1,5 +1,9 @@ configuration = m::mock(Configuration::class); - $this->configuration->shouldReceive('getOutputWriter'); + $this->dependencyFactory = m::mock(DependencyFactory::class); + $this->migrationRepository = m::mock(MigrationRepository::class); + $this->outputWriter = m::mock(OutputWriter::class); + $this->stopwatch = m::mock(Stopwatch::class); + $this->configuration->shouldReceive('getOutputWriter')->andReturn($this->outputWriter); + $this->configuration->shouldReceive('getDependencyFactory')->andReturn($this->dependencyFactory); + $this->dependencyFactory->shouldReceive('getMigrationRepository')->andReturn($this->migrationRepository); + $this->dependencyFactory->shouldReceive('getStopwatch')->andReturn($this->stopwatch); } - public function test_can_make_migration() + /** + * @throws ExecutedUnavailableMigrationsException + */ + public function test_can_make_migration() { $this->configuration->shouldReceive('resolveVersionAlias')->andReturn('version3'); $this->configuration->shouldReceive('getMigratedVersions')->andReturn([ @@ -41,11 +75,14 @@ public function test_can_make_migration() 'latest' ); - $this->assertInstanceOf(\Doctrine\DBAL\Migrations\Migration::class, $migration->getMigration()); + $this->assertInstanceOf(\Doctrine\Migrations\Migrator::class, $migration->getMigration()); $this->assertEquals('version3', $migration->getVersion()); } - public function test_throw_exception_when_executed_unavailable_migrations() + /** + * @throws ExecutedUnavailableMigrationsException + */ + public function test_throw_exception_when_executed_unavailable_migrations() { $this->configuration->shouldReceive('resolveVersionAlias')->andReturn('version3'); $this->configuration->shouldReceive('getMigratedVersions')->andReturn([ @@ -66,7 +103,10 @@ public function test_throw_exception_when_executed_unavailable_migrations() $migration->checkIfNotExecutedUnavailableMigrations(); } - public function test_throw_exception_when_no_version() + /** + * @throws ExecutedUnavailableMigrationsException + */ + public function test_throw_exception_when_no_version() { $this->configuration->shouldReceive('resolveVersionAlias')->andReturn(null); $this->configuration->shouldReceive('getMigratedVersions')->andReturn([ diff --git a/tests/MigratorTest.php b/tests/MigratorTest.php index d3e0362..9fff268 100644 --- a/tests/MigratorTest.php +++ b/tests/MigratorTest.php @@ -1,6 +1,8 @@ configuration = m::mock(Configuration::class); $this->configuration->shouldReceive('getOutputWriter'); - $this->dbalMig = m::mock(\Doctrine\DBAL\Migrations\Migration::class); + $this->dbalMig = m::mock(\Doctrine\Migrations\Migrator::class); $this->migration = m::mock(Migration::class); } - public function test_migrate() + /** + * @throws MigrationException + */ + public function test_migrate() { + $doctrineConfig = new MigratorConfiguration(); + $doctrineConfig->setDryRun(false); + $doctrineConfig->setTimeAllQueries(false); + $doctrineConfig->setNoMigrationException(false); + $this->migration->shouldReceive('getMigration')->andReturn($this->dbalMig); $this->migration->shouldReceive('getConfiguration')->andReturn($this->configuration); $this->configuration->shouldReceive('getVersion')->andReturn(m::mock(Version::class)); $this->migration->shouldReceive('getVersion')->andReturn('version1'); - $this->dbalMig->shouldReceive('migrate')->with('version1', false, false)->andReturn([ + $this->dbalMig->shouldReceive('migrate')->with('version1', with(Mockery::on(function($arg) use ($doctrineConfig) { + return $arg == $doctrineConfig; + })))->andReturn([ 'version1' => 'SQL' ]); - $this->dbalMig->shouldReceive('setNoMigrationException')->with(false); $migrator = (new Migrator); $migrator->migrate($this->migration); diff --git a/tests/Naming/DefaultNamingStrategyTest.php b/tests/Naming/DefaultNamingStrategyTest.php index d546d3b..60814dd 100644 --- a/tests/Naming/DefaultNamingStrategyTest.php +++ b/tests/Naming/DefaultNamingStrategyTest.php @@ -1,6 +1,6 @@ expectException(InvalidArgumentException::class); - $this->expectErrorMessage('Migrations directory "doesntexist" does not exist.'); + /** + * This is hacky, but on TravisCI in PHP 7.2 this expectErrorMessage call was failing + * for some reason it wasn't found. Since this is a PHPUnit\TestCase object, I felt + * like this was a safe enough change to make. + */ + if(method_Exists($this, 'expectErrorMessage')) { + $this->expectErrorMessage('Migrations directory "doesntexist" does not exist.'); + } $writer->write('contents', 'filename.php', 'doesntexist'); } From 4f30ddb72e74416cbc86dbb7ea3070dad71bbbbd Mon Sep 17 00:00:00 2001 From: David Kartik Date: Sat, 4 Apr 2020 11:48:42 -0700 Subject: [PATCH 2/3] Updating stubs to reflect breaking changes. --- src/Output/stubs/blank.stub | 6 +++--- src/Output/stubs/create.stub | 6 +++--- src/Output/stubs/update.stub | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Output/stubs/blank.stub b/src/Output/stubs/blank.stub index 44c3dc3..a0251ee 100644 --- a/src/Output/stubs/blank.stub +++ b/src/Output/stubs/blank.stub @@ -3,14 +3,14 @@ namespace ; use Doctrine\Migrations\AbstractMigration; -use Doctrine\Schema\Schema as Schema; +use Doctrine\DBAL\Schema\Schema as Schema; class extends AbstractMigration { /** * @param Schema $schema */ - public function up(Schema $schema) + public function up(Schema $schema): void { } @@ -18,7 +18,7 @@ class extends AbstractMigration /** * @param Schema $schema */ - public function down(Schema $schema) + public function down(Schema $schema): void { } diff --git a/src/Output/stubs/create.stub b/src/Output/stubs/create.stub index 09f28c0..d818830 100644 --- a/src/Output/stubs/create.stub +++ b/src/Output/stubs/create.stub @@ -3,7 +3,7 @@ namespace ; use Doctrine\Migrations\AbstractMigration; -use Doctrine\Schema\Schema as Schema; +use Doctrine\DBAL\Schema\Schema as Schema; use LaravelDoctrine\Migrations\Schema\Table; use LaravelDoctrine\Migrations\Schema\Builder; @@ -12,7 +12,7 @@ class extends AbstractMigration /** * @param Schema $schema */ - public function up(Schema $schema) + public function up(Schema $schema): void { (new Builder($schema))->create('', function (Table $table) { $table->increments('id'); @@ -23,7 +23,7 @@ class extends AbstractMigration /** * @param Schema $schema */ - public function down(Schema $schema) + public function down(Schema $schema): void { (new Builder($schema))->drop('
'); } diff --git a/src/Output/stubs/update.stub b/src/Output/stubs/update.stub index f47aaa4..37538ad 100644 --- a/src/Output/stubs/update.stub +++ b/src/Output/stubs/update.stub @@ -3,7 +3,7 @@ namespace ; use Doctrine\Migrations\AbstractMigration; -use Doctrine\Schema\Schema as Schema; +use Doctrine\DBAL\Schema\Schema as Schema; use LaravelDoctrine\Migrations\Schema\Table; use LaravelDoctrine\Migrations\Schema\Builder; @@ -12,7 +12,7 @@ class extends AbstractMigration /** * @param Schema $schema */ - public function up(Schema $schema) + public function up(Schema $schema): void { (new Builder($schema))->table('
', function (Table $table) { // @@ -22,7 +22,7 @@ class extends AbstractMigration /** * @param Schema $schema */ - public function down(Schema $schema) + public function down(Schema $schema): void { (new Builder($schema))->table('
', function (Table $table) { // From 993385093af7b6a9ca3090241657afcb0b42af5f Mon Sep 17 00:00:00 2001 From: David Kartik Date: Sun, 5 Apr 2020 08:29:31 -0700 Subject: [PATCH 3/3] Fixing FileWriterTest. --- tests/Output/FileWriterTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Output/FileWriterTest.php b/tests/Output/FileWriterTest.php index 48fe323..784ecc7 100644 --- a/tests/Output/FileWriterTest.php +++ b/tests/Output/FileWriterTest.php @@ -15,9 +15,7 @@ public function test_can_write_to_non_existing_path() * for some reason it wasn't found. Since this is a PHPUnit\TestCase object, I felt * like this was a safe enough change to make. */ - if(method_Exists($this, 'expectErrorMessage')) { - $this->expectErrorMessage('Migrations directory "doesntexist" does not exist.'); - } + $this->expectExceptionMessage('Migrations directory "doesntexist" does not exist.'); $writer->write('contents', 'filename.php', 'doesntexist'); }