From d409941d5c64f975b53b6c1ad7b79c0b3b4e8beb Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sun, 18 Feb 2024 01:42:10 +0100 Subject: [PATCH] drop symfony 5 support --- .github/workflows/test-application.yaml | 27 ++++++---------- CHANGELOG.md | 2 +- bootstrap/bootstrap.php | 18 ----------- composer.json | 23 +++++++------ resources/.travis.yml | 23 ------------- resources/config/dist/framework.php | 12 +------ resources/config/dist/security.php | 12 ++----- src/Functional/BaseTestCase.php | 36 ++++----------------- src/Functional/DbManager/ORM.php | 6 ++-- src/Functional/DbManager/PHPCR.php | 18 +++-------- src/Functional/DbManager/PhpcrDecorator.php | 8 +---- tests/Functional/BaseTestCaseTest.php | 28 ++++++---------- 12 files changed, 49 insertions(+), 164 deletions(-) delete mode 100644 resources/.travis.yml diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 5fefe4b..5f64133 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -24,26 +24,18 @@ jobs: symfony-version: - '*' include: - - php-version: '7.1' + - php-version: '8.1' dependencies: 'lowest' - symfony-version: '^3.4' symfony-deprecation-helper: 'weak' - - - php-version: '7.2' - - php-version: '7.3' - - php-version: '7.4' - symfony-version: '^4.4' - - php-version: '7.4' - symfony-version: '5.0.*' - - php-version: '8.0' - - php-version: '8.0' - symfony-version: '6.0.*' + - php-version: '8.1' + symfony-version: '6.4.*' - php-version: '8.2' + - php-version: '8.3' symfony-version: '7.0.*' steps: - name: Checkout project - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install and configure PHP uses: shivammathur/setup-php@v2 @@ -52,13 +44,12 @@ jobs: tools: 'composer:v2' - name: Install Symfony Flex - run: composer global require --no-progress --no-scripts --no-plugins symfony/flex - - - name: Allow Symfony Flex Plugin - run: composer global config --no-plugins allow-plugins.symfony/flex true + run: | + composer global require --no-progress --no-scripts --no-plugins symfony/flex + composer global config --no-plugins allow-plugins.symfony/flex true - name: Install dependencies with Composer - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 with: dependency-versions: ${{ matrix.dependencies }} composer-options: --prefer-dist diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c8b6d6..4f549dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ Changelog 5.0.0 (unreleased) -* Support Symfony 7, drop support for Symfony < 5.4 +* Support Symfony 7, drop support for Symfony < 6.4 * The default framework configuration no longer enables validation attributes. * The phpcr-odm additional namespace is expected to use attributes rather than annotations. diff --git a/bootstrap/bootstrap.php b/bootstrap/bootstrap.php index a478073..100d0f9 100644 --- a/bootstrap/bootstrap.php +++ b/bootstrap/bootstrap.php @@ -21,24 +21,6 @@ exit(1); } -use Doctrine\Common\Annotations\AnnotationRegistry; - -if (method_exists(AnnotationRegistry::class, 'registerLoader')) { - AnnotationRegistry::registerLoader(function ($class) use ($loader) { - $loader->loadClass($class); - - // this was class_exists($class, false) i.e. do not autoload. - // this is required so that custom annotations (e.g. TreeUiBundle - // annotations) are autoloaded - but they should be found by the - // composer loader above. - // - // This probably slows things down. - // - // @todo: Fix me. - return class_exists($class); - }); -} - if (!defined('CMF_TEST_ROOT_DIR')) { define('CMF_TEST_ROOT_DIR', realpath(__DIR__.'/..')); } diff --git a/composer.json b/composer.json index 612d016..82218d9 100644 --- a/composer.json +++ b/composer.json @@ -9,23 +9,26 @@ } ], "require": { - "php": "^7.1|^8.0", + "php": "^8.1", "doctrine/data-fixtures": "^1.2", - "symfony/browser-kit": "^5.4 || ^6.4 || ^7.0" + "symfony/browser-kit": "^6.4 || ^7.0" }, "require-dev": { "doctrine/doctrine-bundle": "^1.8 || ^2.0", - "doctrine/phpcr-bundle": "^1.3 || ^2.0.0 || ^3.0@beta", - "symfony/console": "^5.4 || ^6.4 || ^7.0", - "symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0", - "symfony/doctrine-bridge": "^5.4 || ^6.4 || ^7.0", - "symfony/framework-bundle": "^5.4 || ^6.4 || ^7.0", - "symfony/http-kernel": "^5.4 || ^6.4 || ^7.0", + "doctrine/phpcr-bundle": "^3.0@beta", + "symfony/console": "^6.4 || ^7.0", + "symfony/dependency-injection": "^6.4 || ^7.0", + "symfony/doctrine-bridge": "^6.4 || ^7.0", + "symfony/framework-bundle": "^6.4 || ^7.0", + "symfony/http-kernel": "^6.4 || ^7.0", "symfony/monolog-bundle": "^3.5", - "symfony/security-bundle": "^5.4 || ^6.4 || ^7.0", - "symfony/twig-bundle": "^5.4 || ^6.4 || ^7.0", + "symfony/security-bundle": "^6.4 || ^7.0", + "symfony/twig-bundle": "^6.4 || ^7.0", "symfony/phpunit-bridge": "^7.0.3" }, + "conflict": { + "doctrine/phpcr-bundle": "<3.0" + }, "autoload": { "psr-4": { "Symfony\\Cmf\\Component\\Testing\\": "src/" diff --git a/resources/.travis.yml b/resources/.travis.yml deleted file mode 100644 index dd9412d..0000000 --- a/resources/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -language: php - -php: - - 5.3 - - 5.4 - -env: - - SYMFONY_VERSION=2.3.* - - SYMFONY_VERSION=2.4.* - - SYMFONY_VERSION=dev-master - -before_script: - - ./vendor/symfony-cmf/testing/bin/init-travis/phpcr_odm_doctrine_dbal.sh - -script: phpunit --coverage-text - -notifications: - irc: "irc.freenode.org#symfony-cmf" - email: "symfony-cmf-devs@googlegroups.com" - -matrix: - allow_failures: - - env: SYMFONY_VERSION=dev-master diff --git a/resources/config/dist/framework.php b/resources/config/dist/framework.php index b33edda..32aa127 100644 --- a/resources/config/dist/framework.php +++ b/resources/config/dist/framework.php @@ -9,13 +9,6 @@ * file that was distributed with this source code. */ -use Symfony\Component\HttpKernel\Kernel; - -$routerPath = '%kernel.root_dir%/config/routing.php'; -if ($container->hasParameter('kernel.project_dir')) { - $routerPath = '%kernel.project_dir%/config/routing.php'; -} - $config = [ 'secret' => 'test', 'test' => null, @@ -24,7 +17,7 @@ 'enabled' => true, ], 'router' => [ - 'resource' => $routerPath, + 'resource' => '%kernel.project_dir%/config/routing.php', ], 'default_locale' => 'en', 'translator' => [ @@ -34,9 +27,6 @@ 'storage_factory_id' => 'session.storage.factory.mock_file', ] ]; -if (Kernel::MAJOR_VERSION < 6) { - $config['validation']['enable_annotations'] = true; -} $container->loadFromExtension('framework', $config); diff --git a/resources/config/dist/security.php b/resources/config/dist/security.php index 543448b..f40d8b7 100644 --- a/resources/config/dist/security.php +++ b/resources/config/dist/security.php @@ -37,17 +37,11 @@ ], ]; -if (class_exists(\Symfony\Component\Security\Core\Authentication\Provider\AnonymousAuthenticationProvider::class)) { - // Symfony <=5.4 +if (class_exists(\Symfony\Component\Security\Core\Security::class)) { $config = array_merge($config, [ - 'firewall' => ['main' => ['anonymous' => null]], - 'encoders' => ['Symfony\Component\Security\Core\User\User' => 'plaintext'], + 'enable_authenticator_manager' => true, + 'password_hashers' => ['Symfony\Component\Security\Core\User\User' => 'plaintext'], ]); -} elseif (class_exists(\Symfony\Component\Security\Core\Security::class)) { - $config = array_merge($config, [ - 'enable_authenticator_manager' => true, - 'password_hashers' => ['Symfony\Component\Security\Core\User\User' => 'plaintext'], - ]); } $container->loadFromExtension('security', $config); diff --git a/src/Functional/BaseTestCase.php b/src/Functional/BaseTestCase.php index 39ab2a9..da6cdda 100644 --- a/src/Functional/BaseTestCase.php +++ b/src/Functional/BaseTestCase.php @@ -12,13 +12,11 @@ namespace Symfony\Cmf\Component\Testing\Functional; use Doctrine\Bundle\PHPCRBundle\Test\RepositoryManager; -use Symfony\Bundle\FrameworkBundle\Client; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Cmf\Component\Testing\Functional\DbManager\ORM; use Symfony\Cmf\Component\Testing\Functional\DbManager\PHPCR; use Symfony\Cmf\Component\Testing\Functional\DbManager\PhpcrDecorator; -use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\KernelInterface; @@ -32,15 +30,10 @@ abstract class BaseTestCase extends WebTestCase { /** * Use this property to save the DbManagers. - * - * @var array */ - protected $dbManagers = []; + protected array $dbManagers = []; - /** - * @var Client - */ - protected $client; + protected ?KernelBrowser $client = null; /** * Return the configuration to use when creating the Kernel. @@ -80,18 +73,6 @@ protected static function bootKernel(array $options = []): KernelInterface return parent::bootKernel(static::getKernelConfiguration()); } - /** - * BC with Symfony < 5.3 - when minimum version raises to ^5.3, we can remove this method. - */ - protected static function getContainer(): Container - { - if (method_exists(KernelTestCase::class, 'getContainer')) { - return parent::getContainer(); - } - - return self::getKernel()->getContainer(); - } - protected static function getKernel(): KernelInterface { if (null === static::$kernel) { @@ -100,9 +81,7 @@ protected static function getKernel(): KernelInterface if (static::$kernel instanceof KernelInterface) { $kernelEnvironment = static::$kernel->getEnvironment(); - $expectedEnvironment = isset(static::getKernelConfiguration()['environment']) - ? static::getKernelConfiguration()['environment'] - : 'phpcr'; + $expectedEnvironment = static::getKernelConfiguration()['environment'] ?? 'phpcr'; if ($kernelEnvironment !== $expectedEnvironment) { var_dump($kernelEnvironment, $expectedEnvironment); static::bootKernel(); @@ -116,17 +95,14 @@ protected static function getKernel(): KernelInterface return static::$kernel; } - /** - * @return Client|KernelBrowser - */ - protected function getFrameworkBundleClient() + protected function getFrameworkBundleClient(): KernelBrowser { if (null === $this->client) { // property does not exist in all symfony versions if (property_exists(self::class, 'booted') && self::$booted) { self::ensureKernelShutdown(); } - $this->client = self::createClient($this->getKernelConfiguration()); + $this->client = self::createClient(self::getKernelConfiguration()); } return $this->client; @@ -174,7 +150,7 @@ protected function getDbManager(string $type) return $dbManager; } - protected static function assertResponseSuccess(Response $response) + protected static function assertResponseSuccess(Response $response): void { libxml_use_internal_errors(true); diff --git a/src/Functional/DbManager/ORM.php b/src/Functional/DbManager/ORM.php index 7753867..54b8b98 100644 --- a/src/Functional/DbManager/ORM.php +++ b/src/Functional/DbManager/ORM.php @@ -16,8 +16,6 @@ use Doctrine\Common\DataFixtures\Loader; use Doctrine\Common\DataFixtures\ProxyReferenceRepository; use Doctrine\Common\DataFixtures\Purger\ORMPurger; -use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry; -use Doctrine\Common\Persistence\ObjectManager as LegacyObjectManager; use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ObjectManager; use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader; @@ -53,7 +51,7 @@ public function __construct(ContainerInterface $container) } /** - * @return ManagerRegistry|LegacyManagerRegistry + * @return ManagerRegistry */ public function getRegistry() { @@ -61,7 +59,7 @@ public function getRegistry() } /** - * @return ObjectManager|LegacyObjectManager + * @return ObjectManager */ public function getOm($managerName = null) { diff --git a/src/Functional/DbManager/PHPCR.php b/src/Functional/DbManager/PHPCR.php index 5e3c4c6..dc92e75 100644 --- a/src/Functional/DbManager/PHPCR.php +++ b/src/Functional/DbManager/PHPCR.php @@ -16,7 +16,6 @@ use Doctrine\Common\DataFixtures\Loader; use Doctrine\Common\DataFixtures\ProxyReferenceRepository; use Doctrine\Common\DataFixtures\Purger\PHPCRPurger; -use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry; use Doctrine\ODM\PHPCR\DocumentManager; use Doctrine\Persistence\ManagerRegistry; use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader; @@ -26,25 +25,16 @@ class PHPCR { protected $container; - /** - * @var DocumentManager - */ - protected $om; + protected ?DocumentManager $om=null; - /** - * @var PHPCRExecutor - */ - private $executor; + private ?PHPCRExecutor $executor = null; public function __construct(ContainerInterface $container) { $this->container = $container; } - /** - * @return ManagerRegistry|LegacyManagerRegistry - */ - public function getRegistry() + public function getRegistry(): ManagerRegistry { return $this->container->get('doctrine_phpcr'); } @@ -78,7 +68,7 @@ public function loadFixtures(array $classNames, bool $initialize = false): void $this->getExecutor($initialize)->execute($loader->getFixtures(), false); } - public function loadFixtureClass(Loader $loader, string $className) + public function loadFixtureClass(Loader $loader, string $className): void { if (!class_exists($className)) { throw new \InvalidArgumentException(sprintf( diff --git a/src/Functional/DbManager/PhpcrDecorator.php b/src/Functional/DbManager/PhpcrDecorator.php index 501ae39..c1ab08b 100644 --- a/src/Functional/DbManager/PhpcrDecorator.php +++ b/src/Functional/DbManager/PhpcrDecorator.php @@ -23,13 +23,7 @@ class PhpcrDecorator extends RepositoryManager { public function __construct(ContainerInterface $container) { - // BC with DoctrinePHPCRBundle 2.* - $refl = new \ReflectionClass(RepositoryManager::class); - if (1 === $refl->getConstructor()->getNumberOfParameters()) { - parent::__construct($container); - } else { - parent::__construct($container->get('doctrine_phpcr'), $container->get('doctrine_phpcr.initializer_manager')); - } + parent::__construct($container->get('doctrine_phpcr'), $container->get('doctrine_phpcr.initializer_manager')); } public function getOm(string $managerName = null): DocumentManagerInterface diff --git a/tests/Functional/BaseTestCaseTest.php b/tests/Functional/BaseTestCaseTest.php index 7078af4..0aa4c2f 100644 --- a/tests/Functional/BaseTestCaseTest.php +++ b/tests/Functional/BaseTestCaseTest.php @@ -16,7 +16,6 @@ use Doctrine\Bundle\PHPCRBundle\Test\RepositoryManager; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Symfony\Bundle\FrameworkBundle\Client; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Cmf\Component\Testing\Functional\BaseTestCase; use Symfony\Cmf\Component\Testing\Functional\DbManager\PHPCR; @@ -42,7 +41,7 @@ class BaseTestCaseTest extends TestCase private $testCase; /** - * @var KernelBrowser|Client|MockObject + * @var KernelBrowser&MockObject */ private $client; @@ -76,18 +75,13 @@ protected function setUp(): void $this->testCase = new TestTestCase(); $this->testCase->setKernel($this->kernel); - if (class_exists(KernelBrowser::class)) { - $this->client = $this->createMock(KernelBrowser::class); - } else { - $this->client = $this->createMock(Client::class); - } - - $this->client->expects($this->any()) + $this->client = $this->createMock(KernelBrowser::class); + $this->client ->method('getContainer') ->willReturn($this->container); } - public function testGetContainer() + public function testGetContainer(): void { $class = new \ReflectionClass(BaseTestCase::class); $method = $class->getMethod('getContainer'); @@ -96,7 +90,7 @@ public function testGetContainer() $this->assertEquals($this->container, $method->invoke(null)); } - public function testGetKernel() + public function testGetKernel(): void { $class = new \ReflectionClass(BaseTestCase::class); $method = $class->getMethod('getKernel'); @@ -105,20 +99,16 @@ public function testGetKernel() $this->assertInstanceOf(KernelInterface::class, $method->invoke(null)); } - public function testItCanProvideAFrameworkBundleClient() + public function testItCanProvideAFrameworkBundleClient(): void { $class = new \ReflectionClass(BaseTestCase::class); $method = $class->getMethod('getFrameworkBundleClient'); $method->setAccessible(true); - if (class_exists(KernelBrowser::class)) { - $this->assertInstanceOf(KernelBrowser::class, $method->invoke($this->testCase)); - } else { - $this->assertInstanceOf(Client::class, $method->invoke($this->testCase)); - } + $this->assertInstanceOf(KernelBrowser::class, $method->invoke($this->testCase)); } - public function provideTestDb() + public function provideTestDb(): array { return [ ['PHPCR', 'PHPCR'], @@ -133,7 +123,7 @@ public function provideTestDb() * * @depends testGetContainer */ - public function testDb($dbName, $expected) + public function testDb($dbName, $expected): void { $class = new \ReflectionClass(BaseTestCase::class); $method = $class->getMethod('getDbManager');