diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 0be5657..22ce986 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -14,32 +14,23 @@ 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: - include: - - php-version: '7.2' - dependencies: 'lowest' - symfony-version: '^5.4' - symfony-deprecation-helper: 'weak' - - php-version: '7.3' - symfony-version: '*' - - php-version: '7.4' - 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' + fail-fast: false + matrix: + include: + - php-version: '8.1' + dependencies: 'lowest' + symfony-version: '^6.4' + - 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 @@ -48,7 +39,7 @@ jobs: tools: composer:v2, flex - 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 ef12e28..742867f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,29 @@ Changelog ========= +5.x +=== + +5.0.2 +----- + +* Fixed regression in `TestKernel`. + +5.0.1 +----- + +* Cleanup PHP 8.1 language features. +* Simplify configuration code. +* Update with cleanups from symfony-cmf/testing 4.5.*. + +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. + 4.x === 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 97a64de..07dd10e 100644 --- a/composer.json +++ b/composer.json @@ -9,26 +9,30 @@ } ], "require": { - "php": "^7.2|^8.0", + "php": "^8.1", "doctrine/data-fixtures": "^1.2", - "symfony/browser-kit": "^5.4 || ^6.0 || ^7.0" + "symfony/browser-kit": "^6.4 || ^7.0" }, "require-dev": { + "ext-dom": "*", "doctrine/doctrine-bundle": "^1.8 || ^2.0", - "doctrine/phpcr-bundle": "^1.3 || ^2.0 || ^3.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", + "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", + "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.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" + "symfony/security-bundle": "^6.4 || ^7.0", + "symfony/twig-bundle": "^6.4 || ^7.0", + "symfony/phpunit-bridge": "^7.0.3" }, "conflict": { - "symfony/framework-bundle": "<5.4.6" + "doctrine/phpcr-odm": "<2.0", + "doctrine/phpcr-bundle": "<3.0", + "symfony/framework-bundle": "<6.4" }, "autoload": { "psr-4": { 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/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 diff --git a/resources/config/dist/framework.php b/resources/config/dist/framework.php index 73ef908..bf9c84e 100644 --- a/resources/config/dist/framework.php +++ b/resources/config/dist/framework.php @@ -9,11 +9,6 @@ * 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' => true, @@ -22,7 +17,7 @@ 'enabled' => true, ], 'router' => [ - 'resource' => $routerPath, + 'resource' => '%kernel.project_dir%/config/routing.php', ], 'default_locale' => 'en', 'translator' => [ @@ -33,11 +28,6 @@ ], ]; -if (class_exists(\Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::class)) { - // Symfony < 7 - $config['validation']['enable_annotations'] = true; -} - $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 26b08c7..57d1dc1 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'], @@ -38,20 +35,14 @@ ], ], ], + 'password_hashers' => [ + 'Symfony\Component\Security\Core\User\User' => 'plaintext', + ], ]; -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']); - $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; - } +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/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 845ba68..3a77b68 100644 --- a/src/Functional/BaseTestCase.php +++ b/src/Functional/BaseTestCase.php @@ -12,7 +12,6 @@ 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; @@ -31,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. @@ -101,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; @@ -122,15 +113,12 @@ protected function getFrameworkBundleClient() * * @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]; @@ -152,21 +140,14 @@ 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; 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 0ae6622..4a86fab 100644 --- a/src/Functional/DbManager/PHPCR.php +++ b/src/Functional/DbManager/PHPCR.php @@ -17,7 +17,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; @@ -25,27 +24,18 @@ class PHPCR { - protected $container; + protected ContainerInterface $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'); } @@ -85,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; @@ -131,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; 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 8092d5b..27b7b06 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', ]); @@ -183,7 +179,7 @@ public function getCacheDir(): string public function getLogDir(): string { return implode('/', [ - $this->getKernelDir(), + $this->getProjectDir(), 'var', 'logs', ]); @@ -192,9 +188,9 @@ 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'; + $bundleFilePath = $this->getProjectDir().'/config/bundles.php'; if (!file_exists($bundleFilePath)) { return; } @@ -217,8 +213,8 @@ protected function registerConfiguredBundles() 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); } } 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 22f0b1b..dbfaa8c 100644 --- a/tests/Functional/BaseTestCaseTest.php +++ b/tests/Functional/BaseTestCaseTest.php @@ -12,58 +12,37 @@ 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; 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\Container; -use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\KernelInterface; class BaseTestCaseTest extends TestCase { - /** - * @var ContainerInterface&MockObject - */ - private $container; - - /** - * @var KernelInterface&MockObject - */ - private $kernel; - - /** - * @var TestTestCase - */ - private $testCase; - - /** - * @var KernelBrowser|Client|MockObject - */ - private $client; + private Container&MockObject $container; + private KernelInterface&MockObject $kernel; + private TestTestCase $testCase; + private KernelBrowser&MockObject $client; protected function setUp(): void { - $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); + $managerRegistry = $this->createMock(ManagerRegistryInterface::class); + $initializerManager = $this->createMock(InitializerManager::class); + $this->container = $this->createMock(Container::class); $this->container ->method('get') - ->willReturnCallback(function ($name) use ($managerRegistry) { + ->willReturnCallback(function ($name) use ($managerRegistry, $initializerManager) { $dic = [ 'test.client' => $this->client, 'test.service_container' => $this->container, 'doctrine_phpcr' => $managerRegistry, - 'doctrine_phpcr.initializer_manager' => $this->createMock(InitializerManager::class), + 'doctrine_phpcr.initializer_manager' => $initializerManager, ]; return $dic[$name]; @@ -82,40 +61,30 @@ 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 = $this->createMock(KernelBrowser::class); $this->client ->method('getContainer') ->willReturn($this->container); } - public function testGetKernel() + public function testGetKernel(): void { $class = new \ReflectionClass(BaseTestCase::class); $method = $class->getMethod('getKernel'); - $method->setAccessible(true); $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'], @@ -128,11 +97,10 @@ 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'); - $method->setAccessible(true); if (null === $expected) { $this->expectException('InvalidArgumentException'); 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('');