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

backport container aware #7

Merged
merged 1 commit into from
Apr 5, 2024
Merged
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
19 changes: 10 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ on:

jobs:
php:
name: "PHP ${{ matrix.php-version }} Symfony ${{ matrix.symfony-version }}"
name: "PHP ${{ matrix.php-version }} Symfony ${{ matrix.symfony-version }} ${{ matrix.dependencies}}"
runs-on: ubuntu-latest

env:
KERNEL_CLASS: PHPCR\PhpcrMigrationsBundle\Tests\Resources\App\AppKernel
SYMFONY_REQUIRE: ${{ matrix.symfony-version }}

strategy:
fail-fast: false
Expand All @@ -24,10 +25,11 @@ jobs:
symfony-version: '^5.4'

- php-version: '8.1'
symfony-version: '6.0.*'
symfony-version: '^6.0'
dependencies: 'lowest'

- php-version: '8.1'
symfony-version: '^6.0'
symfony-version: '^6.4'

- php-version: '8.2'

Expand All @@ -42,16 +44,15 @@ jobs:
with:
php-version: ${{ matrix.php-version }}
extensions: ctype, iconv, mysql
tools: composer:v2, flex
ini-values: memory_limit=-1
coverage: none

- name: Add additional packages
run: |
composer require symfony/symfony:${{ matrix.symfony-version }} --no-update
if: ${{ matrix.symfony-version }}

- name: Install composer dependencies
- name: Install dependencies with Composer
uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.dependencies }}
composer-options: --prefer-dist

- name: Prepare phpcr odm doctrine dbal
run: vendor/symfony-cmf/testing/bin/travis/phpcr_odm_doctrine_dbal.sh
Expand Down
4 changes: 3 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

$finder = PhpCsFixer\Finder::create()
->in('src/')
->in('tests/');
->in('tests/')
->exclude('tests/Resources/App/var/')
;
$config = new PhpCsFixer\Config();

return $config->setFinder($finder)
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
CHANGELOG
=========

1.x
===

1.6.0
-----

* Deprecate using `Symfony\Component\DependencyInjection\ContainerAwareInterface` in favor of
`PHPCR\PhpcrMigrationsBundle\ContainerAwareInterface` as Symfony 7 dropped its
ContainerAwareInterface.
On Symfony 6, the legacy ContainerAwareInterface continues to be supported.

1.5.0
-----

* Allow installation with Symfony 7
* Allow installation with Symfony 7 (! broken if you use `Symfony\Component\DependencyInjection\ContainerAwareInterface`)
* Drop support for PHP < 8.1 and modernize code

1.4.0
Expand Down
18 changes: 13 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,27 @@
"php": "^8.1",
"phpcr/phpcr-migrations": "^1.1",
"phpcr/phpcr-implementation": "^2.1",
"doctrine/phpcr-bundle": "^1.3 || ^2.0",
"doctrine/phpcr-bundle": "^2.2 || ^3.0",
"symfony/config": "^5.4 || ^6.0 || ^7.0",
"symfony/console": "^5.4 || ^6.0 || ^7.0",
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0"
},
"require-dev": {
"doctrine/doctrine-bundle": "^1.8 || ^2.0",
"doctrine/doctrine-bundle": "^1.8 || ^2.5",
"doctrine/phpcr-odm": "^1.4 || ^2.0",
"doctrine/annotations": "^1.14 || ^2.0",
"jackalope/jackalope-doctrine-dbal": "^1.4 || ^2.0",
"symfony/monolog-bundle": "^3.0",
"symfony/phpunit-bridge": "^7.0",
"symfony/symfony": "^5.4 || ^6.0 || ^7.0",
"symfony-cmf/testing": "^2.1 || ^3.0 || ^4.0"
"symfony/phpunit-bridge": "^7.0.6",
"symfony-cmf/testing": "^4.5.0",
"symfony/security-bundle": "^5.4 || ^6.0 || ^7.0",
"symfony/twig-bundle": "^5.4 || ^6.0 || ^7.0",
"symfony/yaml": "^5.4 || ^6.0 || ^7.0",
"symfony/translation": "^5.4 || ^6.0 || ^7.0",
"symfony/form": "^5.4 || ^6.0 || ^7.0",
"symfony/validator": "^5.4 || ^6.0 || ^7.0",
"symfony/property-access": "^5.4 || ^6.0 || ^7.0"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 5 additions & 1 deletion src/Command/MigrateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
namespace PHPCR\PhpcrMigrationsBundle\Command;

use PHPCR\Migrations\MigratorFactory;
use PHPCR\PhpcrMigrationsBundle\ContainerAwareInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface as SymfonyContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class MigrateCommand extends Command
Expand Down Expand Up @@ -77,6 +78,9 @@ public function execute(InputInterface $input, OutputInterface $output): int
foreach ($migrator->getVersions() as $version) {
if ($version instanceof ContainerAwareInterface) {
$version->setContainer($this->container);
} elseif ($version instanceof SymfonyContainerAwareInterface) {
$version->setContainer($this->container);
@trigger_error('Relying on '.SymfonyContainerAwareInterface::class.' is deprecated and will break when upgrading to Symfony 7. Use '.ContainerAwareInterface::class.' instead.', \E_USER_DEPRECATED);
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/ContainerAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

/*
* This file is part of the PHPCR Migrations package
*
* (c) Daniel Leech <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PHPCR\PhpcrMigrationsBundle;

use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Interface for migrations to get the Symfony container injected.
*/
interface ContainerAwareInterface
{
public function setContainer(?ContainerInterface $container = null): void;
}
3 changes: 3 additions & 0 deletions tests/Functional/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

namespace PHPCR\PhpcrMigrationsBundle\Tests\Functional;

use PHPCR\SessionInterface;
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase as CmfBaseTestCase;
use Symfony\Component\Console\Tester\CommandTester;

abstract class BaseTestCase extends CmfBaseTestCase
{
protected SessionInterface $session;

public function setUp(): void
{
$this->db('PHPCR')->purgeRepository();
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/MigrateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class MigrateCommandTest extends BaseTestCase
{
/**
* It should migrate all the unexecuted migrators.
* It should migrate all the non-executed migrators.
*/
public function testMigrateToLatest(): void
{
Expand Down
8 changes: 4 additions & 4 deletions tests/Resources/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class AppKernel extends TestKernel
{
public function configure()
public function configure(): void
{
$this->requireBundleSets([
'default',
Expand All @@ -34,14 +34,14 @@ public function configure()
]);
}

public function registerContainerConfiguration(LoaderInterface $loader)
public function registerContainerConfiguration(LoaderInterface $loader): void
{
$loader->import(CMF_TEST_CONFIG_DIR.'/default.php');
$loader->import(CMF_TEST_CONFIG_DIR.'/phpcr_odm.php');
$loader->load(__DIR__.'/config/config.yml');
$loader->load(__DIR__.'/config/config.php');
}

protected function prepareContainer(ContainerBuilder $container)
protected function prepareContainer(ContainerBuilder $container): void
{
parent::prepareContainer($container);
$container->setParameter('cmf_testing.bundle_fqn', 'Phpcr\PhpcrMigrationsBundle\PhpcrMigrationsBundle');
Expand Down
15 changes: 15 additions & 0 deletions tests/Resources/App/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

$frameworkConfig = [
'property_access' => true,
];

if (class_exists(Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::class)) {
// Symfony < 7
$frameworkConfig['annotations'] = true;
}

$container->loadFromExtension('framework', $frameworkConfig);
$container->loadFromExtension('phpcr_migrations', [
'version_node_name' => 'jcr:migrations',
]);
5 changes: 0 additions & 5 deletions tests/Resources/App/config/config.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
*/

use PHPCR\Migrations\VersionInterface;
use PHPCR\PhpcrMigrationsBundle\ContainerAwareInterface;
use PHPCR\SessionInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class Version201401011300 implements VersionInterface, ContainerAwareInterface
{
private $container;

public function setContainer(?ContainerInterface $container = null)
public function setContainer(?ContainerInterface $container = null): void
{
$this->container = $container;
}
Expand Down