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('');