From ec7c793777d7397de73fa09cc15e940b09a2c08f Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 16 Feb 2024 21:24:41 +0000 Subject: [PATCH 1/9] Apply fixes from StyleCI [ci skip] [skip ci] --- src/Functional/BaseTestCase.php | 4 ++-- src/Unit/Constraint/SchemaAcceptsXml.php | 2 +- tests/Functional/BaseTestCaseTest.php | 1 + tests/Unit/Constraint/SchemaAcceptsXmlTest.php | 6 +++--- tests/Unit/XmlSchemaTestCaseTest.php | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Functional/BaseTestCase.php b/src/Functional/BaseTestCase.php index 6e61652..3097d44 100644 --- a/src/Functional/BaseTestCase.php +++ b/src/Functional/BaseTestCase.php @@ -178,10 +178,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..e9c293e 100644 --- a/tests/Functional/BaseTestCaseTest.php +++ b/tests/Functional/BaseTestCaseTest.php @@ -122,6 +122,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 03456ab0c5f0d63f3fbe7288b3bb6b8f2f23448a Mon Sep 17 00:00:00 2001 From: Trent Steel Date: Thu, 30 Nov 2023 13:41:56 +1000 Subject: [PATCH 2/9] Support Symfony 7 --- .github/workflows/test-application.yaml | 4 +++- composer.json | 18 +++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index a215c5c..5fefe4b 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -38,6 +38,8 @@ jobs: - php-version: '8.0' - php-version: '8.0' symfony-version: '6.0.*' + - php-version: '8.2' + symfony-version: '7.0.*' steps: - name: Checkout project @@ -51,7 +53,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 caf153a..df3de07 100644 --- a/composer.json +++ b/composer.json @@ -11,19 +11,19 @@ "require": { "php": "^7.1|^8.0", "doctrine/data-fixtures": "^1.2", - "symfony/browser-kit": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0" + "symfony/browser-kit": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0" }, "require-dev": { "doctrine/doctrine-bundle": "^1.8 || ^2.0", - "doctrine/phpcr-bundle": "^1.3 || ^2.0.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", + "doctrine/phpcr-bundle": "^1.3 || ^2.0.0 || ^3.0@beta", + "symfony/console": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0", + "symfony/dependency-injection": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0", + "symfony/doctrine-bridge": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0", + "symfony/framework-bundle": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0", + "symfony/http-kernel": "^3.4.26 || ^4.3.8 || ^5.0 || ^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/security-bundle": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0", + "symfony/twig-bundle": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0", "symfony/phpunit-bridge": "^5.4" }, "autoload": { From ace45d8054b10dbff68fba837885c6d0c3a45db5 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 16 Feb 2024 22:20:45 +0100 Subject: [PATCH 3/9] Adjust for sf7 and new doctrine versions * drop annotations * adjust security to symfony 7 * ignore database creation failure because doctrine dbal decided to be a stickler * drop symfony 5 support --- .github/workflows/test-application.yaml | 43 +++----- CHANGELOG.md | 13 +++ README.md | 14 +-- bin/make/functional_tests_orm.mk | 2 +- bootstrap/bootstrap.php | 18 ---- composer.json | 30 +++--- phpunit.xml.dist | 19 ++-- resources/.travis.yml | 23 ----- resources/config/dist/framework.php | 19 +--- resources/config/dist/phpcr_odm.php | 2 +- resources/config/dist/security.php | 11 +-- src/Functional/BaseTestCase.php | 36 ++----- src/Functional/DbManager/ORM.php | 36 ++----- src/Functional/DbManager/PHPCR.php | 18 +--- src/Functional/DbManager/PhpcrDecorator.php | 6 ++ src/HttpKernel/TestKernel.php | 2 +- tests/Functional/BaseTestCaseTest.php | 104 +++++--------------- 17 files changed, 107 insertions(+), 289 deletions(-) delete mode 100644 resources/.travis.yml diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 5fefe4b..bafb2b9 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' @@ -15,35 +14,22 @@ jobs: runs-on: ubuntu-20.04 env: - SYMFONY_DEPRECATIONS_HELPER: ${{ matrix.symfony-deprecation-helper }} + SYMFONY_DEPRECATIONS_HELPER: weak SYMFONY_REQUIRE: ${{ matrix.symfony-version }} strategy: - fail-fast: false - matrix: - symfony-version: - - '*' - include: - - php-version: '7.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.2' - symfony-version: '7.0.*' + fail-fast: false + matrix: + include: + - php-version: '8.1' + dependencies: 'lowest' + - php-version: '8.1' + - php-version: '8.2' + - php-version: '8.3' steps: - name: Checkout project - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Install and configure PHP uses: shivammathur/setup-php@v2 @@ -52,13 +38,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 332dc34..bad45b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,19 @@ Changelog ========= +5.x +=== + +5.0.0 +----- + +* 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. + +4.x +=== + 4.4.2 ----- diff --git a/README.md b/README.md index 690e8d2..5a4f764 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ [![Total Downloads](https://poser.pugx.org/symfony-cmf/testing/downloads)](https://packagist.org/packages/symfony-cmf/testing) [![Monthly Downloads](https://poser.pugx.org/symfony-cmf/testing/d/monthly)](https://packagist.org/packages/symfony-cmf/testing) -[![Daily Downloads](https://poser.pugx.org/symfony-cmf/testing/d/daily)](https://packagist.org/packages/symfony-cmf/testing) This package is part of the [Symfony Content Management Framework (CMF)](https://cmf.symfony.com/) and licensed under the [MIT License](LICENSE). @@ -18,12 +17,7 @@ the context of the CMF. For the install guide and reference, see: -* [symfony-cmf/testing Documentation](https://symfony.com/doc/master/cmf/components/testing/index.html) - -See also: - -* [All Symfony CMF documentation](https://symfony.com/doc/master/cmf/index.html) - complete Symfony CMF reference -* [Symfony CMF Website](https://cmf.symfony.com/) - introduction, live demo, support and community links +* [symfony-cmf/testing Documentation](https://github.com/symfony-cmf/symfony-cmf-docs/blob/master/components/testing.rst) ## Support @@ -32,13 +26,9 @@ For general support and questions, please use [StackOverflow](https://stackoverf ## Contributing Pull requests are welcome. Please see our -[CONTRIBUTING](https://github.com/symfony-cmf/blob/master/CONTRIBUTING.md) +[CONTRIBUTING](https://github.com/symfony-cmf/testing/blob/5.x/CONTRIBUTING.md) guide. -Unit and/or functional tests exist for this package. See the -[Testing documentation](https://symfony.com/doc/master/cmf/components/testing.html) -for a guide to running the tests. - Thanks to [everyone who has contributed](contributors) already. diff --git a/bin/make/functional_tests_orm.mk b/bin/make/functional_tests_orm.mk index 272369a..4c22f40 100644 --- a/bin/make/functional_tests_orm.mk +++ b/bin/make/functional_tests_orm.mk @@ -4,7 +4,7 @@ functional_tests_orm: @echo @echo '+++ create ORM database +++' @${CONSOLE} doctrine:schema:drop --env=orm --force - @${CONSOLE} doctrine:database:create --env=orm + @${CONSOLE} doctrine:database:create --env=orm || echo "Failed to create database. If this is sqlite, this is normal. Otherwise there will be an error with schema creation" @${CONSOLE} doctrine:schema:create --env=orm @echo '+++ run ORM functional tests +++' ifeq ($(HAS_XDEBUG), 0) 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 df3de07..ef88379 100644 --- a/composer.json +++ b/composer.json @@ -9,22 +9,25 @@ } ], "require": { - "php": "^7.1|^8.0", + "php": "^8.1", "doctrine/data-fixtures": "^1.2", - "symfony/browser-kit": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^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": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0", - "symfony/dependency-injection": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0", - "symfony/doctrine-bridge": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0", - "symfony/framework-bundle": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0", - "symfony/http-kernel": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0", + "doctrine/phpcr-bundle": "^3.0", + "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": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0", - "symfony/twig-bundle": "^3.4.26 || ^4.3.8 || ^5.0 || ^6.0 || ^7.0", - "symfony/phpunit-bridge": "^5.4" + "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": { @@ -41,10 +44,5 @@ "allow-plugins": { "composer/package-versions-deprecated": true } - }, - "extra": { - "branch-alias": { - "dev-master": "4.x-dev" - } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f6973ee..d1e9538 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,19 +1,18 @@ - - - - - ./tests - - + + + ./tests + + - 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 e1a05e4..4928e61 100644 --- a/resources/config/dist/framework.php +++ b/resources/config/dist/framework.php @@ -9,36 +9,25 @@ * file that was distributed with this source code. */ -$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, 'form' => true, 'validation' => [ 'enabled' => true, - 'enable_annotations' => true, ], 'router' => [ - 'resource' => $routerPath, + 'resource' => '%kernel.project_dir%/config/routing.php', ], 'default_locale' => 'en', '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']]); -} - $container->loadFromExtension('framework', $config); $container->loadFromExtension('twig', [ diff --git a/resources/config/dist/phpcr_odm.php b/resources/config/dist/phpcr_odm.php index 75dc67a..4933d35 100644 --- a/resources/config/dist/phpcr_odm.php +++ b/resources/config/dist/phpcr_odm.php @@ -39,7 +39,7 @@ if (file_exists($phpcrOdmDocDir)) { $config['odm']['mappings']['test_additional'] = [ - 'type' => 'annotation', + 'type' => 'attribute', 'prefix' => $phpcrOdmDocPrefix, 'dir' => $phpcrOdmDocDir, 'is_bundle' => false, diff --git a/resources/config/dist/security.php b/resources/config/dist/security.php index 9651d85..f40d8b7 100644 --- a/resources/config/dist/security.php +++ b/resources/config/dist/security.php @@ -10,9 +10,6 @@ */ $config = [ - 'encoders' => [ - 'Symfony\Component\Security\Core\User\User' => 'plaintext', - ], 'role_hierarchy' => [ 'ROLE_ADMIN' => 'ROLE_USER', 'ROLE_SUPER_ADMIN' => ['ROLE_USER', 'ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH'], @@ -40,13 +37,7 @@ ], ]; -if (class_exists(\Symfony\Component\Security\Core\Authentication\Provider\AnonymousAuthenticationProvider::class)) { - // Symfony <=5.4 - $config = array_merge($config, ['firewall' => ['main' => ['anonymous' => null]]]); -} - -if (interface_exists(\Symfony\Component\PasswordHasher\PasswordHasherInterface::class)) { - unset($config['encoders']); +if (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'], diff --git a/src/Functional/BaseTestCase.php b/src/Functional/BaseTestCase.php index 3097d44..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\ContainerInterface; 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(): 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 +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..c72fd14 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; @@ -32,49 +30,29 @@ */ class ORM { - /** - * @var ORMExecutor - */ - private $executor; - - /** - * @var ContainerInterface - */ - protected $container; - - /** - * @var ObjectManager - */ - protected $om; + private ORMExecutor $executor; + protected ContainerInterface $container; + protected ObjectManager $om; public function __construct(ContainerInterface $container) { $this->container = $container; } - /** - * @return ManagerRegistry|LegacyManagerRegistry - */ - public function getRegistry() + public function getRegistry(): ManagerRegistry { return $this->container->get('doctrine'); } - /** - * @return ObjectManager|LegacyObjectManager - */ - public function getOm($managerName = null) + public function getOm($managerName = null): ObjectManager { - if (!$this->om) { + if (!isset($this->om)) { $this->om = $this->getRegistry()->getManager($managerName); } return $this->om; } - /** - * Purge the database. - */ public function purgeDatabase(): void { $referenceRepository = new ProxyReferenceRepository($this->getOm()); @@ -125,7 +103,7 @@ protected function loadFixtureClass(Loader $loader, string $className): void private function getExecutor(): ORMExecutor { - if ($this->executor) { + if (isset($this->executor)) { return $this->executor; } diff --git a/src/Functional/DbManager/PHPCR.php b/src/Functional/DbManager/PHPCR.php index 5e3c4c6..6f34cbb 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 14b1a7d..c1ab08b 100644 --- a/src/Functional/DbManager/PhpcrDecorator.php +++ b/src/Functional/DbManager/PhpcrDecorator.php @@ -13,6 +13,7 @@ use Doctrine\Bundle\PHPCRBundle\Test\RepositoryManager; use Doctrine\ODM\PHPCR\DocumentManagerInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * A decorator around the DoctrinePHPCRBundle RepositoryManager class to @@ -20,6 +21,11 @@ */ class PhpcrDecorator extends RepositoryManager { + public function __construct(ContainerInterface $container) + { + parent::__construct($container->get('doctrine_phpcr'), $container->get('doctrine_phpcr.initializer_manager')); + } + public function getOm(string $managerName = null): DocumentManagerInterface { return $this->getDocumentManager($managerName); 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 e9c293e..f9f8ccd 100644 --- a/tests/Functional/BaseTestCaseTest.php +++ b/tests/Functional/BaseTestCaseTest.php @@ -11,26 +11,25 @@ namespace Symfony\Cmf\Component\Testing\Tests\Functional; -use Doctrine\Bundle\PHPCRBundle\Test\RepositoryManager; +use Doctrine\Bundle\PHPCRBundle\Initializer\InitializerManager; +use Doctrine\Bundle\PHPCRBundle\ManagerRegistryInterface; 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; use Symfony\Cmf\Component\Testing\Tests\Fixtures\TestTestCase; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpKernel\KernelInterface; class BaseTestCaseTest extends TestCase { /** - * @var ContainerInterface|MockObject + * @var Container&MockObject */ private $container; /** - * @var KernelInterface|MockObject + * @var KernelInterface&MockObject */ private $kernel; @@ -40,27 +39,33 @@ class BaseTestCaseTest extends TestCase private $testCase; /** - * @var KernelBrowser|Client|MockObject + * @var KernelBrowser&MockObject */ private $client; protected function setUp(): void { - $this->container = $this->createMock(ContainerInterface::class); - $this->container->expects($this->any()) + $managerRegistry = $this->createMock(ManagerRegistryInterface::class); + $initializerManager = $this->createMock(InitializerManager::class); + $this->container = $this->createMock(Container::class); + $this->container ->method('get') - ->will($this->returnCallback(function ($name) { - $dic = ['test.client' => $this->client]; + ->willReturnCallback(function ($name) use ($managerRegistry, $initializerManager) { + $dic = [ + 'test.client' => $this->client, + 'doctrine_phpcr' => $managerRegistry, + 'doctrine_phpcr.initializer_manager' => $initializerManager, + ]; 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') ; @@ -68,27 +73,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() - { - $class = new \ReflectionClass(BaseTestCase::class); - $method = $class->getMethod('getContainer'); - $method->setAccessible(true); - - $this->assertEquals($this->container, $method->invoke(null)); - } - - public function testGetKernel() + public function testGetKernel(): void { $class = new \ReflectionClass(BaseTestCase::class); $method = $class->getMethod('getKernel'); @@ -97,59 +88,12 @@ 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)); - } - } - - public function provideTestDb() - { - return [ - ['PHPCR', 'PHPCR'], - ['Phpcr', 'PHPCR'], - ['ORM', 'ORM'], - ['foobar', null], - ]; - } - - /** - * @dataProvider provideTestDb - * - * @depends testGetContainer - */ - public function testDb($dbName, $expected) - { - $class = new \ReflectionClass(BaseTestCase::class); - $method = $class->getMethod('getDbManager'); - $method->setAccessible(true); - - if (null === $expected) { - $this->expectException('InvalidArgumentException'); - $this->expectExceptionMessage($dbName.'" does not exist'); - } - - $res = $method->invoke($this->testCase, $dbName); - if (null === $expected) { - // do not do assertions if the expected exception has not been thrown. - return; - } - - $className = sprintf( - 'Symfony\Cmf\Component\Testing\Functional\DbManager\%s', - $expected - ); - if (PHPCR::class === $className && class_exists(RepositoryManager::class)) { - $className = RepositoryManager::class; - } - - $this->assertInstanceOf($className, $res); + $this->assertInstanceOf(KernelBrowser::class, $method->invoke($this->testCase)); } } From 9be0bcdc6bcf9389af79f5ca041de165383e0530 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 3 Apr 2024 22:21:04 +0200 Subject: [PATCH 4/9] explicitly disable controller resolver auto mapping to avoid doctrine deprecation warning --- resources/config/dist/doctrine_orm.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/config/dist/doctrine_orm.yml b/resources/config/dist/doctrine_orm.yml index 363512c..c616981 100644 --- a/resources/config/dist/doctrine_orm.yml +++ b/resources/config/dist/doctrine_orm.yml @@ -1,3 +1,5 @@ doctrine: orm: auto_mapping: true + controller_resolver: + auto_mapping: false From a00c429fbccc41e8070ae6228f5164b96fda2294 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 6 Apr 2024 10:17:32 +0200 Subject: [PATCH 5/9] remove workarounds for symfony 5 --- composer.json | 3 ++- resources/config/dist/security.php | 1 - src/Functional/BaseTestCase.php | 9 +-------- tests/Functional/BaseTestCaseTest.php | 4 +--- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 7321256..12d8681 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,9 @@ "symfony/phpunit-bridge": "^7.0.3" }, "conflict": { + "doctrine/phpcr-odm": "<2.0", "doctrine/phpcr-bundle": "<3.0", - "symfony/framework-bundle": "<5.4.6" + "symfony/framework-bundle": "<6.4" }, "autoload": { "psr-4": { diff --git a/resources/config/dist/security.php b/resources/config/dist/security.php index 3008522..57d1dc1 100644 --- a/resources/config/dist/security.php +++ b/resources/config/dist/security.php @@ -40,7 +40,6 @@ ], ]; - if (class_exists(\Symfony\Component\Security\Core\Security::class)) { // Symfony 6 but not 7 $config['enable_authenticator_manager'] = true; diff --git a/src/Functional/BaseTestCase.php b/src/Functional/BaseTestCase.php index 9d7b66e..022559e 100644 --- a/src/Functional/BaseTestCase.php +++ b/src/Functional/BaseTestCase.php @@ -143,14 +143,7 @@ protected function getDbManager(string $type) )); } - $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')); - } + $dbManager = new $className(self::getContainer()); $this->dbManagers[$type] = $dbManager; diff --git a/tests/Functional/BaseTestCaseTest.php b/tests/Functional/BaseTestCaseTest.php index f441da7..34ad8c3 100644 --- a/tests/Functional/BaseTestCaseTest.php +++ b/tests/Functional/BaseTestCaseTest.php @@ -18,6 +18,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\KernelBrowser; 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\HttpKernel\KernelInterface; @@ -86,7 +87,6 @@ public function testGetKernel(): void { $class = new \ReflectionClass(BaseTestCase::class); $method = $class->getMethod('getKernel'); - $method->setAccessible(true); $this->assertInstanceOf(KernelInterface::class, $method->invoke(null)); } @@ -95,7 +95,6 @@ public function testItCanProvideAFrameworkBundleClient(): void { $class = new \ReflectionClass(BaseTestCase::class); $method = $class->getMethod('getFrameworkBundleClient'); - $method->setAccessible(true); $this->assertInstanceOf(KernelBrowser::class, $method->invoke($this->testCase)); } @@ -117,7 +116,6 @@ public function testDb($dbName, $expected) { $class = new \ReflectionClass(BaseTestCase::class); $method = $class->getMethod('getDbManager'); - $method->setAccessible(true); if (null === $expected) { $this->expectException('InvalidArgumentException'); From ad232b99ef6b68eb5c6d21d1370ef6d3c8ce6add Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 6 Apr 2024 11:06:14 +0200 Subject: [PATCH 6/9] cleanup code for new symfony versions --- CHANGELOG.md | 7 ++++ composer.json | 3 ++ .../Compiler/TestContainerPass.php | 8 ++--- src/Functional/BaseTestCase.php | 7 ++-- src/Functional/DbManager/PHPCR.php | 2 +- src/HttpKernel/TestKernel.php | 34 ++++++++----------- tests/Fixtures/TestTestCase.php | 2 +- tests/Functional/BaseTestCaseTest.php | 27 ++++----------- .../Functional/HttpKernel/TestKernelTest.php | 18 +++++----- .../Unit/Constraint/SchemaAcceptsXmlTest.php | 8 ++--- tests/Unit/XmlSchemaTestCaseTest.php | 4 +-- 11 files changed, 52 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c7619a..613941c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,17 @@ Changelog 5.x === +5.0.1 +----- + +* Cleanup PHP 8.1 language features. +* Simplify configuration code. + 5.0.0 ----- * Drop support for Symfony < 6.4 +* Drop support for PHP < 8.1 * 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/composer.json b/composer.json index 12d8681..07dd10e 100644 --- a/composer.json +++ b/composer.json @@ -14,8 +14,11 @@ "symfony/browser-kit": "^6.4 || ^7.0" }, "require-dev": { + "ext-dom": "*", "doctrine/doctrine-bundle": "^1.8 || ^2.0", + "doctrine/phpcr-odm": "^2.0", "doctrine/phpcr-bundle": "^3.0", + "jackalope/jackalope-doctrine-dbal": "^2.0", "symfony/console": "^6.4 || ^7.0", "symfony/dependency-injection": "^6.4 || ^7.0", "symfony/doctrine-bridge": "^6.4 || ^7.0", diff --git a/src/DependencyInjection/Compiler/TestContainerPass.php b/src/DependencyInjection/Compiler/TestContainerPass.php index 5df4773..4514164 100644 --- a/src/DependencyInjection/Compiler/TestContainerPass.php +++ b/src/DependencyInjection/Compiler/TestContainerPass.php @@ -20,18 +20,16 @@ class TestContainerPass implements CompilerPassInterface { /** - * An array of service id's which should be public in a test scenario. - * - * @var array + * @var string[] Service id's which should be public in a test scenario */ - private $services = []; + private array $services; public function __construct(array $services = []) { $this->services = $services; } - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { foreach ($container->getDefinitions() as $id => $definition) { if (\in_array($id, $this->services, true)) { diff --git a/src/Functional/BaseTestCase.php b/src/Functional/BaseTestCase.php index 022559e..3a77b68 100644 --- a/src/Functional/BaseTestCase.php +++ b/src/Functional/BaseTestCase.php @@ -113,15 +113,12 @@ protected function getFrameworkBundleClient(): KernelBrowser * * @see self::getDbManager */ - protected function db($type) + protected function db(string $type): PhpcrDecorator|PHPCR|ORM { return $this->getDbManager($type); } - /** - * @return ORM|PHPCR - */ - protected function getDbManager(string $type) + protected function getDbManager(string $type): PhpcrDecorator|PHPCR|ORM { if (isset($this->dbManagers[$type])) { return $this->dbManagers[$type]; diff --git a/src/Functional/DbManager/PHPCR.php b/src/Functional/DbManager/PHPCR.php index 6f34cbb..f25b931 100644 --- a/src/Functional/DbManager/PHPCR.php +++ b/src/Functional/DbManager/PHPCR.php @@ -23,7 +23,7 @@ class PHPCR { - protected $container; + protected ContainerInterface $container; protected ?DocumentManager $om = null; diff --git a/src/HttpKernel/TestKernel.php b/src/HttpKernel/TestKernel.php index 8092d5b..bfc3343 100644 --- a/src/HttpKernel/TestKernel.php +++ b/src/HttpKernel/TestKernel.php @@ -32,9 +32,9 @@ */ abstract class TestKernel extends Kernel { - protected $bundleSets = []; + protected array $bundleSets = []; - protected $requiredBundles = []; + protected array $requiredBundles = []; /** * Register commonly needed bundle sets and then @@ -42,7 +42,7 @@ abstract class TestKernel extends Kernel * concrete kernel configure itself using the abstracvt * configure() command. */ - public function __construct($env, $debug) + public function __construct(string $env, bool $debug) { $defaultBundles = [ FrameworkBundle::class, @@ -72,7 +72,7 @@ public function __construct($env, $debug) * $this->addBundle(new MyBundle); * $this->addBundles(array(new Bundle1, new Bundle2)); */ - abstract protected function configure(); + abstract protected function configure(): void; /** * Register a set of bundles with the given name. @@ -80,15 +80,17 @@ abstract protected function configure(); * This method does not add the bundles to the kernel, * it just makes a set available. */ - public function registerBundleSet($name, $bundles) + public function registerBundleSet(string $name, array $bundles): void { $this->bundleSets[$name] = $bundles; } /** * The bundles in the named sets will be added to the Kernel. + * + * @param string[] $names */ - public function requireBundleSets(array $names) + public function requireBundleSets(array $names): void { foreach ($names as $name) { $this->requireBundleSet($name); @@ -102,7 +104,7 @@ public function requireBundleSets(array $names) * This enables us to declare pre-defined bundle sets without * worrying if the bundle is actually present or not. */ - public function requireBundleSet($name) + public function requireBundleSet(string $name): void { if (!isset($this->bundleSets[$name])) { throw new \InvalidArgumentException(sprintf( @@ -127,7 +129,7 @@ public function requireBundleSet($name) /** * Add concrete bundles to the kernel. */ - public function addBundles(array $bundles) + public function addBundles(array $bundles): void { foreach ($bundles as $bundle) { $this->addBundle($bundle); @@ -137,7 +139,7 @@ public function addBundles(array $bundles) /** * Add a concrete bundle to the kernel. */ - public function addBundle(BundleInterface $bundle) + public function addBundle(BundleInterface $bundle): void { $this->requiredBundles[] = $bundle; } @@ -153,28 +155,22 @@ public function registerBundles(): iterable } /** - * Returns the KernelDir of the CHILD class, + * Returns the project directory of the CHILD class, * i.e. the concrete implementation in the bundles * src/ directory (or wherever). */ - public function getKernelDir() - { - return $this->getProjectDir(); - } - public function getProjectDir(): string { $refl = new \ReflectionClass($this); $fname = $refl->getFileName(); - $kernelDir = \dirname($fname); - return $kernelDir; + return \dirname($fname); } public function getCacheDir(): string { return implode('/', [ - $this->getKernelDir(), + $this->getProjectDir(), 'var', 'cache', ]); @@ -192,7 +188,7 @@ public function getLogDir(): string /** * Registers the bundles defined in config/bundles.php. */ - protected function registerConfiguredBundles() + protected function registerConfiguredBundles(): void { $bundleFilePath = $this->getKernelDir().'/config/bundles.php'; if (!file_exists($bundleFilePath)) { diff --git a/tests/Fixtures/TestTestCase.php b/tests/Fixtures/TestTestCase.php index ca96891..17b2b4c 100644 --- a/tests/Fixtures/TestTestCase.php +++ b/tests/Fixtures/TestTestCase.php @@ -16,7 +16,7 @@ class TestTestCase extends BaseTestCase { - public function setKernel(KernelInterface $kernel) + public function setKernel(KernelInterface $kernel): void { static::$kernel = $kernel; } diff --git a/tests/Functional/BaseTestCaseTest.php b/tests/Functional/BaseTestCaseTest.php index 34ad8c3..dbfaa8c 100644 --- a/tests/Functional/BaseTestCaseTest.php +++ b/tests/Functional/BaseTestCaseTest.php @@ -25,25 +25,10 @@ class BaseTestCaseTest extends TestCase { - /** - * @var Container&MockObject - */ - private $container; - - /** - * @var KernelInterface&MockObject - */ - private $kernel; - - /** - * @var TestTestCase - */ - private $testCase; - - /** - * @var KernelBrowser&MockObject - */ - private $client; + private Container&MockObject $container; + private KernelInterface&MockObject $kernel; + private TestTestCase $testCase; + private KernelBrowser&MockObject $client; protected function setUp(): void { @@ -99,7 +84,7 @@ public function testItCanProvideAFrameworkBundleClient(): void $this->assertInstanceOf(KernelBrowser::class, $method->invoke($this->testCase)); } - public function provideTestDb() + public function provideTestDb(): array { return [ ['PHPCR', 'PHPCR'], @@ -112,7 +97,7 @@ public function provideTestDb() /** * @dataProvider provideTestDb */ - public function testDb($dbName, $expected) + public function testDb(string $dbName, string|null $expected): void { $class = new \ReflectionClass(BaseTestCase::class); $method = $class->getMethod('getDbManager'); diff --git a/tests/Functional/HttpKernel/TestKernelTest.php b/tests/Functional/HttpKernel/TestKernelTest.php index 775ce19..4d67acc 100644 --- a/tests/Functional/HttpKernel/TestKernelTest.php +++ b/tests/Functional/HttpKernel/TestKernelTest.php @@ -9,10 +9,11 @@ * file that was distributed with this source code. */ -namespace Symfony\Cmf\Component\Testing\Tests\HttpKernel; +namespace Symfony\Cmf\Component\Testing\Tests\Functional\HttpKernel; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; use Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\SecurityBundle\SecurityBundle; @@ -22,12 +23,9 @@ class TestKernelTest extends TestCase { - /** - * @var TestKernel - */ - private $kernel; + private TestKernel&MockObject $kernel; - private $mockBundle; + private BundleInterface&MockObject $mockBundle; protected function setUp(): void { @@ -41,7 +39,7 @@ protected function setUp(): void /** * @dataProvider bundleSetProvider */ - public function testBundleSetRequire(array $bundleSets, array $expectedBundles) + public function testBundleSetRequire(array $bundleSets, array $expectedBundles): void { $this->kernel->requireBundleSets($bundleSets); $bundles = array_keys($this->kernel->registerBundles()); @@ -52,7 +50,7 @@ public function testBundleSetRequire(array $bundleSets, array $expectedBundles) } } - public function bundleSetProvider() + public function bundleSetProvider(): array { return [ [['default'], [FrameworkBundle::class, SecurityBundle::class, TwigBundle::class]], @@ -61,7 +59,7 @@ public function bundleSetProvider() ]; } - public function testBundleAdd() + public function testBundleAdd(): void { $this->kernel->addBundle($this->mockBundle); $this->kernel->addBundle($this->mockBundle); @@ -69,7 +67,7 @@ public function testBundleAdd() $this->assertCount(2, $this->kernel->registerBundles()); } - public function testRequireInvalidBundleSet() + public function testRequireInvalidBundleSet(): void { $this->expectException(\InvalidArgumentException::class); $this->kernel->requireBundleSet('foobar'); diff --git a/tests/Unit/Constraint/SchemaAcceptsXmlTest.php b/tests/Unit/Constraint/SchemaAcceptsXmlTest.php index 898de98..91b2b7b 100644 --- a/tests/Unit/Constraint/SchemaAcceptsXmlTest.php +++ b/tests/Unit/Constraint/SchemaAcceptsXmlTest.php @@ -16,7 +16,7 @@ class SchemaAcceptsXmlTest extends TestCase { - public function testCount() + public function testCount(): void { $constraint = new SchemaAcceptsXml(['config1', 'config2', 'config3']); @@ -31,7 +31,7 @@ public function testCount() /** * @dataProvider getAssertingData */ - public function testAsserting($input, $schemaFile, $result, $message = null) + public function testAsserting($input, $schemaFile, $result, $message = null): void { $constraint = new SchemaAcceptsXml($input); @@ -47,7 +47,7 @@ public function testAsserting($input, $schemaFile, $result, $message = null) } } - public function getAssertingData() + public function getAssertingData(): array { $schema1 = __DIR__.'/../../Fixtures/schema/schema1.xsd'; @@ -68,7 +68,7 @@ public function getAssertingData() return $data; } - public function testFailsIfNoConfigElementIsAvailable() + public function testFailsIfNoConfigElementIsAvailable(): void { $dom = new \DOMDocument(); $dom->loadXML(''); diff --git a/tests/Unit/XmlSchemaTestCaseTest.php b/tests/Unit/XmlSchemaTestCaseTest.php index d02ea45..ea13d7f 100644 --- a/tests/Unit/XmlSchemaTestCaseTest.php +++ b/tests/Unit/XmlSchemaTestCaseTest.php @@ -15,14 +15,14 @@ class XmlSchemaTestCaseTest extends XmlSchemaTestCase { - public function testAcceptsSingleDomsWithoutArray() + public function testAcceptsSingleDomsWithoutArray(): void { $dom = new \DOMDocument(); $dom->loadXML(''); $this->assertSchemaAcceptsXml($dom, __DIR__.'/../Fixtures/schema/schema1.xsd'); } - public function testNegativeAssertion() + public function testNegativeAssertion(): void { $dom = new \DOMDocument(); $dom->loadXML(''); From d447691a44a0bfba8985a7d827a437dd205309b7 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 6 Apr 2024 11:30:59 +0200 Subject: [PATCH 7/9] add missing strict typing --- src/Functional/DbManager/PHPCR.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Functional/DbManager/PHPCR.php b/src/Functional/DbManager/PHPCR.php index f607441..4a86fab 100644 --- a/src/Functional/DbManager/PHPCR.php +++ b/src/Functional/DbManager/PHPCR.php @@ -75,7 +75,7 @@ public function loadFixtures(array $classes, bool $initialize = false): void /** * @param class-string|FixtureInterface $class */ - public function loadFixtureClass(Loader $loader, $class) + public function loadFixtureClass(Loader $loader, $class): void { if (\is_object($class)) { $fixture = $class; @@ -121,7 +121,7 @@ public function createTestNode(): void $session->save(); } - private function getExecutor($initialize = false): PHPCRExecutor + private function getExecutor(bool $initialize = false): PHPCRExecutor { static $lastInitialize = null; From 4c0c16cbd7ce2049cf003ea4c3e3b6af1acbda79 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 6 Apr 2024 11:35:47 +0200 Subject: [PATCH 8/9] prepare release --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d0ffd3..2cda5c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Changelog * Cleanup PHP 8.1 language features. * Simplify configuration code. +* Update with cleanups from symfony-cmf/testing 4.5.*. 5.0.0 ----- From d65e62414e257c679b4507c19cc4ede21e668204 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Sat, 6 Apr 2024 17:12:42 +0200 Subject: [PATCH 9/9] fix TestKernel --- CHANGELOG.md | 5 +++++ src/HttpKernel/TestKernel.php | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cda5c2..742867f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ Changelog 5.x === +5.0.2 +----- + +* Fixed regression in `TestKernel`. + 5.0.1 ----- diff --git a/src/HttpKernel/TestKernel.php b/src/HttpKernel/TestKernel.php index bfc3343..27b7b06 100644 --- a/src/HttpKernel/TestKernel.php +++ b/src/HttpKernel/TestKernel.php @@ -179,7 +179,7 @@ public function getCacheDir(): string public function getLogDir(): string { return implode('/', [ - $this->getKernelDir(), + $this->getProjectDir(), 'var', 'logs', ]); @@ -190,7 +190,7 @@ public function getLogDir(): string */ protected function registerConfiguredBundles(): void { - $bundleFilePath = $this->getKernelDir().'/config/bundles.php'; + $bundleFilePath = $this->getProjectDir().'/config/bundles.php'; if (!file_exists($bundleFilePath)) { return; } @@ -213,8 +213,8 @@ protected function registerConfiguredBundles(): void protected function build(ContainerBuilder $container): void { parent::build($container); - if (\in_array($this->getEnvironment(), ['test', 'phpcr']) && file_exists($this->getKernelDir().'/config/public_services.php')) { - $services = require $this->getKernelDir().'/config/public_services.php'; + if (\in_array($this->getEnvironment(), ['test', 'phpcr']) && file_exists($this->getProjectDir().'/config/public_services.php')) { + $services = require $this->getProjectDir().'/config/public_services.php'; $container->addCompilerPass(new TestContainerPass($services), PassConfig::TYPE_OPTIMIZE); } }