Skip to content

Commit

Permalink
Merge branch '3.0.x-merge-up-into-3.1.x_60204e5c66f340.22495263' into…
Browse files Browse the repository at this point in the history
… 3.0.x-merge-up
  • Loading branch information
goetas committed Feb 7, 2021
2 parents 3e2970d + f424cc7 commit 260991b
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Expand Up @@ -40,7 +40,7 @@ jobs:
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"

- name: "Install dependencies with Composer"
run: "composer install --no-interaction --no-progress --no-suggest"
run: "composer install --no-interaction --no-progress"

# https://github.com/doctrine/.github/issues/3
- name: "Run PHP_CodeSniffer"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Expand Up @@ -40,7 +40,7 @@ jobs:
restore-keys: "php-${{ matrix.php-version }}-composer-locked-"

- name: "Install dependencies with composer"
run: "composer install --no-interaction --no-progress --no-suggest"
run: "composer install --no-interaction --no-progress"

- name: "Run a static analysis with phpstan/phpstan"
run: "vendor/bin/phpstan analyse"
2 changes: 1 addition & 1 deletion docs/en/reference/configuration.rst
Expand Up @@ -161,7 +161,7 @@ Here the possible options for ``table_storage``:
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| executed_at_column_name | no | executed_at | The name of the column which stores the date that a migration was executed. |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+
| execution_time_column_name | no | executed_at | The name of the column which stores how long a migration took (milliseconds). |
| execution_time_column_name | no | execution_time | The name of the column which stores how long a migration took (milliseconds). |
+----------------------------+------------+------------------------------+----------------------------------------------------------------------------------+

Manually Providing Migrations
Expand Down
7 changes: 6 additions & 1 deletion lib/Doctrine/Migrations/DependencyFactory.php
Expand Up @@ -59,6 +59,9 @@
*/
class DependencyFactory
{
/** @psalm-var array<string, bool> */
private $inResolution = [];

/** @var Configuration */
private $configuration;

Expand Down Expand Up @@ -490,8 +493,10 @@ public function getRollup(): Rollup
*/
private function getDependency(string $id, callable $callback)
{
if (array_key_exists($id, $this->factories) && ! array_key_exists($id, $this->dependencies)) {
if (! isset($this->inResolution[$id]) && array_key_exists($id, $this->factories) && ! array_key_exists($id, $this->dependencies)) {
$this->inResolution[$id] = true;
$this->dependencies[$id] = call_user_func($this->factories[$id], $this);
unset($this->inResolution);
}

if (! array_key_exists($id, $this->dependencies)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Migrations/Version/DbalMigrationFactory.php
Expand Up @@ -11,7 +11,7 @@
/**
* The DbalMigrationFactory class is responsible for creating instances of a migration class name for a DBAL connection.
*
* @var internal
* @internal
*/
final class DbalMigrationFactory implements MigrationFactory
{
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Expand Up @@ -25,7 +25,6 @@ parameters:
-
message: '~^Method Doctrine\\Migrations\\Tests\\Stub\\DoctrineRegistry::getService\(\) should return Doctrine\\Persistence\\ObjectManager but returns Doctrine\\DBAL\\Connection\|Doctrine\\ORM\\EntityManager~'
path: %currentWorkingDirectory%/tests/Doctrine/Migrations/Tests/Stub/DoctrineRegistry.php
- '~Unable to resolve the template type T in call to method static method Doctrine\\DBAL\\DriverManager\:\:getConnection\(\)~'
- '~Call to method getVersion\(\) of deprecated class PackageVersions\\Versions\:.*~'

symfony:
Expand Down
20 changes: 20 additions & 0 deletions tests/Doctrine/Migrations/Tests/DependencyFactoryTest.php
Expand Up @@ -18,6 +18,9 @@
use Doctrine\Migrations\Metadata\Storage\TableMetadataStorageConfiguration;
use Doctrine\Migrations\Provider\OrmSchemaProvider;
use Doctrine\Migrations\Provider\SchemaProvider;
use Doctrine\Migrations\Tests\MigrationRepository\Migrations\A\A;
use Doctrine\Migrations\Tests\Stub\CustomClassNameMigrationFactory;
use Doctrine\Migrations\Version\MigrationFactory;
use Doctrine\ORM\EntityManager;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -198,6 +201,23 @@ public function testServiceDefinition(): void
self::assertSame($anotherLogger, $di->getLogger());
}

public function testServiceDecoratesDefaultImplementation(): void
{
$configuration = new Configuration();
$configuration->addMigrationClass(A::class);

$di = DependencyFactory::fromConnection(new ExistingConfiguration($configuration), new ExistingConnection($this->connection));

$di->setDefinition(MigrationFactory::class, static function (DependencyFactory $innerDi): CustomClassNameMigrationFactory {
$serviceToDecorate = $innerDi->getMigrationFactory();

return new CustomClassNameMigrationFactory($serviceToDecorate, A::class);
});

$factory = $di->getMigrationFactory();
self::assertInstanceOf(A::class, $factory->createVersion('SomeVersion'));
}

public function testServiceHasPriorityOverDefinition(): void
{
$logger = $this->createMock(LoggerInterface::class);
Expand Down
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Doctrine\Migrations\Tests\Stub;

use Doctrine\Migrations\AbstractMigration;
use Doctrine\Migrations\Version\MigrationFactory;

class CustomClassNameMigrationFactory implements MigrationFactory
{
/** @var MigrationFactory */
private $parentMigrationFactory;

/** @psalm-var class-string<AbstractMigration> */
private $migrationClassName;

/**
* @param class-string<AbstractMigration> $migrationClassName
*/
public function __construct(MigrationFactory $parentMigrationFactory, string $migrationClassName)
{
$this->parentMigrationFactory = $parentMigrationFactory;
$this->migrationClassName = $migrationClassName;
}

public function createVersion(string $migrationClassName): AbstractMigration
{
return $this->parentMigrationFactory->createVersion($this->migrationClassName);
}
}
20 changes: 14 additions & 6 deletions tests/Doctrine/Migrations/Tests/Stub/DoctrineRegistry.php
Expand Up @@ -22,17 +22,25 @@ class DoctrineRegistry extends AbstractManagerRegistry
private $connections;

/**
* @param Connection[] $connections
* @param EntityManager[] $realEntityManagers
* @param array<string,Connection> $connections
* @param array<string,EntityManager> $realEntityManagers
*/
public function __construct(array $connections = [], array $realEntityManagers = [])
{
/**
* @var string[] $connectionNames
*/
$connectionNames = array_keys($connections);
/**
* @var string[] $realEntityManagerNames
*/
$realEntityManagerNames = array_keys($realEntityManagers);
parent::__construct(
'some_registry',
(array) array_combine(array_keys($connections), array_keys($connections)),
(array) array_combine(array_keys($realEntityManagers), array_keys($realEntityManagers)),
key($connections) !== null ? (string) key($connections) : null,
key($realEntityManagers) !== null ? (string) key($realEntityManagers) : null,
array_combine($connectionNames, $connectionNames),
array_combine($realEntityManagerNames, $realEntityManagerNames),
key($connections) ?? null,
key($realEntityManagers) ?? null,
'Doctrine\Persistence\Proxy'
);
$this->realEntityManagers = $realEntityManagers;
Expand Down

0 comments on commit 260991b

Please sign in to comment.