Skip to content

Commit

Permalink
Remove support for container-aware migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Jan 12, 2025
1 parent b1e4351 commit f85face
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 125 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
Type declarations have been added to all method signatures and properties. You
might have to adjust your own code to abide by the new type declarations.

## BC break: Removed support for container-aware migrations

* Migrations that implement `ContainerAwareInterface` will no longer have the container injected automatically.
* The `ContainerAwareMigrationFactory` class has been removed.

## From 2.x to 3.0.0

- The configuration for the migration namespace and directory changed as follows:
Expand Down
8 changes: 0 additions & 8 deletions config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@
<factory service="doctrine.migrations.dependency_factory" method="getMigrationFactory"/>
</service>

<service id="doctrine.migrations.container_aware_migrations_factory"
class="Doctrine\Bundle\MigrationsBundle\MigrationsFactory\ContainerAwareMigrationFactory"
decorates="doctrine.migrations.migrations_factory"
>
<argument id="doctrine.migrations.container_aware_migrations_factory.inner" type="service"/>
<argument id="service_container" type="service"/>
</service>

<service id="doctrine_migrations.diff_command" class="Doctrine\Migrations\Tools\Console\Command\DiffCommand">

<argument type="service" id="doctrine.migrations.dependency_factory"/>
Expand Down
11 changes: 0 additions & 11 deletions phpstan-baseline.neon

This file was deleted.

5 changes: 0 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ parameters:
- src
- tests

excludePaths:
# That file contains an error that cannot be ignored
- tests/Fixtures/Migrations/ContainerAwareMigration.php

includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
Expand Down
8 changes: 0 additions & 8 deletions src/DependencyInjection/DoctrineMigrationsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use RuntimeException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\Extension;
Expand All @@ -24,7 +23,6 @@
use function assert;
use function explode;
use function implode;
use function interface_exists;
use function is_array;
use function sprintf;
use function strlen;
Expand Down Expand Up @@ -128,12 +126,6 @@ public function load(array $configs, ContainerBuilder $container): void

$container->setParameter('doctrine.migrations.preferred_em', $config['em']);
$container->setParameter('doctrine.migrations.preferred_connection', $config['connection']);

if (interface_exists(ContainerAwareInterface::class)) {
return;
}

$container->removeDefinition('doctrine.migrations.container_aware_migrations_factory');
}

private function checkIfBundleRelativePath(string $path, ContainerBuilder $container): string
Expand Down
35 changes: 0 additions & 35 deletions src/MigrationsFactory/ContainerAwareMigrationFactory.php

This file was deleted.

28 changes: 0 additions & 28 deletions tests/DependencyInjection/DoctrineMigrationsExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension;
use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle;
use Doctrine\Bundle\MigrationsBundle\Tests\Fixtures\Migrations\ContainerAwareMigration;
use Doctrine\Bundle\MigrationsBundle\Tests\Fixtures\TestBundle\TestBundle;
use Doctrine\Migrations\Configuration\Configuration;
use Doctrine\Migrations\DependencyFactory;
Expand All @@ -28,7 +27,6 @@
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
Expand All @@ -37,7 +35,6 @@
use Symfony\Component\VarExporter\LazyGhostTrait;

use function assert;
use function interface_exists;
use function sys_get_temp_dir;
use function trait_exists;

Expand Down Expand Up @@ -177,31 +174,6 @@ public function compare(Version $a, Version $b): int
self::assertSame($sorter, $di->getVersionComparator());
}

/** @group legacy */
public function testContainerAwareMigrations(): void
{
if (! interface_exists(ContainerAwareInterface::class)) {
self::markTestSkipped('This test requires Symfony < 7');
}

$config = [
'migrations_paths' => ['DoctrineMigrationsTest' => 'a'],
];
$container = $this->getContainer($config);

$container->compile();

$di = $container->get('doctrine.migrations.dependency_factory');
self::assertInstanceOf(DependencyFactory::class, $di);

$this->expectDeprecation('Since doctrine/doctrine-migrations-bundle 3.3: Migration "Doctrine\Bundle\MigrationsBundle\Tests\Fixtures\Migrations\ContainerAwareMigration" implements "Symfony\Component\DependencyInjection\ContainerAwareInterface" to gain access to the application\'s service container. This method is deprecated and won\'t work with Symfony 7.');

$migration = $di->getMigrationFactory()->createVersion(ContainerAwareMigration::class);

self::assertInstanceOf(ContainerAwareMigration::class, $migration);
self::assertSame($container, $migration->getContainer());
}

public function testServicesAreLazy(): void
{
$config = [
Expand Down
30 changes: 0 additions & 30 deletions tests/Fixtures/Migrations/ContainerAwareMigration.php

This file was deleted.

0 comments on commit f85face

Please sign in to comment.