Skip to content

Commit 61f88c8

Browse files
greg0ireNyholm
authored andcommitted
Final keywords (#115)
* Close the API This will make BC-breaks less likely, and will encourage users to contribute enhancements rather than relying on methode override. * Remove duplicate implementation
1 parent ba42f80 commit 61f88c8

17 files changed

+49
-45
lines changed

Loader/Exception/UnknownConfigurationSourceException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
namespace Matthias\SymfonyDependencyInjectionTest\Loader\Exception;
44

5-
class UnknownConfigurationSourceException extends \InvalidArgumentException
5+
final class UnknownConfigurationSourceException extends \InvalidArgumentException
66
{
77
}

Loader/ExtensionConfigurationBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Symfony\Component\DependencyInjection\ContainerBuilder;
66
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
77

8-
class ExtensionConfigurationBuilder
8+
final class ExtensionConfigurationBuilder
99
{
1010
private $extension;
1111
private $sources = [];

Loader/LoaderFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1313
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
1414

15-
class LoaderFactory implements LoaderFactoryInterface
15+
final class LoaderFactory implements LoaderFactoryInterface
1616
{
1717
public function createLoaderForSource(ContainerBuilder $container, $source): LoaderInterface
1818
{

PhpUnit/AbstractCompilerPassTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract protected function registerCompilerPass(ContainerBuilder $container): v
1919
*
2020
* @test
2121
*/
22-
public function compilation_should_not_fail_with_empty_container(): void
22+
final public function compilation_should_not_fail_with_empty_container(): void
2323
{
2424
try {
2525
$this->compile();

PhpUnit/AbstractContainerBuilderTestCase.php

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function tearDown(): void
3030
/**
3131
* Shortcut for quickly defining services. The returned Definition object can be further modified if necessary.
3232
*/
33-
protected function registerService(string $serviceId, string $class): Definition
33+
final protected function registerService(string $serviceId, string $class): Definition
3434
{
3535
$definition = new Definition($class);
3636

@@ -42,7 +42,7 @@ protected function registerService(string $serviceId, string $class): Definition
4242
/**
4343
* Set a service definition you manually created.
4444
*/
45-
protected function setDefinition(string $serviceId, Definition $definition): void
45+
final protected function setDefinition(string $serviceId, Definition $definition): void
4646
{
4747
$this->container->setDefinition($serviceId, $definition);
4848
}
@@ -52,24 +52,26 @@ protected function setDefinition(string $serviceId, Definition $definition): voi
5252
*
5353
* @param mixed $parameterValue
5454
*/
55-
protected function setParameter(string $parameterId, $parameterValue): void
55+
final protected function setParameter(string $parameterId, $parameterValue): void
5656
{
5757
$this->container->setParameter($parameterId, $parameterValue);
5858
}
5959

6060
/**
6161
* Call this method to compile the ContainerBuilder, to test if any problems would occur at runtime.
6262
*/
63-
protected function compile(): void
63+
final protected function compile(): void
6464
{
6565
$this->container->compile();
6666
}
6767

6868
/**
6969
* Assert that the ContainerBuilder for this test has a service definition with the given id and class.
7070
*/
71-
protected function assertContainerBuilderHasService(string $serviceId, ?string $expectedClass = null): void
72-
{
71+
final protected function assertContainerBuilderHasService(
72+
string $serviceId,
73+
?string $expectedClass = null
74+
): void {
7375
$checkExpectedClass = (func_num_args() > 1);
7476

7577
self::assertThat(
@@ -81,7 +83,7 @@ protected function assertContainerBuilderHasService(string $serviceId, ?string $
8183
/**
8284
* Assert that the ContainerBuilder for this test does not have a service definition with the given id.
8385
*/
84-
protected function assertContainerBuilderNotHasService(string $serviceId): void
86+
final protected function assertContainerBuilderNotHasService(string $serviceId): void
8587
{
8688
self::assertThat(
8789
$this->container,
@@ -92,7 +94,7 @@ protected function assertContainerBuilderNotHasService(string $serviceId): void
9294
/**
9395
* Assert that the ContainerBuilder for this test has a synthetic service with the given id.
9496
*/
95-
protected function assertContainerBuilderHasSyntheticService(string $serviceId): void
97+
final protected function assertContainerBuilderHasSyntheticService(string $serviceId): void
9698
{
9799
self::assertThat(
98100
$this->container,
@@ -103,8 +105,10 @@ protected function assertContainerBuilderHasSyntheticService(string $serviceId):
103105
/**
104106
* Assert that the ContainerBuilder for this test has an alias and that it is an alias for the given service id.
105107
*/
106-
protected function assertContainerBuilderHasAlias(string $aliasId, ?string $expectedServiceId = null): void
107-
{
108+
final protected function assertContainerBuilderHasAlias(
109+
string $aliasId,
110+
?string $expectedServiceId = null
111+
): void {
108112
self::assertThat(
109113
$this->container,
110114
new ContainerBuilderHasAliasConstraint($aliasId, $expectedServiceId)
@@ -116,8 +120,10 @@ protected function assertContainerBuilderHasAlias(string $aliasId, ?string $expe
116120
*
117121
* @param mixed $expectedParameterValue
118122
*/
119-
protected function assertContainerBuilderHasParameter(string $parameterName, $expectedParameterValue = null): void
120-
{
123+
final protected function assertContainerBuilderHasParameter(
124+
string $parameterName,
125+
$expectedParameterValue = null
126+
): void {
121127
$checkParameterValue = (func_num_args() > 1);
122128

123129
self::assertThat(
@@ -132,7 +138,7 @@ protected function assertContainerBuilderHasParameter(string $parameterName, $ex
132138
*
133139
* @param mixed $expectedValue
134140
*/
135-
protected function assertContainerBuilderHasServiceDefinitionWithArgument(
141+
final protected function assertContainerBuilderHasServiceDefinitionWithArgument(
136142
string $serviceId,
137143
$argumentIndex,
138144
$expectedValue = null
@@ -153,7 +159,7 @@ protected function assertContainerBuilderHasServiceDefinitionWithArgument(
153159
* @param int|string $argumentIndex
154160
* @param array $expectedServiceMap an array of service-id references and their key in the map
155161
*/
156-
protected function assertContainerBuilderHasServiceDefinitionWithServiceLocatorArgument(
162+
final protected function assertContainerBuilderHasServiceDefinitionWithServiceLocatorArgument(
157163
string $serviceId,
158164
$argumentIndex,
159165
array $expectedValue
@@ -170,7 +176,7 @@ protected function assertContainerBuilderHasServiceDefinitionWithServiceLocatorA
170176
*
171177
* @param int|null $index
172178
*/
173-
protected function assertContainerBuilderHasServiceDefinitionWithMethodCall(
179+
final protected function assertContainerBuilderHasServiceDefinitionWithMethodCall(
174180
string $serviceId,
175181
string $method,
176182
array $arguments = [],
@@ -185,7 +191,7 @@ protected function assertContainerBuilderHasServiceDefinitionWithMethodCall(
185191
* Assert that the ContainerBuilder for this test has a service definition with the given id, which has a tag
186192
* with the given attributes.
187193
*/
188-
protected function assertContainerBuilderHasServiceDefinitionWithTag(
194+
final protected function assertContainerBuilderHasServiceDefinitionWithTag(
189195
string $serviceId,
190196
string $tag,
191197
array $attributes = []
@@ -199,8 +205,10 @@ protected function assertContainerBuilderHasServiceDefinitionWithTag(
199205
* Assert that the ContainerBuilder for this test has a service definition with the given id which is a decorated
200206
* service and it has the given parent service.
201207
*/
202-
protected function assertContainerBuilderHasServiceDefinitionWithParent(string $serviceId, string $parentServiceId): void
203-
{
208+
final protected function assertContainerBuilderHasServiceDefinitionWithParent(
209+
string $serviceId,
210+
string $parentServiceId
211+
): void {
204212
$definition = $this->container->findDefinition($serviceId);
205213

206214
self::assertThat($definition, new DefinitionIsChildOfConstraint($parentServiceId));
@@ -211,8 +219,10 @@ protected function assertContainerBuilderHasServiceDefinitionWithParent(string $
211219
*
212220
* @param array $expectedServiceMap an array of service-id references and their key in the map
213221
*/
214-
protected function assertContainerBuilderHasServiceLocator(string $serviceId, array $expectedServiceMap = []): void
215-
{
222+
final protected function assertContainerBuilderHasServiceLocator(
223+
string $serviceId,
224+
array $expectedServiceMap = []
225+
): void {
216226
$definition = $this->container->findDefinition($serviceId);
217227

218228
// Service locator was provided as context (and therefor a factory)

PhpUnit/AbstractExtensionConfigurationTestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ abstract protected function getContainerExtension(): ExtensionInterface;
2121
*/
2222
abstract protected function getConfiguration(): ConfigurationInterface;
2323

24-
protected function assertProcessedConfigurationEquals(array $expectedConfiguration, array $sources): void
25-
{
24+
final protected function assertProcessedConfigurationEquals(
25+
array $expectedConfiguration,
26+
array $sources
27+
): void {
2628
$extensionConfigurationBuilder = new ExtensionConfigurationBuilder(new LoaderFactory());
2729
$extensionConfiguration = $extensionConfigurationBuilder
2830
->setExtension($this->getContainerExtension())

PhpUnit/AbstractExtensionTestCase.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function setUp(): void
4545
* Call this method from within your test after you have (optionally) modified the ContainerBuilder for this test
4646
* ($this->container).
4747
*/
48-
protected function load(array $configurationValues = []): void
48+
final protected function load(array $configurationValues = []): void
4949
{
5050
$configs = [$this->getMinimalConfiguration(), $configurationValues];
5151

@@ -57,12 +57,4 @@ protected function load(array $configurationValues = []): void
5757
$extension->load($configs, $this->container);
5858
}
5959
}
60-
61-
/**
62-
* Call this method if you want to compile the ContainerBuilder *inside* the test instead of *after* the test.
63-
*/
64-
protected function compile(): void
65-
{
66-
$this->container->compile();
67-
}
6860
}

PhpUnit/ContainerBuilderHasAliasConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use PHPUnit\Framework\Constraint\IsEqual;
77
use Symfony\Component\DependencyInjection\ContainerBuilder;
88

9-
class ContainerBuilderHasAliasConstraint extends Constraint
9+
final class ContainerBuilderHasAliasConstraint extends Constraint
1010
{
1111
private $aliasId;
1212
private $expectedServiceId;

PhpUnit/ContainerBuilderHasServiceDefinitionConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use PHPUnit\Framework\Constraint\IsEqual;
77
use Symfony\Component\DependencyInjection\ContainerBuilder;
88

9-
class ContainerBuilderHasServiceDefinitionConstraint extends Constraint
9+
final class ContainerBuilderHasServiceDefinitionConstraint extends Constraint
1010
{
1111
private $serviceId;
1212
private $expectedClass;

PhpUnit/ContainerBuilderHasSyntheticServiceConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use PHPUnit\Framework\Constraint\Constraint;
66
use Symfony\Component\DependencyInjection\ContainerBuilder;
77

8-
class ContainerBuilderHasSyntheticServiceConstraint extends Constraint
8+
final class ContainerBuilderHasSyntheticServiceConstraint extends Constraint
99
{
1010
private $serviceId;
1111

0 commit comments

Comments
 (0)