From e226ac6d5bad57dcd83ee5d75ec3686d204b2a0b Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 4 Apr 2024 18:18:12 +0200 Subject: [PATCH 1/3] support phpcr-bundle 3 --- CHANGELOG.md | 8 ++++++ composer.json | 2 +- src/Functional/BaseTestCase.php | 13 +++++++--- src/Unit/Constraint/SchemaAcceptsXml.php | 2 +- tests/Functional/BaseTestCaseTest.php | 25 ++++++++++++------- .../Unit/Constraint/SchemaAcceptsXmlTest.php | 6 ++--- tests/Unit/XmlSchemaTestCaseTest.php | 4 +-- 7 files changed, 41 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 332dc34..e5fcb3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ Changelog ========= +4.x +=== + +4.4.3 +----- + +* Support phpcr-bundle 3. + 4.4.2 ----- diff --git a/composer.json b/composer.json index caf153a..4b51f2a 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ }, "require-dev": { "doctrine/doctrine-bundle": "^1.8 || ^2.0", - "doctrine/phpcr-bundle": "^1.3 || ^2.0.0", + "doctrine/phpcr-bundle": "^1.3 || ^2.0 || ^3.0", "symfony/console": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0", "symfony/dependency-injection": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0", "symfony/doctrine-bridge": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0", diff --git a/src/Functional/BaseTestCase.php b/src/Functional/BaseTestCase.php index 6e61652..9733efa 100644 --- a/src/Functional/BaseTestCase.php +++ b/src/Functional/BaseTestCase.php @@ -167,7 +167,14 @@ protected function getDbManager(string $type) )); } - $dbManager = new $className($this->getContainer()); + $refl = new \ReflectionClass($className); + if (1 === $refl->getConstructor()->getNumberOfParameters()) { + // phpcr-bundle < 3 + $dbManager = new $className(self::getContainer()); + } else { + // phpcr-bundle >= 3 + $dbManager = new $className(self::getContainer()->get('doctrine_phpcr'), self::getContainer()->get('doctrine_phpcr.initializer_manager')); + } $this->dbManagers[$type] = $dbManager; @@ -178,10 +185,10 @@ protected static function assertResponseSuccess(Response $response) { libxml_use_internal_errors(true); - $dom = new \DomDocument(); + $dom = new \DOMDocument(); $dom->loadHTML($response->getContent()); - $xpath = new \DOMXpath($dom); + $xpath = new \DOMXPath($dom); $result = $xpath->query('//div[contains(@class,"text-exception")]/h1'); $exception = null; if ($result->length) { diff --git a/src/Unit/Constraint/SchemaAcceptsXml.php b/src/Unit/Constraint/SchemaAcceptsXml.php index 46c1e82..d3913ae 100644 --- a/src/Unit/Constraint/SchemaAcceptsXml.php +++ b/src/Unit/Constraint/SchemaAcceptsXml.php @@ -35,7 +35,7 @@ public function matches($schemaFile): bool throw new \InvalidArgumentException(sprintf('Can only test a file if it contains 1 element, %d given', $configElement->length)); } - $configDom = new \DomDocument(); + $configDom = new \DOMDocument(); $configDom->appendChild($configDom->importNode($configElement->item(0), true)); libxml_use_internal_errors(true); diff --git a/tests/Functional/BaseTestCaseTest.php b/tests/Functional/BaseTestCaseTest.php index e063e02..5983b30 100644 --- a/tests/Functional/BaseTestCaseTest.php +++ b/tests/Functional/BaseTestCaseTest.php @@ -11,6 +11,8 @@ namespace Symfony\Cmf\Component\Testing\Tests\Functional; +use Doctrine\Bundle\PHPCRBundle\Initializer\InitializerManager; +use Doctrine\Bundle\PHPCRBundle\ManagerRegistryInterface; use Doctrine\Bundle\PHPCRBundle\Test\RepositoryManager; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -25,12 +27,12 @@ class BaseTestCaseTest extends TestCase { /** - * @var ContainerInterface|MockObject + * @var ContainerInterface&MockObject */ private $container; /** - * @var KernelInterface|MockObject + * @var KernelInterface&MockObject */ private $kernel; @@ -47,20 +49,24 @@ class BaseTestCaseTest extends TestCase protected function setUp(): void { $this->container = $this->createMock(ContainerInterface::class); - $this->container->expects($this->any()) + $this->container ->method('get') - ->will($this->returnCallback(function ($name) { - $dic = ['test.client' => $this->client]; + ->willReturnCallback(function ($name) { + $dic = [ + 'test.client' => $this->client, + 'doctrine_phpcr' => $this->createMock(ManagerRegistryInterface::class), + 'doctrine_phpcr.initializer_manager' => $this->createMock(InitializerManager::class), + ]; return $dic[$name]; - })); + }); $this->kernel = $this->createMock(KernelInterface::class); - $this->kernel->expects($this->any()) + $this->kernel ->method('getContainer') ->willReturn($this->container) ; - $this->kernel->expects($this->any()) + $this->kernel ->method('getEnvironment') ->willReturn('phpcr') ; @@ -74,7 +80,7 @@ protected function setUp(): void $this->client = $this->createMock(Client::class); } - $this->client->expects($this->any()) + $this->client ->method('getContainer') ->willReturn($this->container); } @@ -122,6 +128,7 @@ public function provideTestDb() /** * @dataProvider provideTestDb + * * @depends testGetContainer */ public function testDb($dbName, $expected) diff --git a/tests/Unit/Constraint/SchemaAcceptsXmlTest.php b/tests/Unit/Constraint/SchemaAcceptsXmlTest.php index 29e8801..898de98 100644 --- a/tests/Unit/Constraint/SchemaAcceptsXmlTest.php +++ b/tests/Unit/Constraint/SchemaAcceptsXmlTest.php @@ -53,11 +53,11 @@ public function getAssertingData() $data = []; - $dom1 = new \DomDocument(); + $dom1 = new \DOMDocument(); $dom1->loadXML(''); $data[] = [[$dom1], $schema1, true]; - $dom2 = new \DomDocument(); + $dom2 = new \DOMDocument(); $dom2->loadXML(''); $data[] = [[$dom2], $schema1, false]; @@ -70,7 +70,7 @@ public function getAssertingData() public function testFailsIfNoConfigElementIsAvailable() { - $dom = new \DomDocument(); + $dom = new \DOMDocument(); $dom->loadXML(''); $constraint = new SchemaAcceptsXml([$dom]); diff --git a/tests/Unit/XmlSchemaTestCaseTest.php b/tests/Unit/XmlSchemaTestCaseTest.php index e70678e..d02ea45 100644 --- a/tests/Unit/XmlSchemaTestCaseTest.php +++ b/tests/Unit/XmlSchemaTestCaseTest.php @@ -17,14 +17,14 @@ class XmlSchemaTestCaseTest extends XmlSchemaTestCase { public function testAcceptsSingleDomsWithoutArray() { - $dom = new \DomDocument(); + $dom = new \DOMDocument(); $dom->loadXML(''); $this->assertSchemaAcceptsXml($dom, __DIR__.'/../Fixtures/schema/schema1.xsd'); } public function testNegativeAssertion() { - $dom = new \DomDocument(); + $dom = new \DOMDocument(); $dom->loadXML(''); $this->assertSchemaRefusesXml($dom, __DIR__.'/../Fixtures/schema/schema1.xsd'); From 3b52fcb94e58bfb4a7b138b8169306b2f1f77384 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 5 Apr 2024 12:39:29 +0200 Subject: [PATCH 2/3] remove obsolete branch alias --- .github/workflows/test-application.yaml | 3 +-- composer.json | 5 ----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index a215c5c..036e636 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -4,7 +4,6 @@ on: pull_request: push: branches: - - 'master' - '[0-9]+.x' - '[0-9]+.[0-9]+' - '[0-9]+.[0-9]+.x' @@ -51,7 +50,7 @@ jobs: - 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 diff --git a/composer.json b/composer.json index 4b51f2a..f910041 100644 --- a/composer.json +++ b/composer.json @@ -41,10 +41,5 @@ "allow-plugins": { "composer/package-versions-deprecated": true } - }, - "extra": { - "branch-alias": { - "dev-master": "4.x-dev" - } } } From 613197b723fda622f0c89450875edbe23767a4b6 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 5 Apr 2024 15:35:51 +0200 Subject: [PATCH 3/3] Support doctrine/phpcr-bundle 3 and Symfony 7 --- .github/workflows/test-application.yaml | 29 ++++++++++--------------- CHANGELOG.md | 4 +++- composer.json | 24 +++++++++++--------- resources/config/dist/framework.php | 15 ++++++------- resources/config/dist/security.php | 11 +++++----- src/Functional/BaseTestCase.php | 17 +-------------- src/HttpKernel/TestKernel.php | 2 +- tests/Functional/BaseTestCaseTest.php | 25 ++++++++++----------- 8 files changed, 54 insertions(+), 73 deletions(-) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 036e636..0be5657 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -20,24 +20,23 @@ jobs: strategy: fail-fast: false matrix: - symfony-version: - - '*' include: - - php-version: '7.1' + - php-version: '7.2' dependencies: 'lowest' - symfony-version: '^3.4' + symfony-version: '^5.4' symfony-deprecation-helper: 'weak' - - - php-version: '7.2' - php-version: '7.3' + symfony-version: '*' - php-version: '7.4' - symfony-version: '^4.4' - - php-version: '7.4' - symfony-version: '5.0.*' - - php-version: '8.0' + symfony-version: '^5.4' - php-version: '8.0' symfony-version: '6.0.*' - + - php-version: '8.1' + symfony-version: '^6.4' + - php-version: '8.2' + symfony-version: '*' + - php-version: '8.3' + symfony-version: '^7.0' steps: - name: Checkout project uses: actions/checkout@v2 @@ -46,13 +45,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} - 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 + tools: composer:v2, flex - name: Install dependencies with Composer uses: ramsey/composer-install@v1 diff --git a/CHANGELOG.md b/CHANGELOG.md index e5fcb3e..a33c22c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,12 @@ Changelog 4.x === -4.4.3 +4.5.0 ----- * Support phpcr-bundle 3. +* Support Symfony 7. +* Drop support for Symfony < 5.4. 4.4.2 ----- diff --git a/composer.json b/composer.json index f910041..97a64de 100644 --- a/composer.json +++ b/composer.json @@ -9,22 +9,26 @@ } ], "require": { - "php": "^7.1|^8.0", + "php": "^7.2|^8.0", "doctrine/data-fixtures": "^1.2", - "symfony/browser-kit": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0" + "symfony/browser-kit": "^5.4 || ^6.0 || ^7.0" }, "require-dev": { "doctrine/doctrine-bundle": "^1.8 || ^2.0", "doctrine/phpcr-bundle": "^1.3 || ^2.0 || ^3.0", - "symfony/console": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0", - "symfony/dependency-injection": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0", - "symfony/doctrine-bridge": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0", - "symfony/framework-bundle": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0", - "symfony/http-kernel": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0", + "symfony/console": "^5.4 || ^6.0 || ^7.0", + "symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0", + "symfony/doctrine-bridge": "^5.4 || ^6.0 || ^7.0", + "symfony/framework-bundle": "^5.4.6 || ^6.0 || ^7.0", + "symfony/http-kernel": "^5.4 || ^6.0 || ^7.0", "symfony/monolog-bundle": "^3.5", - "symfony/security-bundle": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0", - "symfony/twig-bundle": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0", - "symfony/phpunit-bridge": "^5.4" + "symfony/security-bundle": "^5.4 || ^6.0 || ^7.0", + "symfony/twig-bundle": "^5.4 || ^6.0 || ^7.0", + "symfony/phpunit-bridge": "^7.0.6", + "symfony/yaml": "^5.4 || ^6.0 || ^7.0" + }, + "conflict": { + "symfony/framework-bundle": "<5.4.6" }, "autoload": { "psr-4": { diff --git a/resources/config/dist/framework.php b/resources/config/dist/framework.php index e1a05e4..73ef908 100644 --- a/resources/config/dist/framework.php +++ b/resources/config/dist/framework.php @@ -16,11 +16,10 @@ $config = [ 'secret' => 'test', - 'test' => null, + 'test' => true, 'form' => true, 'validation' => [ 'enabled' => true, - 'enable_annotations' => true, ], 'router' => [ 'resource' => $routerPath, @@ -29,14 +28,14 @@ 'translator' => [ 'fallback' => 'en', ], + 'session' => [ + 'storage_factory_id' => 'session.storage.factory.mock_file', + ], ]; -if (interface_exists(\Symfony\Component\HttpFoundation\Session\Storage\SessionStorageFactoryInterface::class)) { - // Symfony 5.3+ - $config = array_merge($config, ['session' => ['storage_factory_id' => 'session.storage.factory.mock_file']]); -} else { - // Symfony <5.3 - $config = array_merge($config, ['session' => ['storage_id' => 'session.storage.filesystem']]); +if (class_exists(\Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::class)) { + // Symfony < 7 + $config['validation']['enable_annotations'] = true; } $container->loadFromExtension('framework', $config); diff --git a/resources/config/dist/security.php b/resources/config/dist/security.php index 9651d85..26b08c7 100644 --- a/resources/config/dist/security.php +++ b/resources/config/dist/security.php @@ -41,16 +41,17 @@ ]; if (class_exists(\Symfony\Component\Security\Core\Authentication\Provider\AnonymousAuthenticationProvider::class)) { - // Symfony <=5.4 + // Symfony 5.4 $config = array_merge($config, ['firewall' => ['main' => ['anonymous' => null]]]); } if (interface_exists(\Symfony\Component\PasswordHasher\PasswordHasherInterface::class)) { unset($config['encoders']); - $config = array_merge($config, [ - 'enable_authenticator_manager' => true, - 'password_hashers' => ['Symfony\Component\Security\Core\User\User' => 'plaintext'], - ]); + $config['password_hashers'] = ['Symfony\Component\Security\Core\User\User' => 'plaintext']; + if (class_exists(\Symfony\Component\Security\Core\Security::class)) { + // Symfony 6 but not 7 + $config['enable_authenticator_manager'] = true; + } } $container->loadFromExtension('security', $config); diff --git a/src/Functional/BaseTestCase.php b/src/Functional/BaseTestCase.php index 9733efa..845ba68 100644 --- a/src/Functional/BaseTestCase.php +++ b/src/Functional/BaseTestCase.php @@ -18,7 +18,6 @@ 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\ContainerInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\KernelInterface; @@ -80,18 +79,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(): ContainerInterface - { - if (method_exists(KernelTestCase::class, 'getContainer')) { - return parent::getContainer(); - } - - return self::getKernel()->getContainer(); - } - protected static function getKernel(): KernelInterface { if (null === static::$kernel) { @@ -100,9 +87,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(); diff --git a/src/HttpKernel/TestKernel.php b/src/HttpKernel/TestKernel.php index 16ba132..8092d5b 100644 --- a/src/HttpKernel/TestKernel.php +++ b/src/HttpKernel/TestKernel.php @@ -214,7 +214,7 @@ protected function registerConfiguredBundles() } } - protected function build(ContainerBuilder $container) + protected function build(ContainerBuilder $container): void { parent::build($container); if (\in_array($this->getEnvironment(), ['test', 'phpcr']) && file_exists($this->getKernelDir().'/config/public_services.php')) { diff --git a/tests/Functional/BaseTestCaseTest.php b/tests/Functional/BaseTestCaseTest.php index 5983b30..22f0b1b 100644 --- a/tests/Functional/BaseTestCaseTest.php +++ b/tests/Functional/BaseTestCaseTest.php @@ -12,6 +12,7 @@ namespace Symfony\Cmf\Component\Testing\Tests\Functional; use Doctrine\Bundle\PHPCRBundle\Initializer\InitializerManager; +use Doctrine\Bundle\PHPCRBundle\ManagerRegistry; use Doctrine\Bundle\PHPCRBundle\ManagerRegistryInterface; use Doctrine\Bundle\PHPCRBundle\Test\RepositoryManager; use PHPUnit\Framework\MockObject\MockObject; @@ -21,7 +22,9 @@ use Symfony\Cmf\Component\Testing\Functional\BaseTestCase; use Symfony\Cmf\Component\Testing\Functional\DbManager\PHPCR; use Symfony\Cmf\Component\Testing\Tests\Fixtures\TestTestCase; +use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\KernelInterface; class BaseTestCaseTest extends TestCase @@ -48,13 +51,18 @@ class BaseTestCaseTest extends TestCase protected function setUp(): void { - $this->container = $this->createMock(ContainerInterface::class); + $managerRegistry = interface_exists(ManagerRegistryInterface::class) + ? $this->createMock(ManagerRegistryInterface::class) + : $this->createMock(ManagerRegistry::class) + ; + $this->container = Kernel::MAJOR_VERSION >= 7 ? $this->createMock(Container::class) : $this->createMock(ContainerInterface::class); $this->container ->method('get') - ->willReturnCallback(function ($name) { + ->willReturnCallback(function ($name) use ($managerRegistry) { $dic = [ 'test.client' => $this->client, - 'doctrine_phpcr' => $this->createMock(ManagerRegistryInterface::class), + 'test.service_container' => $this->container, + 'doctrine_phpcr' => $managerRegistry, 'doctrine_phpcr.initializer_manager' => $this->createMock(InitializerManager::class), ]; @@ -85,15 +93,6 @@ protected function setUp(): void ->willReturn($this->container); } - public function testGetContainer() - { - $class = new \ReflectionClass(BaseTestCase::class); - $method = $class->getMethod('getContainer'); - $method->setAccessible(true); - - $this->assertEquals($this->container, $method->invoke(null)); - } - public function testGetKernel() { $class = new \ReflectionClass(BaseTestCase::class); @@ -128,8 +127,6 @@ public function provideTestDb() /** * @dataProvider provideTestDb - * - * @depends testGetContainer */ public function testDb($dbName, $expected) {