Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0 BC breaks documentation #1005

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions .scrutinizer.yml

This file was deleted.

5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![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

Expand Down
6 changes: 5 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 39 additions & 0 deletions lib/Doctrine/Migrations/Tools/Console/ConsoleRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -67,6 +73,7 @@ public static function findDependencyFactory() : ?DependencyFactory
}

$dependencyFactory = require $configurationFile;
$dependencyFactory = self::checkLegacyConfiguration($dependencyFactory, $configurationFile);
}

if ($dependencyFactory !== null && ! ($dependencyFactory instanceof DependencyFactory)) {
Expand Down Expand Up @@ -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
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Symfony\Component\Console\Helper\HelperSet;

$conn = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]);

return new HelperSet([
'db' => new ConnectionHelper($conn),
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

return [];
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\Persistence\Mapping\Driver\PHPDriver;
use Symfony\Component\Console\Helper\HelperSet;

$conf = new Configuration();
$conf->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),
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

return [];
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Symfony\Component\Console\Helper\HelperSet;

$conn = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]);

return new HelperSet([
'abc' => new ConnectionHelper($conn),
]);