[Config] Backport type declarations

Signed-off-by: Alexander M. Turek <me@derrabus.de>
This commit is contained in:
Alexander M. Turek 2021-06-08 23:07:02 +02:00
parent 7957b48855
commit 46e18aff9b
28 changed files with 144 additions and 184 deletions

View File

@ -203,11 +203,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
} }
/** /**
* Finalizes the value of this node. * {@inheritdoc}
*
* @param mixed $value
*
* @return mixed The finalised value
* *
* @throws UnsetKeyException * @throws UnsetKeyException
* @throws InvalidConfigurationException if the node doesn't have enough children * @throws InvalidConfigurationException if the node doesn't have enough children
@ -249,11 +245,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
} }
/** /**
* Validates the type of the value. * {@inheritdoc}
*
* @param mixed $value
*
* @throws InvalidTypeException
*/ */
protected function validateType($value) protected function validateType($value)
{ {
@ -269,11 +261,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
} }
/** /**
* Normalizes the value. * {@inheritdoc}
*
* @param mixed $value The value to normalize
*
* @return mixed The normalized value
* *
* @throws InvalidConfigurationException * @throws InvalidConfigurationException
*/ */
@ -355,12 +343,7 @@ class ArrayNode extends BaseNode implements PrototypeNodeInterface
} }
/** /**
* Merges values together. * {@inheritdoc}
*
* @param mixed $leftSide The left side to merge
* @param mixed $rightSide The right side to merge
*
* @return mixed The merged values
* *
* @throws InvalidConfigurationException * @throws InvalidConfigurationException
* @throws \RuntimeException * @throws \RuntimeException

View File

@ -280,7 +280,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
->treatNullLike(['enabled' => true]) ->treatNullLike(['enabled' => true])
->beforeNormalization() ->beforeNormalization()
->ifArray() ->ifArray()
->then(function ($v) { ->then(function (array $v) {
$v['enabled'] = $v['enabled'] ?? true; $v['enabled'] = $v['enabled'] ?? true;
return $v; return $v;

View File

@ -37,7 +37,7 @@ class ExprBuilder
*/ */
public function always(\Closure $then = null) public function always(\Closure $then = null)
{ {
$this->ifPart = function ($v) { return true; }; $this->ifPart = function () { return true; };
if (null !== $then) { if (null !== $then) {
$this->thenPart = $then; $this->thenPart = $then;
@ -168,7 +168,7 @@ class ExprBuilder
*/ */
public function thenEmptyArray() public function thenEmptyArray()
{ {
$this->thenPart = function ($v) { return []; }; $this->thenPart = function () { return []; };
return $this; return $this;
} }
@ -200,7 +200,7 @@ class ExprBuilder
*/ */
public function thenUnset() public function thenUnset()
{ {
$this->thenPart = function ($v) { throw new UnsetKeyException('Unsetting key.'); }; $this->thenPart = function () { throw new UnsetKeyException('Unsetting key.'); };
return $this; return $this;
} }

View File

@ -26,7 +26,7 @@ abstract class NumericNodeDefinition extends ScalarNodeDefinition
/** /**
* Ensures that the value is smaller than the given reference. * Ensures that the value is smaller than the given reference.
* *
* @param mixed $max * @param int|float $max
* *
* @return $this * @return $this
* *
@ -45,7 +45,7 @@ abstract class NumericNodeDefinition extends ScalarNodeDefinition
/** /**
* Ensures that the value is bigger than the given reference. * Ensures that the value is bigger than the given reference.
* *
* @param mixed $min * @param int|float $min
* *
* @return $this * @return $this
* *

View File

@ -49,7 +49,7 @@ class XmlReferenceDumper
// xml remapping // xml remapping
if ($node->getParent()) { if ($node->getParent()) {
$remapping = array_filter($node->getParent()->getXmlRemappings(), function ($mapping) use ($rootName) { $remapping = array_filter($node->getParent()->getXmlRemappings(), function (array $mapping) use ($rootName) {
return $rootName === $mapping[1]; return $rootName === $mapping[1];
}); });

View File

@ -38,6 +38,9 @@ class EnumNode extends ScalarNode
return $this->values; return $this->values;
} }
/**
* {@inheritdoc}
*/
protected function finalizeValue($value) protected function finalizeValue($value)
{ {
$value = parent::finalizeValue($value); $value = parent::finalizeValue($value);

View File

@ -23,6 +23,10 @@ class NumericNode extends ScalarNode
protected $min; protected $min;
protected $max; protected $max;
/**
* @param int|float|null $min
* @param int|float|null $max
*/
public function __construct(?string $name, NodeInterface $parent = null, $min = null, $max = null, string $pathSeparator = BaseNode::DEFAULT_PATH_SEPARATOR) public function __construct(?string $name, NodeInterface $parent = null, $min = null, $max = null, string $pathSeparator = BaseNode::DEFAULT_PATH_SEPARATOR)
{ {
parent::__construct($name, $parent, $pathSeparator); parent::__construct($name, $parent, $pathSeparator);

View File

@ -173,14 +173,7 @@ class PrototypedArrayNode extends ArrayNode
} }
/** /**
* Finalizes the value of this node. * {@inheritdoc}
*
* @param mixed $value
*
* @return mixed The finalized value
*
* @throws UnsetKeyException
* @throws InvalidConfigurationException if the node doesn't have enough children
*/ */
protected function finalizeValue($value) protected function finalizeValue($value)
{ {
@ -208,13 +201,8 @@ class PrototypedArrayNode extends ArrayNode
} }
/** /**
* Normalizes the value. * {@inheritdoc}
* *
* @param mixed $value The value to normalize
*
* @return mixed The normalized value
*
* @throws InvalidConfigurationException
* @throws DuplicateKeyException * @throws DuplicateKeyException
*/ */
protected function normalizeValue($value) protected function normalizeValue($value)
@ -282,15 +270,7 @@ class PrototypedArrayNode extends ArrayNode
} }
/** /**
* Merges values together. * {@inheritdoc}
*
* @param mixed $leftSide The left side to merge
* @param mixed $rightSide The right side to merge
*
* @return mixed The merged values
*
* @throws InvalidConfigurationException
* @throws \RuntimeException
*/ */
protected function mergeValues($leftSide, $rightSide) protected function mergeValues($leftSide, $rightSide)
{ {

View File

@ -38,7 +38,7 @@ class ConfigCacheTest extends TestCase
/** /**
* @dataProvider debugModes * @dataProvider debugModes
*/ */
public function testCacheIsNotValidIfNothingHasBeenCached($debug) public function testCacheIsNotValidIfNothingHasBeenCached(bool $debug)
{ {
unlink($this->cacheFile); // remove tempnam() side effect unlink($this->cacheFile); // remove tempnam() side effect
$cache = new ConfigCache($this->cacheFile, $debug); $cache = new ConfigCache($this->cacheFile, $debug);
@ -60,7 +60,7 @@ class ConfigCacheTest extends TestCase
/** /**
* @dataProvider debugModes * @dataProvider debugModes
*/ */
public function testIsFreshWhenNoResourceProvided($debug) public function testIsFreshWhenNoResourceProvided(bool $debug)
{ {
$cache = new ConfigCache($this->cacheFile, $debug); $cache = new ConfigCache($this->cacheFile, $debug);
$cache->write('', []); $cache->write('', []);
@ -89,7 +89,7 @@ class ConfigCacheTest extends TestCase
$this->assertFalse($cache->isFresh()); $this->assertFalse($cache->isFresh());
} }
public function debugModes() public function debugModes(): array
{ {
return [ return [
[true], [true],

View File

@ -55,7 +55,7 @@ class ArrayNodeTest extends TestCase
$node->normalize(['beta' => 'foo']); $node->normalize(['beta' => 'foo']);
} }
public function ignoreAndRemoveMatrixProvider() public function ignoreAndRemoveMatrixProvider(): array
{ {
$unrecognizedOptionException = new InvalidConfigurationException('Unrecognized option "foo" under "root"'); $unrecognizedOptionException = new InvalidConfigurationException('Unrecognized option "foo" under "root"');
@ -68,9 +68,11 @@ class ArrayNodeTest extends TestCase
} }
/** /**
* @param array|\Exception $expected
*
* @dataProvider ignoreAndRemoveMatrixProvider * @dataProvider ignoreAndRemoveMatrixProvider
*/ */
public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $message = '') public function testIgnoreAndRemoveBehaviors(bool $ignore, bool $remove, $expected, string $message = '')
{ {
if ($expected instanceof \Exception) { if ($expected instanceof \Exception) {
$this->expectException(\get_class($expected)); $this->expectException(\get_class($expected));
@ -85,7 +87,7 @@ class ArrayNodeTest extends TestCase
/** /**
* @dataProvider getPreNormalizationTests * @dataProvider getPreNormalizationTests
*/ */
public function testPreNormalize($denormalized, $normalized) public function testPreNormalize(array $denormalized, array $normalized)
{ {
$node = new ArrayNode('foo'); $node = new ArrayNode('foo');
@ -95,7 +97,7 @@ class ArrayNodeTest extends TestCase
$this->assertSame($normalized, $r->invoke($node, $denormalized)); $this->assertSame($normalized, $r->invoke($node, $denormalized));
} }
public function getPreNormalizationTests() public function getPreNormalizationTests(): array
{ {
return [ return [
[ [
@ -120,7 +122,7 @@ class ArrayNodeTest extends TestCase
/** /**
* @dataProvider getZeroNamedNodeExamplesData * @dataProvider getZeroNamedNodeExamplesData
*/ */
public function testNodeNameCanBeZero($denormalized, $normalized) public function testNodeNameCanBeZero(array $denormalized, array $normalized)
{ {
$zeroNode = new ArrayNode(0); $zeroNode = new ArrayNode(0);
$zeroNode->addChild(new ScalarNode('name')); $zeroNode->addChild(new ScalarNode('name'));
@ -137,7 +139,7 @@ class ArrayNodeTest extends TestCase
$this->assertSame($normalized, $r->invoke($rootNode, $denormalized)); $this->assertSame($normalized, $r->invoke($rootNode, $denormalized));
} }
public function getZeroNamedNodeExamplesData() public function getZeroNamedNodeExamplesData(): array
{ {
return [ return [
[ [
@ -168,7 +170,7 @@ class ArrayNodeTest extends TestCase
/** /**
* @dataProvider getPreNormalizedNormalizedOrderedData * @dataProvider getPreNormalizedNormalizedOrderedData
*/ */
public function testChildrenOrderIsMaintainedOnNormalizeValue($prenormalized, $normalized) public function testChildrenOrderIsMaintainedOnNormalizeValue(array $prenormalized, array $normalized)
{ {
$scalar1 = new ScalarNode('1'); $scalar1 = new ScalarNode('1');
$scalar2 = new ScalarNode('2'); $scalar2 = new ScalarNode('2');
@ -184,7 +186,7 @@ class ArrayNodeTest extends TestCase
$this->assertSame($normalized, $r->invoke($node, $prenormalized)); $this->assertSame($normalized, $r->invoke($node, $prenormalized));
} }
public function getPreNormalizedNormalizedOrderedData() public function getPreNormalizedNormalizedOrderedData(): array
{ {
return [ return [
[ [
@ -260,7 +262,7 @@ class ArrayNodeTest extends TestCase
/** /**
* @dataProvider getDataWithIncludedExtraKeys * @dataProvider getDataWithIncludedExtraKeys
*/ */
public function testMergeWithoutIgnoringExtraKeys($prenormalizeds, $merged) public function testMergeWithoutIgnoringExtraKeys(array $prenormalizeds)
{ {
$this->expectException(\RuntimeException::class); $this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('merge() expects a normalized config array.'); $this->expectExceptionMessage('merge() expects a normalized config array.');
@ -278,7 +280,7 @@ class ArrayNodeTest extends TestCase
/** /**
* @dataProvider getDataWithIncludedExtraKeys * @dataProvider getDataWithIncludedExtraKeys
*/ */
public function testMergeWithIgnoringAndRemovingExtraKeys($prenormalizeds, $merged) public function testMergeWithIgnoringAndRemovingExtraKeys(array $prenormalizeds)
{ {
$this->expectException(\RuntimeException::class); $this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('merge() expects a normalized config array.'); $this->expectExceptionMessage('merge() expects a normalized config array.');
@ -296,7 +298,7 @@ class ArrayNodeTest extends TestCase
/** /**
* @dataProvider getDataWithIncludedExtraKeys * @dataProvider getDataWithIncludedExtraKeys
*/ */
public function testMergeWithIgnoringExtraKeys($prenormalizeds, $merged) public function testMergeWithIgnoringExtraKeys(array $prenormalizeds, array $merged)
{ {
$node = new ArrayNode('root'); $node = new ArrayNode('root');
$node->addChild(new ScalarNode('foo')); $node->addChild(new ScalarNode('foo'));
@ -309,7 +311,7 @@ class ArrayNodeTest extends TestCase
$this->assertEquals($merged, $r->invoke($node, ...$prenormalizeds)); $this->assertEquals($merged, $r->invoke($node, ...$prenormalizeds));
} }
public function getDataWithIncludedExtraKeys() public function getDataWithIncludedExtraKeys(): array
{ {
return [ return [
[ [

View File

@ -20,7 +20,7 @@ class BaseNodeTest extends TestCase
/** /**
* @dataProvider providePath * @dataProvider providePath
*/ */
public function testGetPathForChildNode($expected, array $params) public function testGetPathForChildNode(string $expected, array $params)
{ {
$constructorArgs = []; $constructorArgs = [];
$constructorArgs[] = $params[0]; $constructorArgs[] = $params[0];
@ -41,7 +41,7 @@ class BaseNodeTest extends TestCase
$this->assertSame($expected, $node->getPath()); $this->assertSame($expected, $node->getPath());
} }
public function providePath() public function providePath(): array
{ {
return [ return [
'name only' => ['root', ['root']], 'name only' => ['root', ['root']],

View File

@ -20,7 +20,7 @@ class BooleanNodeTest extends TestCase
/** /**
* @dataProvider getValidValues * @dataProvider getValidValues
*/ */
public function testNormalize($value) public function testNormalize(bool $value)
{ {
$node = new BooleanNode('test'); $node = new BooleanNode('test');
$this->assertSame($value, $node->normalize($value)); $this->assertSame($value, $node->normalize($value));
@ -28,10 +28,8 @@ class BooleanNodeTest extends TestCase
/** /**
* @dataProvider getValidValues * @dataProvider getValidValues
*
* @param bool $value
*/ */
public function testValidNonEmptyValues($value) public function testValidNonEmptyValues(bool $value)
{ {
$node = new BooleanNode('test'); $node = new BooleanNode('test');
$node->setAllowEmptyValue(false); $node->setAllowEmptyValue(false);
@ -39,7 +37,7 @@ class BooleanNodeTest extends TestCase
$this->assertSame($value, $node->finalize($value)); $this->assertSame($value, $node->finalize($value));
} }
public function getValidValues() public function getValidValues(): array
{ {
return [ return [
[false], [false],
@ -57,7 +55,7 @@ class BooleanNodeTest extends TestCase
$node->normalize($value); $node->normalize($value);
} }
public function getInvalidValues() public function getInvalidValues(): array
{ {
return [ return [
[null], [null],

View File

@ -42,7 +42,7 @@ class ArrayNodeDefinitionTest extends TestCase
/** /**
* @dataProvider providePrototypeNodeSpecificCalls * @dataProvider providePrototypeNodeSpecificCalls
*/ */
public function testPrototypeNodeSpecificOption($method, $args) public function testPrototypeNodeSpecificOption(string $method, array $args)
{ {
$this->expectException(InvalidDefinitionException::class); $this->expectException(InvalidDefinitionException::class);
$node = new ArrayNodeDefinition('root'); $node = new ArrayNodeDefinition('root');
@ -52,7 +52,7 @@ class ArrayNodeDefinitionTest extends TestCase
$node->getNode(); $node->getNode();
} }
public function providePrototypeNodeSpecificCalls() public function providePrototypeNodeSpecificCalls(): array
{ {
return [ return [
['defaultValue', [[]]], ['defaultValue', [[]]],
@ -98,9 +98,11 @@ class ArrayNodeDefinitionTest extends TestCase
} }
/** /**
* @param int|array|string|null $args
*
* @dataProvider providePrototypedArrayNodeDefaults * @dataProvider providePrototypedArrayNodeDefaults
*/ */
public function testPrototypedArrayNodeDefault($args, $shouldThrowWhenUsingAttrAsKey, $shouldThrowWhenNotUsingAttrAsKey, $defaults) public function testPrototypedArrayNodeDefault($args, bool $shouldThrowWhenUsingAttrAsKey, bool $shouldThrowWhenNotUsingAttrAsKey, array $defaults)
{ {
$node = new ArrayNodeDefinition('root'); $node = new ArrayNodeDefinition('root');
$node $node
@ -132,7 +134,7 @@ class ArrayNodeDefinitionTest extends TestCase
} }
} }
public function providePrototypedArrayNodeDefaults() public function providePrototypedArrayNodeDefaults(): array
{ {
return [ return [
[null, true, false, [[]]], [null, true, false, [[]]],
@ -173,7 +175,7 @@ class ArrayNodeDefinitionTest extends TestCase
/** /**
* @dataProvider getEnableableNodeFixtures * @dataProvider getEnableableNodeFixtures
*/ */
public function testTrueEnableEnabledNode($expected, $config, $message) public function testTrueEnableEnabledNode(array $expected, array $config, string $message)
{ {
$processor = new Processor(); $processor = new Processor();
$node = new ArrayNodeDefinition('root'); $node = new ArrayNodeDefinition('root');
@ -293,7 +295,7 @@ class ArrayNodeDefinitionTest extends TestCase
$this->assertEquals($node->prototype('enum'), $node->enumPrototype()); $this->assertEquals($node->prototype('enum'), $node->enumPrototype());
} }
public function getEnableableNodeFixtures() public function getEnableableNodeFixtures(): array
{ {
return [ return [
[['enabled' => true, 'foo' => 'bar'], [true], 'true enables an enableable node'], [['enabled' => true, 'foo' => 'bar'], [true], 'true enables an enableable node'],
@ -432,7 +434,10 @@ class ArrayNodeDefinitionTest extends TestCase
$this->assertSame($expectedName, $this->getField($actualNode, 'name')); $this->assertSame($expectedName, $this->getField($actualNode, 'name'));
} }
protected function getField($object, $field) /**
* @param object $object
*/
protected function getField($object, string $field)
{ {
$reflection = new \ReflectionProperty($object, $field); $reflection = new \ReflectionProperty($object, $field);
$reflection->setAccessible(true); $reflection->setAccessible(true);

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Config\Tests\Definition\Builder;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Builder\ExprBuilder; use Symfony\Component\Config\Definition\Builder\ExprBuilder;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
@ -36,13 +37,13 @@ class ExprBuilderTest extends TestCase
$this->assertFinalizedValueIs('new_value', $test, ['key' => true]); $this->assertFinalizedValueIs('new_value', $test, ['key' => true]);
$test = $this->getTestBuilder() $test = $this->getTestBuilder()
->ifTrue(function ($v) { return true; }) ->ifTrue(function () { return true; })
->then($this->returnClosure('new_value')) ->then($this->returnClosure('new_value'))
->end(); ->end();
$this->assertFinalizedValueIs('new_value', $test); $this->assertFinalizedValueIs('new_value', $test);
$test = $this->getTestBuilder() $test = $this->getTestBuilder()
->ifTrue(function ($v) { return false; }) ->ifTrue(function () { return false; })
->then($this->returnClosure('new_value')) ->then($this->returnClosure('new_value'))
->end(); ->end();
$this->assertFinalizedValueIs('value', $test); $this->assertFinalizedValueIs('value', $test);
@ -150,7 +151,7 @@ class ExprBuilderTest extends TestCase
/** /**
* @dataProvider castToArrayValues * @dataProvider castToArrayValues
*/ */
public function testCastToArrayExpression($configValue, $expectedValue) public function testCastToArrayExpression($configValue, array $expectedValue)
{ {
$test = $this->getTestBuilder() $test = $this->getTestBuilder()
->castToArray() ->castToArray()
@ -158,7 +159,7 @@ class ExprBuilderTest extends TestCase
$this->assertFinalizedValueIs($expectedValue, $test, ['key' => $configValue]); $this->assertFinalizedValueIs($expectedValue, $test, ['key' => $configValue]);
} }
public function castToArrayValues() public function castToArrayValues(): iterable
{ {
yield ['value', ['value']]; yield ['value', ['value']];
yield [-3.14, [-3.14]]; yield [-3.14, [-3.14]];
@ -219,20 +220,19 @@ class ExprBuilderTest extends TestCase
/** /**
* Close the validation process and finalize with the given config. * Close the validation process and finalize with the given config.
* *
* @param TreeBuilder $testBuilder The tree builder to finalize * @param array|null $config The config you want to use for the finalization, if nothing provided
* @param array $config The config you want to use for the finalization, if nothing provided * a simple ['key'=>'value'] will be used
* a simple ['key'=>'value'] will be used
* *
* @return array The finalized config values * @return array The finalized config values
*/ */
protected function finalizeTestBuilder($testBuilder, $config = null): array protected function finalizeTestBuilder(NodeDefinition $nodeDefinition, ?array $config = null): array
{ {
return $testBuilder return $nodeDefinition
->end() ->end()
->end() ->end()
->end() ->end()
->buildTree() ->buildTree()
->finalize(null === $config ? ['key' => 'value'] : $config) ->finalize($config ?? ['key' => 'value'])
; ;
} }
@ -243,7 +243,7 @@ class ExprBuilderTest extends TestCase
*/ */
protected function returnClosure($val): \Closure protected function returnClosure($val): \Closure
{ {
return function ($v) use ($val) { return function () use ($val) {
return $val; return $val;
}; };
} }
@ -251,12 +251,11 @@ class ExprBuilderTest extends TestCase
/** /**
* Assert that the given test builder, will return the given value. * Assert that the given test builder, will return the given value.
* *
* @param mixed $value The value to test * @param mixed $value The value to test
* @param TreeBuilder $treeBuilder The tree builder to finalize * @param mixed $config The config values that new to be finalized
* @param mixed $config The config values that new to be finalized
*/ */
protected function assertFinalizedValueIs($value, $treeBuilder, $config = null) protected function assertFinalizedValueIs($value, NodeDefinition $nodeDefinition, $config = null)
{ {
$this->assertEquals(['key' => $value], $this->finalizeTestBuilder($treeBuilder, $config)); $this->assertEquals(['key' => $value], $this->finalizeTestBuilder($nodeDefinition, $config));
} }
} }

View File

@ -26,7 +26,7 @@ class YamlReferenceDumperTest extends TestCase
$this->assertEquals($this->getConfigurationAsString(), $dumper->dump($configuration)); $this->assertEquals($this->getConfigurationAsString(), $dumper->dump($configuration));
} }
public function provideDumpAtPath() public function provideDumpAtPath(): array
{ {
return [ return [
'Regular node' => ['scalar_true', <<<EOL 'Regular node' => ['scalar_true', <<<EOL
@ -72,7 +72,7 @@ EOL
/** /**
* @dataProvider provideDumpAtPath * @dataProvider provideDumpAtPath
*/ */
public function testDumpAtPath($path, $expected) public function testDumpAtPath(string $path, string $expected)
{ {
$configuration = new ExampleConfiguration(); $configuration = new ExampleConfiguration();
@ -81,7 +81,7 @@ EOL
$this->assertSame(trim($expected), trim($dumper->dumpAtPath($configuration, $path))); $this->assertSame(trim($expected), trim($dumper->dumpAtPath($configuration, $path)));
} }
private function getConfigurationAsString() private function getConfigurationAsString(): string
{ {
return <<<'EOL' return <<<'EOL'
acme_root: acme_root:

View File

@ -19,6 +19,8 @@ class FloatNodeTest extends TestCase
{ {
/** /**
* @dataProvider getValidValues * @dataProvider getValidValues
*
* @param int|float $value
*/ */
public function testNormalize($value) public function testNormalize($value)
{ {
@ -29,7 +31,7 @@ class FloatNodeTest extends TestCase
/** /**
* @dataProvider getValidValues * @dataProvider getValidValues
* *
* @param int $value * @param int|float $value
*/ */
public function testValidNonEmptyValues($value) public function testValidNonEmptyValues($value)
{ {
@ -39,7 +41,7 @@ class FloatNodeTest extends TestCase
$this->assertSame($value, $node->finalize($value)); $this->assertSame($value, $node->finalize($value));
} }
public function getValidValues() public function getValidValues(): array
{ {
return [ return [
[1798.0], [1798.0],
@ -63,7 +65,7 @@ class FloatNodeTest extends TestCase
$node->normalize($value); $node->normalize($value);
} }
public function getInvalidValues() public function getInvalidValues(): array
{ {
return [ return [
[null], [null],

View File

@ -20,7 +20,7 @@ class IntegerNodeTest extends TestCase
/** /**
* @dataProvider getValidValues * @dataProvider getValidValues
*/ */
public function testNormalize($value) public function testNormalize(int $value)
{ {
$node = new IntegerNode('test'); $node = new IntegerNode('test');
$this->assertSame($value, $node->normalize($value)); $this->assertSame($value, $node->normalize($value));
@ -28,10 +28,8 @@ class IntegerNodeTest extends TestCase
/** /**
* @dataProvider getValidValues * @dataProvider getValidValues
*
* @param int $value
*/ */
public function testValidNonEmptyValues($value) public function testValidNonEmptyValues(int $value)
{ {
$node = new IntegerNode('test'); $node = new IntegerNode('test');
$node->setAllowEmptyValue(false); $node->setAllowEmptyValue(false);
@ -39,7 +37,7 @@ class IntegerNodeTest extends TestCase
$this->assertSame($value, $node->finalize($value)); $this->assertSame($value, $node->finalize($value));
} }
public function getValidValues() public function getValidValues(): array
{ {
return [ return [
[1798], [1798],
@ -58,7 +56,7 @@ class IntegerNodeTest extends TestCase
$node->normalize($value); $node->normalize($value);
} }
public function getInvalidValues() public function getInvalidValues(): array
{ {
return [ return [
[null], [null],

View File

@ -51,7 +51,7 @@ class NormalizationTest extends TestCase
$this->assertNormalized($tree, $denormalized, $normalized); $this->assertNormalized($tree, $denormalized, $normalized);
} }
public function getEncoderTests() public function getEncoderTests(): array
{ {
$configs = []; $configs = [];
@ -120,7 +120,7 @@ class NormalizationTest extends TestCase
$this->assertNormalized($tree, $denormalized, $normalized); $this->assertNormalized($tree, $denormalized, $normalized);
} }
public function getAnonymousKeysTests() public function getAnonymousKeysTests(): array
{ {
$configs = []; $configs = [];
@ -151,7 +151,7 @@ class NormalizationTest extends TestCase
$this->assertNormalized($this->getNumericKeysTestTree(), $denormalized, $normalized); $this->assertNormalized($this->getNumericKeysTestTree(), $denormalized, $normalized);
} }
public function getNumericKeysTests() public function getNumericKeysTests(): array
{ {
$configs = []; $configs = [];
@ -233,10 +233,9 @@ class NormalizationTest extends TestCase
self::assertSame($normalized, $tree->normalize($denormalized)); self::assertSame($normalized, $tree->normalize($denormalized));
} }
private function getNumericKeysTestTree() private function getNumericKeysTestTree(): NodeInterface
{ {
$tb = new TreeBuilder('root', 'array'); return (new TreeBuilder('root', 'array'))
$tree = $tb
->getRootNode() ->getRootNode()
->children() ->children()
->node('thing', 'array') ->node('thing', 'array')
@ -247,9 +246,6 @@ class NormalizationTest extends TestCase
->end() ->end()
->end() ->end()
->end() ->end()
->buildTree() ->buildTree();
;
return $tree;
} }
} }

View File

@ -264,7 +264,7 @@ class PrototypedArrayNodeTest extends TestCase
* *
* @dataProvider getDataForKeyRemovedLeftValueOnly * @dataProvider getDataForKeyRemovedLeftValueOnly
*/ */
public function testMappedAttributeKeyIsRemovedLeftValueOnly($value, $children, $expected) public function testMappedAttributeKeyIsRemovedLeftValueOnly($value, $children, array $expected)
{ {
$node = new PrototypedArrayNode('root'); $node = new PrototypedArrayNode('root');
$node->setKeyAttribute('id', true); $node->setKeyAttribute('id', true);
@ -280,7 +280,7 @@ class PrototypedArrayNodeTest extends TestCase
$this->assertEquals($expected, $normalized); $this->assertEquals($expected, $normalized);
} }
public function getDataForKeyRemovedLeftValueOnly() public function getDataForKeyRemovedLeftValueOnly(): array
{ {
$scalarValue = new ScalarNode('value'); $scalarValue = new ScalarNode('value');
@ -342,7 +342,7 @@ class PrototypedArrayNodeTest extends TestCase
/** /**
* @dataProvider getPrototypedArrayNodeDataToMerge * @dataProvider getPrototypedArrayNodeDataToMerge
*/ */
public function testPrototypedArrayNodeMerge($left, $right, $expected) public function testPrototypedArrayNodeMerge(array $left, array $right, array $expected)
{ {
$node = new PrototypedArrayNode('options'); $node = new PrototypedArrayNode('options');
$node->setNormalizeKeys(false); $node->setNormalizeKeys(false);
@ -354,7 +354,7 @@ class PrototypedArrayNodeTest extends TestCase
self::assertSame($result, $expected); self::assertSame($result, $expected);
} }
public function getPrototypedArrayNodeDataToMerge() public function getPrototypedArrayNodeDataToMerge(): array
{ {
return [ return [
// data to merged is a plain array // data to merged is a plain array

View File

@ -28,7 +28,7 @@ class ScalarNodeTest extends TestCase
$this->assertSame($value, $node->normalize($value)); $this->assertSame($value, $node->normalize($value));
} }
public function getValidValues() public function getValidValues(): array
{ {
return [ return [
[false], [false],
@ -84,7 +84,7 @@ class ScalarNodeTest extends TestCase
$node->normalize($value); $node->normalize($value);
} }
public function getInvalidValues() public function getInvalidValues(): array
{ {
return [ return [
[[]], [[]],
@ -127,7 +127,7 @@ class ScalarNodeTest extends TestCase
$this->assertSame($value, $node->finalize($value)); $this->assertSame($value, $node->finalize($value));
} }
public function getValidNonEmptyValues() public function getValidNonEmptyValues(): array
{ {
return [ return [
[false], [false],
@ -153,7 +153,7 @@ class ScalarNodeTest extends TestCase
$node->finalize($value); $node->finalize($value);
} }
public function getEmptyValues() public function getEmptyValues(): array
{ {
return [ return [
[null], [null],

View File

@ -20,7 +20,7 @@ class FileLocatorTest extends TestCase
/** /**
* @dataProvider getIsAbsolutePathTests * @dataProvider getIsAbsolutePathTests
*/ */
public function testIsAbsolutePath($path) public function testIsAbsolutePath(string $path)
{ {
$loader = new FileLocator([]); $loader = new FileLocator([]);
$r = new \ReflectionObject($loader); $r = new \ReflectionObject($loader);
@ -30,7 +30,7 @@ class FileLocatorTest extends TestCase
$this->assertTrue($m->invoke($loader, $path), '->isAbsolutePath() returns true for an absolute path'); $this->assertTrue($m->invoke($loader, $path), '->isAbsolutePath() returns true for an absolute path');
} }
public function getIsAbsolutePathTests() public function getIsAbsolutePathTests(): array
{ {
return [ return [
['/foo.xml'], ['/foo.xml'],

View File

@ -12,10 +12,11 @@
namespace Symfony\Component\Config\Tests\Fixtures\Builder; namespace Symfony\Component\Config\Tests\Fixtures\Builder;
use Symfony\Component\Config\Definition\Builder\NodeBuilder as BaseNodeBuilder; use Symfony\Component\Config\Definition\Builder\NodeBuilder as BaseNodeBuilder;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
class NodeBuilder extends BaseNodeBuilder class NodeBuilder extends BaseNodeBuilder
{ {
public function barNode($name) public function barNode($name): NodeDefinition
{ {
return $this->node($name, 'bar'); return $this->node($name, 'bar');
} }
@ -23,9 +24,8 @@ class NodeBuilder extends BaseNodeBuilder
protected function getNodeClass($type): string protected function getNodeClass($type): string
{ {
switch ($type) { switch ($type) {
case 'variable':
return __NAMESPACE__.'\\'.ucfirst($type).'NodeDefinition';
case 'bar': case 'bar':
case 'variable':
return __NAMESPACE__.'\\'.ucfirst($type).'NodeDefinition'; return __NAMESPACE__.'\\'.ucfirst($type).'NodeDefinition';
default: default:
return parent::getNodeClass($type); return parent::getNodeClass($type);

View File

@ -7,22 +7,22 @@ use Symfony\Component\Config\Definition\NodeInterface;
class CustomNode implements NodeInterface class CustomNode implements NodeInterface
{ {
public function getName() public function getName(): string
{ {
return 'custom_node'; return 'custom_node';
} }
public function getPath() public function getPath(): string
{ {
return 'custom'; return 'custom';
} }
public function isRequired() public function isRequired(): bool
{ {
return false; return false;
} }
public function hasDefaultValue() public function hasDefaultValue(): bool
{ {
return true; return true;
} }

View File

@ -165,22 +165,12 @@ class TestFileLoader extends FileLoader
return $this->supports; return $this->supports;
} }
public function addLoading($resource) public function addLoading(string $resource): void
{ {
self::$loading[$resource] = true; self::$loading[$resource] = true;
} }
public function removeLoading($resource) public function setSupports(bool $supports): void
{
unset(self::$loading[$resource]);
}
public function clearLoading()
{
self::$loading = [];
}
public function setSupports($supports)
{ {
$this->supports = $supports; $this->supports = $supports;
} }

View File

@ -35,7 +35,7 @@ class DirectoryResourceTest extends TestCase
$this->removeDirectory($this->directory); $this->removeDirectory($this->directory);
} }
protected function removeDirectory($directory) protected function removeDirectory(string $directory): void
{ {
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory), \RecursiveIteratorIterator::CHILD_FIRST); $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory), \RecursiveIteratorIterator::CHILD_FIRST);
foreach ($iterator as $path) { foreach ($iterator as $path) {

View File

@ -64,7 +64,7 @@ class ReflectionClassResourceTest extends TestCase
/** /**
* @dataProvider provideHashedSignature * @dataProvider provideHashedSignature
*/ */
public function testHashedSignature($changeExpected, $changedLine, $changedCode, $setContext = null) public function testHashedSignature(bool $changeExpected, int $changedLine, ?string $changedCode, ?\Closure $setContext = null)
{ {
if ($setContext) { if ($setContext) {
$setContext(); $setContext();
@ -117,43 +117,43 @@ EOPHP;
} }
} }
public function provideHashedSignature() public function provideHashedSignature(): iterable
{ {
yield [0, 0, "// line change\n\n"]; yield [false, 0, "// line change\n\n"];
yield [1, 0, '/** class docblock */']; yield [true, 0, '/** class docblock */'];
yield [1, 1, 'abstract class %s']; yield [true, 1, 'abstract class %s'];
yield [1, 1, 'final class %s']; yield [true, 1, 'final class %s'];
yield [1, 1, 'class %s extends Exception']; yield [true, 1, 'class %s extends Exception'];
yield [1, 1, 'class %s implements '.DummyInterface::class]; yield [true, 1, 'class %s implements '.DummyInterface::class];
yield [1, 3, 'const FOO = 456;']; yield [true, 3, 'const FOO = 456;'];
yield [1, 3, 'const BAR = 123;']; yield [true, 3, 'const BAR = 123;'];
yield [1, 4, '/** pub docblock */']; yield [true, 4, '/** pub docblock */'];
yield [1, 5, 'protected $pub = [];']; yield [true, 5, 'protected $pub = [];'];
yield [1, 5, 'public $pub = [123];']; yield [true, 5, 'public $pub = [123];'];
yield [1, 6, '/** prot docblock */']; yield [true, 6, '/** prot docblock */'];
yield [1, 7, 'private $prot;']; yield [true, 7, 'private $prot;'];
yield [0, 8, '/** priv docblock */']; yield [false, 8, '/** priv docblock */'];
yield [0, 9, 'private $priv = 123;']; yield [false, 9, 'private $priv = 123;'];
yield [1, 10, '/** pub docblock */']; yield [true, 10, '/** pub docblock */'];
yield [1, 11, 'public function pub(...$arg) {}']; yield [true, 11, 'public function pub(...$arg) {}'];
yield [1, 11, 'public function pub($arg = null): Foo {}']; yield [true, 11, 'public function pub($arg = null): Foo {}'];
yield [0, 11, "public function pub(\$arg = null) {\nreturn 123;\n}"]; yield [false, 11, "public function pub(\$arg = null) {\nreturn 123;\n}"];
yield [1, 12, '/** prot docblock */']; yield [true, 12, '/** prot docblock */'];
yield [1, 13, 'protected function prot($a = [123]) {}']; yield [true, 13, 'protected function prot($a = [123]) {}'];
yield [0, 14, '/** priv docblock */']; yield [false, 14, '/** priv docblock */'];
yield [0, 15, '']; yield [false, 15, ''];
if (\PHP_VERSION_ID >= 70400) { if (\PHP_VERSION_ID >= 70400) {
// PHP7.4 typed properties without default value are // PHP7.4 typed properties without default value are
// undefined, make sure this doesn't throw an error // undefined, make sure this doesn't throw an error
yield [1, 5, 'public array $pub;']; yield [true, 5, 'public array $pub;'];
yield [0, 7, 'protected int $prot;']; yield [false, 7, 'protected int $prot;'];
yield [0, 9, 'private string $priv;']; yield [false, 9, 'private string $priv;'];
} }
yield [1, 17, 'public function ccc($bar = 187) {}']; yield [true, 17, 'public function ccc($bar = 187) {}'];
yield [1, 17, 'public function ccc($bar = ANOTHER_ONE_THAT_WILL_NEVER_BE_DEFINED_CCCCCCCCC) {}']; yield [true, 17, 'public function ccc($bar = ANOTHER_ONE_THAT_WILL_NEVER_BE_DEFINED_CCCCCCCCC) {}'];
yield [1, 17, null, static function () { \define('A_CONSTANT_THAT_FOR_SURE_WILL_NEVER_BE_DEFINED_CCCCCC', 'foo'); }]; yield [true, 17, null, static function () { \define('A_CONSTANT_THAT_FOR_SURE_WILL_NEVER_BE_DEFINED_CCCCCC', 'foo'); }];
} }
public function testEventSubscriber() public function testEventSubscriber()

View File

@ -17,7 +17,7 @@ class ResourceStub implements SelfCheckingResourceInterface
{ {
private $fresh = true; private $fresh = true;
public function setFresh($isFresh) public function setFresh(bool $isFresh): void
{ {
$this->fresh = $isFresh; $this->fresh = $isFresh;
} }

View File

@ -116,7 +116,7 @@ class XmlUtilsTest extends TestCase
/** /**
* @dataProvider getDataForConvertDomToArray * @dataProvider getDataForConvertDomToArray
*/ */
public function testConvertDomToArray($expected, $xml, $root = false, $checkPrefix = true) public function testConvertDomToArray($expected, string $xml, bool $root = false, bool $checkPrefix = true)
{ {
$dom = new \DOMDocument(); $dom = new \DOMDocument();
$dom->loadXML($root ? $xml : '<root>'.$xml.'</root>'); $dom->loadXML($root ? $xml : '<root>'.$xml.'</root>');
@ -124,7 +124,7 @@ class XmlUtilsTest extends TestCase
$this->assertSame($expected, XmlUtils::convertDomElementToArray($dom->documentElement, $checkPrefix)); $this->assertSame($expected, XmlUtils::convertDomElementToArray($dom->documentElement, $checkPrefix));
} }
public function getDataForConvertDomToArray() public function getDataForConvertDomToArray(): array
{ {
return [ return [
[null, ''], [null, ''],
@ -155,7 +155,7 @@ class XmlUtilsTest extends TestCase
$this->assertSame($expected, XmlUtils::phpize($value)); $this->assertSame($expected, XmlUtils::phpize($value));
} }
public function getDataForPhpize() public function getDataForPhpize(): array
{ {
return [ return [
['', ''], ['', ''],