Skip to content

Commit

Permalink
Merge pull request #221 from symfony-cmf/cleanup
Browse files Browse the repository at this point in the history
cleanup code for new symfony versions
  • Loading branch information
dbu authored Apr 6, 2024
2 parents d00ae5a + ad232b9 commit c85c4cd
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 68 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 3 additions & 5 deletions src/DependencyInjection/Compiler/TestContainerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
7 changes: 2 additions & 5 deletions src/Functional/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/DbManager/PHPCR.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

class PHPCR
{
protected $container;
protected ContainerInterface $container;

protected ?DocumentManager $om = null;

Expand Down
34 changes: 15 additions & 19 deletions src/HttpKernel/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
*/
abstract class TestKernel extends Kernel
{
protected $bundleSets = [];
protected array $bundleSets = [];

protected $requiredBundles = [];
protected array $requiredBundles = [];

/**
* Register commonly needed bundle sets and then
* after initializing the parent kernel, let the
* concrete kernel configure itself using the abstracvt
* configure() command.
*/
public function __construct($env, $debug)
public function __construct(string $env, bool $debug)
{
$defaultBundles = [
FrameworkBundle::class,
Expand Down Expand Up @@ -72,23 +72,25 @@ 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.
*
* 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);
Expand All @@ -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(
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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',
]);
Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/TestTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class TestTestCase extends BaseTestCase
{
public function setKernel(KernelInterface $kernel)
public function setKernel(KernelInterface $kernel): void
{
static::$kernel = $kernel;
}
Expand Down
27 changes: 6 additions & 21 deletions tests/Functional/BaseTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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'],
Expand All @@ -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');
Expand Down
18 changes: 8 additions & 10 deletions tests/Functional/HttpKernel/TestKernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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());
Expand All @@ -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]],
Expand All @@ -61,15 +59,15 @@ public function bundleSetProvider()
];
}

public function testBundleAdd()
public function testBundleAdd(): void
{
$this->kernel->addBundle($this->mockBundle);
$this->kernel->addBundle($this->mockBundle);

$this->assertCount(2, $this->kernel->registerBundles());
}

public function testRequireInvalidBundleSet()
public function testRequireInvalidBundleSet(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->kernel->requireBundleSet('foobar');
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Constraint/SchemaAcceptsXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class SchemaAcceptsXmlTest extends TestCase
{
public function testCount()
public function testCount(): void
{
$constraint = new SchemaAcceptsXml(['config1', 'config2', 'config3']);

Expand All @@ -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);

Expand All @@ -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';

Expand All @@ -68,7 +68,7 @@ public function getAssertingData()
return $data;
}

public function testFailsIfNoConfigElementIsAvailable()
public function testFailsIfNoConfigElementIsAvailable(): void
{
$dom = new \DOMDocument();
$dom->loadXML('<container></container>');
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/XmlSchemaTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@

class XmlSchemaTestCaseTest extends XmlSchemaTestCase
{
public function testAcceptsSingleDomsWithoutArray()
public function testAcceptsSingleDomsWithoutArray(): void
{
$dom = new \DOMDocument();
$dom->loadXML('<container><config xmlns="http://cmf.symfony.com/schema/dic/foo" required="f"/></container>');
$this->assertSchemaAcceptsXml($dom, __DIR__.'/../Fixtures/schema/schema1.xsd');
}

public function testNegativeAssertion()
public function testNegativeAssertion(): void
{
$dom = new \DOMDocument();
$dom->loadXML('<container><config xmlns="http://cmf.symfony.com/schema/dic/foo" /></container>');
Expand Down

0 comments on commit c85c4cd

Please sign in to comment.