diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index b2385aa71f..0000000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,29 +0,0 @@ -build: - nodes: - analysis: - environment: - php: - version: 7.2 - cache: - disabled: false - directories: - - ~/.composer/cache - project_setup: - override: true - tests: - override: - - php-scrutinizer-run - - phpcs-run - dependencies: - override: - - composer install --no-interaction - -tools: - external_code_coverage: - timeout: 600 - -build_failure_conditions: - - 'elements.rating(<= C).new.exists' # No new classes/methods with a rating of C or worse allowed - - 'issues.label("coding-style").new.exists' # No new coding style issues allowed - - 'issues.severity(>= MAJOR).new.exists' # New issues of major or higher severity - - 'project.metric_change("scrutinizer.test_coverage", < 0)' # Code Coverage decreased from previous inspection diff --git a/.travis.yml b/.travis.yml index bc2923dba3..871926c46e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,9 +40,8 @@ jobs: - if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi script: - ./vendor/bin/phpunit --coverage-clover clover.xml - after_script: - - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover clover.xml + after_success: + - bash <(curl -s https://codecov.io/bash) - stage: Code Quality env: CODING_STANDARDS diff --git a/README.md b/README.md index 30c198d5c6..f7fb0b560c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # Doctrine Migrations [![Build Status](https://travis-ci.org/doctrine/migrations.svg)](https://travis-ci.org/doctrine/migrations) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/doctrine/migrations/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/doctrine/migrations/?branch=master) -[![Code Coverage](https://scrutinizer-ci.com/g/doctrine/migrations/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/doctrine/migrations/?branch=master) +[![Code Coverage](https://codecov.io/gh/doctrine/migrations/branch/master/graph/badge.svg)](https://codecov.io/gh/doctrine/migrations/branch/master) ## Documentation diff --git a/UPGRADE.md b/UPGRADE.md index 68c9ecbc76..d84d8ba9c0 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -13,11 +13,15 @@ please refer to the [Code BC breaks](#code-bc-breaks) section. use `migrations:list` instead. - The `--write-sql` option for `migrations:migrate` and `migrations:execute` does not imply dry-run anymore, use the `--dry-run` parameter instead. +- The `migrations:migrate` command will return a non-zero exit code if there are no migrations to execute, +use the `--allow-no-migration` parameter to have a zero exit code. + ## Migrations table - The migrations table now has a new column named `execution_time`. - +- Running the `migrations:migrate` or `migrations:execute` command will automatically upgrade the migration +table structure; a dedicated `migrations:sync-metadata-storage` command is available to sync manually the migrations table. ## Configuration files diff --git a/docs/en/reference/custom-configuration.rst b/docs/en/reference/custom-configuration.rst index 3b29ecd82c..e6100bad3d 100644 --- a/docs/en/reference/custom-configuration.rst +++ b/docs/en/reference/custom-configuration.rst @@ -18,7 +18,7 @@ Once you have your custom integration setup, you can modify it to look like the use Doctrine\Migrations\Configuration\Connection\ExistingConnection; use Doctrine\Migrations\Configuration\Configuration\ExistingConfiguration; use Doctrine\Migrations\DependencyFactory; - une Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration; + use Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration; use Doctrine\Migrations\Tools\Console\Command; use Symfony\Component\Console\Application; diff --git a/lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php b/lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php index adc7c60f04..ffdb7b7d55 100644 --- a/lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php +++ b/lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php @@ -4,6 +4,10 @@ namespace Doctrine\Migrations\Tools\Console; +use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; +use Doctrine\Migrations\Configuration\Connection\ExistingConnection; +use Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager; +use Doctrine\Migrations\Configuration\Migration\ConfigurationFileWithFallback; use Doctrine\Migrations\DependencyFactory; use Doctrine\Migrations\Tools\Console\Command\CurrentCommand; use Doctrine\Migrations\Tools\Console\Command\DiffCommand; @@ -19,9 +23,11 @@ use Doctrine\Migrations\Tools\Console\Command\SyncMetadataCommand; use Doctrine\Migrations\Tools\Console\Command\UpToDateCommand; use Doctrine\Migrations\Tools\Console\Command\VersionCommand; +use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper; use PackageVersions\Versions; use RuntimeException; use Symfony\Component\Console\Application; +use Symfony\Component\Console\Helper\HelperSet; use function file_exists; use function getcwd; use function is_readable; @@ -67,6 +73,7 @@ public static function findDependencyFactory() : ?DependencyFactory } $dependencyFactory = require $configurationFile; + $dependencyFactory = self::checkLegacyConfiguration($dependencyFactory, $configurationFile); } if ($dependencyFactory !== null && ! ($dependencyFactory instanceof DependencyFactory)) { @@ -121,4 +128,36 @@ public static function addCommands(Application $cli, ?DependencyFactory $depende $cli->add(new DiffCommand($dependencyFactory)); } + + /** + * @param mixed|HelperSet $dependencyFactory + * + * @return mixed|DependencyFactory + */ + private static function checkLegacyConfiguration($dependencyFactory, string $configurationFile) + { + if (! ($dependencyFactory instanceof HelperSet)) { + return $dependencyFactory; + } + + $configurations = new ConfigurationFileWithFallback(); + if ($dependencyFactory->has('em') && $dependencyFactory->get('em') instanceof EntityManagerHelper) { + return DependencyFactory::fromEntityManager( + $configurations, + new ExistingEntityManager($dependencyFactory->get('em')->getEntityManager()) + ); + } + + if ($dependencyFactory->has('db') && $dependencyFactory->get('db') instanceof ConnectionHelper) { + return DependencyFactory::fromConnection( + $configurations, + new ExistingConnection($dependencyFactory->get('db')->getConnection()) + ); + } + + throw new RuntimeException(sprintf( + 'Configuration HelperSet returned by "%s" does not have a valid "em" or the "db" helper.', + $configurationFile + )); + } } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php index 8fb8ab4681..6929bac172 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/ConsoleRunnerTest.php @@ -6,6 +6,7 @@ use Doctrine\Migrations\DependencyFactory; use Doctrine\Migrations\Tools\Console\ConsoleRunner; +use Doctrine\ORM\EntityManager; use PHPUnit\Framework\TestCase; use RuntimeException; use Symfony\Component\Console\Application; @@ -24,6 +25,66 @@ class ConsoleRunnerTest extends TestCase /** @var Application */ private $application; + public function testCreateDependencyFactoryFromLegacyDbalHelper() : void + { + $dir = getcwd(); + if ($dir === false) { + $dir = '.'; + } + + chdir(__DIR__ . '/legacy-config-dbal'); + + try { + $dependencyFactory = ConsoleRunnerStub::findDependencyFactory(); + self::assertInstanceOf(DependencyFactory::class, $dependencyFactory); + self::assertSame('sqlite', $dependencyFactory->getConnection()->getDatabasePlatform()->getName()); + } finally { + chdir($dir); + } + } + + public function testCreateDependencyFactoryFromLegacyOrmHelper() : void + { + $dir = getcwd(); + if ($dir === false) { + $dir = '.'; + } + + chdir(__DIR__ . '/legacy-config-orm'); + + try { + $dependencyFactory = ConsoleRunnerStub::findDependencyFactory(); + self::assertInstanceOf(DependencyFactory::class, $dependencyFactory); + self::assertSame('sqlite', $dependencyFactory->getConnection()->getDatabasePlatform()->getName()); + self::assertInstanceOf(EntityManager::class, $dependencyFactory->getEntityManager()); + } finally { + chdir($dir); + } + } + + public function testCreateDependencyFactoryFromWrongLegacyHelper() : void + { + $this->expectException(RuntimeException::class); + + $dir = getcwd(); + if ($dir === false) { + $dir = '.'; + } + + chdir(__DIR__ . '/legacy-config-wrong'); + + $this->expectExceptionMessage(sprintf( + 'Configuration HelperSet returned by "%s" does not have a valid "em" or the "db" helper.', + realpath(__DIR__ . '/legacy-config-wrong/cli-config.php') + )); + + try { + $dependencyFactory = ConsoleRunnerStub::findDependencyFactory(); + } finally { + chdir($dir); + } + } + /** * @dataProvider getDependencyFactoryTestDirectories */ diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-dbal/cli-config.php b/tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-dbal/cli-config.php new file mode 100644 index 0000000000..664a76e5c3 --- /dev/null +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-dbal/cli-config.php @@ -0,0 +1,13 @@ + 'pdo_sqlite', 'memory' => true]); + +return new HelperSet([ + 'db' => new ConnectionHelper($conn), +]); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-dbal/migrations.php b/tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-dbal/migrations.php new file mode 100644 index 0000000000..0dae23dee5 --- /dev/null +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-dbal/migrations.php @@ -0,0 +1,5 @@ +setProxyDir(__DIR__); +$conf->setProxyNamespace('Foo'); +$conf->setMetadataDriverImpl(new PHPDriver('')); + +$conn = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]); + +$em = EntityManager::create($conn, $conf); + +return new HelperSet([ + 'em' => new EntityManagerHelper($em), +]); diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-orm/migrations.php b/tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-orm/migrations.php new file mode 100644 index 0000000000..0dae23dee5 --- /dev/null +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/legacy-config-orm/migrations.php @@ -0,0 +1,5 @@ + 'pdo_sqlite', 'memory' => true]); + +return new HelperSet([ + 'abc' => new ConnectionHelper($conn), +]);