Skip to content

Commit ad232b9

Browse files
committed
cleanup code for new symfony versions
1 parent d00ae5a commit ad232b9

File tree

11 files changed

+52
-68
lines changed

11 files changed

+52
-68
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ Changelog
44
5.x
55
===
66

7+
5.0.1
8+
-----
9+
10+
* Cleanup PHP 8.1 language features.
11+
* Simplify configuration code.
12+
713
5.0.0
814
-----
915

1016
* Drop support for Symfony < 6.4
17+
* Drop support for PHP < 8.1
1118
* The default framework configuration no longer enables validation attributes.
1219
* The PHPCR-ODM additional namespace is expected to use attributes rather than annotations.
1320

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
"symfony/browser-kit": "^6.4 || ^7.0"
1515
},
1616
"require-dev": {
17+
"ext-dom": "*",
1718
"doctrine/doctrine-bundle": "^1.8 || ^2.0",
19+
"doctrine/phpcr-odm": "^2.0",
1820
"doctrine/phpcr-bundle": "^3.0",
21+
"jackalope/jackalope-doctrine-dbal": "^2.0",
1922
"symfony/console": "^6.4 || ^7.0",
2023
"symfony/dependency-injection": "^6.4 || ^7.0",
2124
"symfony/doctrine-bridge": "^6.4 || ^7.0",

src/DependencyInjection/Compiler/TestContainerPass.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,16 @@
2020
class TestContainerPass implements CompilerPassInterface
2121
{
2222
/**
23-
* An array of service id's which should be public in a test scenario.
24-
*
25-
* @var array
23+
* @var string[] Service id's which should be public in a test scenario
2624
*/
27-
private $services = [];
25+
private array $services;
2826

2927
public function __construct(array $services = [])
3028
{
3129
$this->services = $services;
3230
}
3331

34-
public function process(ContainerBuilder $container)
32+
public function process(ContainerBuilder $container): void
3533
{
3634
foreach ($container->getDefinitions() as $id => $definition) {
3735
if (\in_array($id, $this->services, true)) {

src/Functional/BaseTestCase.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,12 @@ protected function getFrameworkBundleClient(): KernelBrowser
113113
*
114114
* @see self::getDbManager
115115
*/
116-
protected function db($type)
116+
protected function db(string $type): PhpcrDecorator|PHPCR|ORM
117117
{
118118
return $this->getDbManager($type);
119119
}
120120

121-
/**
122-
* @return ORM|PHPCR
123-
*/
124-
protected function getDbManager(string $type)
121+
protected function getDbManager(string $type): PhpcrDecorator|PHPCR|ORM
125122
{
126123
if (isset($this->dbManagers[$type])) {
127124
return $this->dbManagers[$type];

src/Functional/DbManager/PHPCR.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
class PHPCR
2525
{
26-
protected $container;
26+
protected ContainerInterface $container;
2727

2828
protected ?DocumentManager $om = null;
2929

src/HttpKernel/TestKernel.php

+15-19
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@
3232
*/
3333
abstract class TestKernel extends Kernel
3434
{
35-
protected $bundleSets = [];
35+
protected array $bundleSets = [];
3636

37-
protected $requiredBundles = [];
37+
protected array $requiredBundles = [];
3838

3939
/**
4040
* Register commonly needed bundle sets and then
4141
* after initializing the parent kernel, let the
4242
* concrete kernel configure itself using the abstracvt
4343
* configure() command.
4444
*/
45-
public function __construct($env, $debug)
45+
public function __construct(string $env, bool $debug)
4646
{
4747
$defaultBundles = [
4848
FrameworkBundle::class,
@@ -72,23 +72,25 @@ public function __construct($env, $debug)
7272
* $this->addBundle(new MyBundle);
7373
* $this->addBundles(array(new Bundle1, new Bundle2));
7474
*/
75-
abstract protected function configure();
75+
abstract protected function configure(): void;
7676

7777
/**
7878
* Register a set of bundles with the given name.
7979
*
8080
* This method does not add the bundles to the kernel,
8181
* it just makes a set available.
8282
*/
83-
public function registerBundleSet($name, $bundles)
83+
public function registerBundleSet(string $name, array $bundles): void
8484
{
8585
$this->bundleSets[$name] = $bundles;
8686
}
8787

8888
/**
8989
* The bundles in the named sets will be added to the Kernel.
90+
*
91+
* @param string[] $names
9092
*/
91-
public function requireBundleSets(array $names)
93+
public function requireBundleSets(array $names): void
9294
{
9395
foreach ($names as $name) {
9496
$this->requireBundleSet($name);
@@ -102,7 +104,7 @@ public function requireBundleSets(array $names)
102104
* This enables us to declare pre-defined bundle sets without
103105
* worrying if the bundle is actually present or not.
104106
*/
105-
public function requireBundleSet($name)
107+
public function requireBundleSet(string $name): void
106108
{
107109
if (!isset($this->bundleSets[$name])) {
108110
throw new \InvalidArgumentException(sprintf(
@@ -127,7 +129,7 @@ public function requireBundleSet($name)
127129
/**
128130
* Add concrete bundles to the kernel.
129131
*/
130-
public function addBundles(array $bundles)
132+
public function addBundles(array $bundles): void
131133
{
132134
foreach ($bundles as $bundle) {
133135
$this->addBundle($bundle);
@@ -137,7 +139,7 @@ public function addBundles(array $bundles)
137139
/**
138140
* Add a concrete bundle to the kernel.
139141
*/
140-
public function addBundle(BundleInterface $bundle)
142+
public function addBundle(BundleInterface $bundle): void
141143
{
142144
$this->requiredBundles[] = $bundle;
143145
}
@@ -153,28 +155,22 @@ public function registerBundles(): iterable
153155
}
154156

155157
/**
156-
* Returns the KernelDir of the CHILD class,
158+
* Returns the project directory of the CHILD class,
157159
* i.e. the concrete implementation in the bundles
158160
* src/ directory (or wherever).
159161
*/
160-
public function getKernelDir()
161-
{
162-
return $this->getProjectDir();
163-
}
164-
165162
public function getProjectDir(): string
166163
{
167164
$refl = new \ReflectionClass($this);
168165
$fname = $refl->getFileName();
169-
$kernelDir = \dirname($fname);
170166

171-
return $kernelDir;
167+
return \dirname($fname);
172168
}
173169

174170
public function getCacheDir(): string
175171
{
176172
return implode('/', [
177-
$this->getKernelDir(),
173+
$this->getProjectDir(),
178174
'var',
179175
'cache',
180176
]);
@@ -192,7 +188,7 @@ public function getLogDir(): string
192188
/**
193189
* Registers the bundles defined in config/bundles.php.
194190
*/
195-
protected function registerConfiguredBundles()
191+
protected function registerConfiguredBundles(): void
196192
{
197193
$bundleFilePath = $this->getKernelDir().'/config/bundles.php';
198194
if (!file_exists($bundleFilePath)) {

tests/Fixtures/TestTestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class TestTestCase extends BaseTestCase
1818
{
19-
public function setKernel(KernelInterface $kernel)
19+
public function setKernel(KernelInterface $kernel): void
2020
{
2121
static::$kernel = $kernel;
2222
}

tests/Functional/BaseTestCaseTest.php

+6-21
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,10 @@
2525

2626
class BaseTestCaseTest extends TestCase
2727
{
28-
/**
29-
* @var Container&MockObject
30-
*/
31-
private $container;
32-
33-
/**
34-
* @var KernelInterface&MockObject
35-
*/
36-
private $kernel;
37-
38-
/**
39-
* @var TestTestCase
40-
*/
41-
private $testCase;
42-
43-
/**
44-
* @var KernelBrowser&MockObject
45-
*/
46-
private $client;
28+
private Container&MockObject $container;
29+
private KernelInterface&MockObject $kernel;
30+
private TestTestCase $testCase;
31+
private KernelBrowser&MockObject $client;
4732

4833
protected function setUp(): void
4934
{
@@ -99,7 +84,7 @@ public function testItCanProvideAFrameworkBundleClient(): void
9984
$this->assertInstanceOf(KernelBrowser::class, $method->invoke($this->testCase));
10085
}
10186

102-
public function provideTestDb()
87+
public function provideTestDb(): array
10388
{
10489
return [
10590
['PHPCR', 'PHPCR'],
@@ -112,7 +97,7 @@ public function provideTestDb()
11297
/**
11398
* @dataProvider provideTestDb
11499
*/
115-
public function testDb($dbName, $expected)
100+
public function testDb(string $dbName, string|null $expected): void
116101
{
117102
$class = new \ReflectionClass(BaseTestCase::class);
118103
$method = $class->getMethod('getDbManager');

tests/Functional/HttpKernel/TestKernelTest.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Cmf\Component\Testing\Tests\HttpKernel;
12+
namespace Symfony\Cmf\Component\Testing\Tests\Functional\HttpKernel;
1313

1414
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
1515
use Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle;
16+
use PHPUnit\Framework\MockObject\MockObject;
1617
use PHPUnit\Framework\TestCase;
1718
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
1819
use Symfony\Bundle\SecurityBundle\SecurityBundle;
@@ -22,12 +23,9 @@
2223

2324
class TestKernelTest extends TestCase
2425
{
25-
/**
26-
* @var TestKernel
27-
*/
28-
private $kernel;
26+
private TestKernel&MockObject $kernel;
2927

30-
private $mockBundle;
28+
private BundleInterface&MockObject $mockBundle;
3129

3230
protected function setUp(): void
3331
{
@@ -41,7 +39,7 @@ protected function setUp(): void
4139
/**
4240
* @dataProvider bundleSetProvider
4341
*/
44-
public function testBundleSetRequire(array $bundleSets, array $expectedBundles)
42+
public function testBundleSetRequire(array $bundleSets, array $expectedBundles): void
4543
{
4644
$this->kernel->requireBundleSets($bundleSets);
4745
$bundles = array_keys($this->kernel->registerBundles());
@@ -52,7 +50,7 @@ public function testBundleSetRequire(array $bundleSets, array $expectedBundles)
5250
}
5351
}
5452

55-
public function bundleSetProvider()
53+
public function bundleSetProvider(): array
5654
{
5755
return [
5856
[['default'], [FrameworkBundle::class, SecurityBundle::class, TwigBundle::class]],
@@ -61,15 +59,15 @@ public function bundleSetProvider()
6159
];
6260
}
6361

64-
public function testBundleAdd()
62+
public function testBundleAdd(): void
6563
{
6664
$this->kernel->addBundle($this->mockBundle);
6765
$this->kernel->addBundle($this->mockBundle);
6866

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

72-
public function testRequireInvalidBundleSet()
70+
public function testRequireInvalidBundleSet(): void
7371
{
7472
$this->expectException(\InvalidArgumentException::class);
7573
$this->kernel->requireBundleSet('foobar');

tests/Unit/Constraint/SchemaAcceptsXmlTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class SchemaAcceptsXmlTest extends TestCase
1818
{
19-
public function testCount()
19+
public function testCount(): void
2020
{
2121
$constraint = new SchemaAcceptsXml(['config1', 'config2', 'config3']);
2222

@@ -31,7 +31,7 @@ public function testCount()
3131
/**
3232
* @dataProvider getAssertingData
3333
*/
34-
public function testAsserting($input, $schemaFile, $result, $message = null)
34+
public function testAsserting($input, $schemaFile, $result, $message = null): void
3535
{
3636
$constraint = new SchemaAcceptsXml($input);
3737

@@ -47,7 +47,7 @@ public function testAsserting($input, $schemaFile, $result, $message = null)
4747
}
4848
}
4949

50-
public function getAssertingData()
50+
public function getAssertingData(): array
5151
{
5252
$schema1 = __DIR__.'/../../Fixtures/schema/schema1.xsd';
5353

@@ -68,7 +68,7 @@ public function getAssertingData()
6868
return $data;
6969
}
7070

71-
public function testFailsIfNoConfigElementIsAvailable()
71+
public function testFailsIfNoConfigElementIsAvailable(): void
7272
{
7373
$dom = new \DOMDocument();
7474
$dom->loadXML('<container></container>');

tests/Unit/XmlSchemaTestCaseTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515

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

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

0 commit comments

Comments
 (0)