diff --git a/UPGRADE-8.0.md b/UPGRADE-8.0.md index 8b9055d500f55..3509c12969eae 100644 --- a/UPGRADE-8.0.md +++ b/UPGRADE-8.0.md @@ -12,6 +12,25 @@ HttpClient * Remove support for amphp/http-client < 5 * Remove setLogger() methods on decorators; configure the logger on the wrapped client directly instead +OptionsResolver +--------------- + + * Remove support for nested options definition via `setDefault()`, use `setOptions()` instead + + *Before* + ```php + $resolver->setDefault('option', function (OptionsResolver $resolver) { + // ... + }); + ``` + + *After* + ```php + $resolver->setOptions('option', function (OptionsResolver $resolver) { + // ... + }); + ``` + TwigBridge ---------- diff --git a/src/Symfony/Component/OptionsResolver/CHANGELOG.md b/src/Symfony/Component/OptionsResolver/CHANGELOG.md index 5bdc9e3f5863f..81a11ef2a9836 100644 --- a/src/Symfony/Component/OptionsResolver/CHANGELOG.md +++ b/src/Symfony/Component/OptionsResolver/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +8.0 +--- + +* Remove support for nested options definition via `setDefault()`, use `setOptions()` instead + 7.3 --- diff --git a/src/Symfony/Component/OptionsResolver/OptionsResolver.php b/src/Symfony/Component/OptionsResolver/OptionsResolver.php index 82ca9166ee09d..4eed96c86ba90 100644 --- a/src/Symfony/Component/OptionsResolver/OptionsResolver.php +++ b/src/Symfony/Component/OptionsResolver/OptionsResolver.php @@ -229,22 +229,6 @@ public function setDefault(string $option, mixed $value): static return $this; } - - // Remove in Symfony 8.0. - if (isset($params[0]) && ($type = $params[0]->getType()) instanceof \ReflectionNamedType && self::class === $type->getName() && (!isset($params[1]) || (($type = $params[1]->getType()) instanceof \ReflectionNamedType && Options::class === $type->getName()))) { - trigger_deprecation('symfony/options-resolver', '7.3', 'Defining nested options via "%s()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.', __METHOD__); - $this->deprecatedNestedOptions[$option] = true; - - // Store closure for later evaluation - $this->nested[$option][] = $value; - $this->defaults[$option] = []; - $this->defined[$option] = true; - - // Make sure the option is processed and is not lazy anymore - unset($this->resolved[$option], $this->lazy[$option]); - - return $this; - } } // This option is not lazy anymore diff --git a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php index 411e161696c43..38b88ba92fb09 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php +++ b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php @@ -1094,44 +1094,6 @@ public function testFailIfSetAllowedValuesFromLazyOption() $this->resolver->resolve(); } - /** - * @group legacy - */ - public function testLegacyResolveFailsIfInvalidValueFromNestedOption() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefault('foo', function (OptionsResolver $resolver) { - $resolver - ->setDefined('bar') - ->setAllowedValues('bar', 'valid value'); - }); - - $this->expectException(InvalidOptionsException::class); - $this->expectExceptionMessage('The option "foo[bar]" with value "invalid value" is invalid. Accepted values are: "valid value".'); - - $this->resolver->resolve(['foo' => ['bar' => 'invalid value']]); - } - - /** - * @group legacy - */ - public function testLegacyResolveFailsIfInvalidTypeFromNestedOption() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefault('foo', function (OptionsResolver $resolver) { - $resolver - ->setDefined('bar') - ->setAllowedTypes('bar', 'string'); - }); - - $this->expectException(InvalidOptionsException::class); - $this->expectExceptionMessage('The option "foo[bar]" with value 1 is expected to be of type "string", but is of type "int".'); - - $this->resolver->resolve(['foo' => ['bar' => 1]]); - } - public function testResolveFailsIfInvalidValue() { $this->expectException(InvalidOptionsException::class); @@ -2111,438 +2073,6 @@ public function testNestedArrayException5() ]); } - /** - * @group legacy - */ - public function testLegacyIsNestedOption() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefaults([ - 'database' => function (OptionsResolver $resolver) { - $resolver->setDefined(['host', 'port']); - }, - ]); - $this->assertTrue($this->resolver->isNested('database')); - } - - /** - * @group legacy - */ - public function testLegacyFailsIfUndefinedNestedOption() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefaults([ - 'name' => 'default', - 'database' => function (OptionsResolver $resolver) { - $resolver->setDefined(['host', 'port']); - }, - ]); - - $this->expectException(UndefinedOptionsException::class); - $this->expectExceptionMessage('The option "database[foo]" does not exist. Defined options are: "host", "port".'); - - $this->resolver->resolve([ - 'database' => ['foo' => 'bar'], - ]); - } - - /** - * @group legacy - */ - public function testLegacyFailsIfMissingRequiredNestedOption() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefaults([ - 'name' => 'default', - 'database' => function (OptionsResolver $resolver) { - $resolver->setRequired('host'); - }, - ]); - - $this->expectException(MissingOptionsException::class); - $this->expectExceptionMessage('The required option "database[host]" is missing.'); - - $this->resolver->resolve([ - 'database' => [], - ]); - } - - /** - * @group legacy - */ - public function testLegacyFailsIfInvalidTypeNestedOption() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefaults([ - 'name' => 'default', - 'database' => function (OptionsResolver $resolver) { - $resolver - ->setDefined('logging') - ->setAllowedTypes('logging', 'bool'); - }, - ]); - - $this->expectException(InvalidOptionsException::class); - $this->expectExceptionMessage('The option "database[logging]" with value null is expected to be of type "bool", but is of type "null".'); - - $this->resolver->resolve([ - 'database' => ['logging' => null], - ]); - } - - /** - * @group legacy - */ - public function testLegacyFailsIfNotArrayIsGivenForNestedOptions() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefaults([ - 'name' => 'default', - 'database' => function (OptionsResolver $resolver) { - $resolver->setDefined('host'); - }, - ]); - - $this->expectException(InvalidOptionsException::class); - $this->expectExceptionMessage('The nested option "database" with value null is expected to be of type array, but is of type "null".'); - - $this->resolver->resolve([ - 'database' => null, - ]); - } - - /** - * @group legacy - */ - public function testLegacyResolveNestedOptionsWithoutDefault() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefaults([ - 'name' => 'default', - 'database' => function (OptionsResolver $resolver) { - $resolver->setDefined(['host', 'port']); - }, - ]); - $actualOptions = $this->resolver->resolve(); - $expectedOptions = [ - 'name' => 'default', - 'database' => [], - ]; - $this->assertSame($expectedOptions, $actualOptions); - } - - /** - * @group legacy - */ - public function testLegacyResolveNestedOptionsWithDefault() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefaults([ - 'name' => 'default', - 'database' => function (OptionsResolver $resolver) { - $resolver->setDefaults([ - 'host' => 'localhost', - 'port' => 3306, - ]); - }, - ]); - $actualOptions = $this->resolver->resolve(); - $expectedOptions = [ - 'name' => 'default', - 'database' => [ - 'host' => 'localhost', - 'port' => 3306, - ], - ]; - $this->assertSame($expectedOptions, $actualOptions); - } - - /** - * @group legacy - */ - public function testLegacyResolveMultipleNestedOptions() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefaults([ - 'name' => 'default', - 'database' => function (OptionsResolver $resolver) { - $resolver - ->setRequired(['dbname', 'host']) - ->setDefaults([ - 'port' => 3306, - 'replicas' => function (OptionsResolver $resolver) { - $resolver->setDefaults([ - 'host' => 'replica1', - 'port' => 3306, - ]); - }, - ]); - }, - ]); - $actualOptions = $this->resolver->resolve([ - 'name' => 'custom', - 'database' => [ - 'dbname' => 'test', - 'host' => 'localhost', - 'port' => null, - 'replicas' => ['host' => 'replica2'], - ], - ]); - $expectedOptions = [ - 'name' => 'custom', - 'database' => [ - 'port' => null, - 'replicas' => ['port' => 3306, 'host' => 'replica2'], - 'dbname' => 'test', - 'host' => 'localhost', - ], - ]; - $this->assertSame($expectedOptions, $actualOptions); - } - - /** - * @group legacy - */ - public function testLegacyResolveLazyOptionUsingNestedOption() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefaults([ - 'version' => fn (Options $options) => $options['database']['server_version'], - 'database' => function (OptionsResolver $resolver) { - $resolver->setDefault('server_version', '3.15'); - }, - ]); - $actualOptions = $this->resolver->resolve(); - $expectedOptions = [ - 'database' => ['server_version' => '3.15'], - 'version' => '3.15', - ]; - $this->assertSame($expectedOptions, $actualOptions); - } - - /** - * @group legacy - */ - public function testLegacyNormalizeNestedOptionValue() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver - ->setDefaults([ - 'database' => function (OptionsResolver $resolver) { - $resolver->setDefaults([ - 'port' => 3306, - 'host' => 'localhost', - 'dbname' => 'demo', - ]); - }, - ]) - ->setNormalizer('database', function (Options $options, $value) { - ksort($value); - - return $value; - }); - $actualOptions = $this->resolver->resolve([ - 'database' => ['dbname' => 'test'], - ]); - $expectedOptions = [ - 'database' => ['dbname' => 'test', 'host' => 'localhost', 'port' => 3306], - ]; - $this->assertSame($expectedOptions, $actualOptions); - } - - /** - * @group legacy - */ - public function testOverwrittenNestedOptionNotEvaluatedIfLazyDefault() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - // defined by superclass - $this->resolver->setDefault('foo', function (OptionsResolver $resolver) { - Assert::fail('Should not be called'); - }); - // defined by subclass - $this->resolver->setDefault('foo', fn (Options $options) => 'lazy'); - $this->assertSame(['foo' => 'lazy'], $this->resolver->resolve()); - } - - /** - * @group legacy - */ - public function testOverwrittenNestedOptionNotEvaluatedIfScalarDefault() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - // defined by superclass - $this->resolver->setDefault('foo', function (OptionsResolver $resolver) { - Assert::fail('Should not be called'); - }); - // defined by subclass - $this->resolver->setDefault('foo', 'bar'); - $this->assertSame(['foo' => 'bar'], $this->resolver->resolve()); - } - - /** - * @group legacy - */ - public function testOverwrittenLazyOptionNotEvaluatedIfNestedOption() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - // defined by superclass - $this->resolver->setDefault('foo', function (Options $options) { - Assert::fail('Should not be called'); - }); - // defined by subclass - $this->resolver->setDefault('foo', function (OptionsResolver $resolver) { - $resolver->setDefault('bar', 'baz'); - }); - $this->assertSame(['foo' => ['bar' => 'baz']], $this->resolver->resolve()); - } - - /** - * @group legacy - */ - public function testLegacyResolveAllNestedOptionDefinitions() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - // defined by superclass - $this->resolver->setDefault('foo', function (OptionsResolver $resolver) { - $resolver->setRequired('bar'); - }); - // defined by subclass - $this->resolver->setDefault('foo', function (OptionsResolver $resolver) { - $resolver->setDefault('bar', 'baz'); - }); - // defined by subclass - $this->resolver->setDefault('foo', function (OptionsResolver $resolver) { - $resolver->setDefault('ping', 'pong'); - }); - $this->assertSame(['foo' => ['ping' => 'pong', 'bar' => 'baz']], $this->resolver->resolve()); - } - - /** - * @group legacy - */ - public function testLegacyNormalizeNestedValue() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - // defined by superclass - $this->resolver->setDefault('foo', function (OptionsResolver $resolver) { - $resolver->setDefault('bar', null); - }); - // defined by subclass - $this->resolver->setNormalizer('foo', function (Options $options, $resolvedValue) { - $resolvedValue['bar'] ??= 'baz'; - - return $resolvedValue; - }); - $this->assertSame(['foo' => ['bar' => 'baz']], $this->resolver->resolve()); - } - - /** - * @group legacy - */ - public function testLegacyFailsIfCyclicDependencyBetweenSameNestedOption() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefault('database', function (OptionsResolver $resolver, Options $parent) { - $resolver->setDefault('replicas', $parent['database']); - }); - - $this->expectException(OptionDefinitionException::class); - - $this->resolver->resolve(); - } - - /** - * @group legacy - */ - public function testLegacyFailsIfCyclicDependencyBetweenNestedOptionAndParentLazyOption() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefaults([ - 'version' => fn (Options $options) => $options['database']['server_version'], - 'database' => function (OptionsResolver $resolver, Options $parent) { - $resolver->setDefault('server_version', $parent['version']); - }, - ]); - - $this->expectException(OptionDefinitionException::class); - - $this->resolver->resolve(); - } - - /** - * @group legacy - */ - public function testLegacyFailsIfCyclicDependencyBetweenNormalizerAndNestedOption() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver - ->setDefault('name', 'default') - ->setDefault('database', function (OptionsResolver $resolver, Options $parent) { - $resolver->setDefault('host', $parent['name']); - }) - ->setNormalizer('name', function (Options $options, $value) { - $options['database']; - }); - - $this->expectException(OptionDefinitionException::class); - - $this->resolver->resolve(); - } - - /** - * @group legacy - */ - public function testLegacyFailsIfCyclicDependencyBetweenNestedOptions() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefault('database', function (OptionsResolver $resolver, Options $parent) { - $resolver->setDefault('host', $parent['replica']['host']); - }); - $this->resolver->setDefault('replica', function (OptionsResolver $resolver, Options $parent) { - $resolver->setDefault('host', $parent['database']['host']); - }); - - $this->expectException(OptionDefinitionException::class); - - $this->resolver->resolve(); - } - - /** - * @group legacy - */ - public function testLegacyGetAccessToParentOptionFromNestedOption() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefaults([ - 'version' => 3.15, - 'database' => function (OptionsResolver $resolver, Options $parent) { - $resolver->setDefault('server_version', $parent['version']); - }, - ]); - $this->assertSame(['version' => 3.15, 'database' => ['server_version' => 3.15]], $this->resolver->resolve()); - } - public function testNestedClosureWithoutTypeHintNotInvoked() { $closure = function ($resolver) { @@ -2561,62 +2091,6 @@ public function testNestedClosureWithoutTypeHint2ndArgumentNotInvoked() $this->assertSame(['foo' => $closure], $this->resolver->resolve()); } - /** - * @group legacy - */ - public function testLegacyResolveLazyOptionWithTransitiveDefaultDependency() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefaults([ - 'ip' => null, - 'database' => function (OptionsResolver $resolver, Options $parent) { - $resolver->setDefault('host', $parent['ip']); - $resolver->setDefault('primary_replica', function (OptionsResolver $resolver, Options $parent) { - $resolver->setDefault('host', $parent['host']); - }); - }, - 'secondary_replica' => fn (Options $options) => $options['database']['primary_replica']['host'], - ]); - $actualOptions = $this->resolver->resolve(['ip' => '127.0.0.1']); - $expectedOptions = [ - 'ip' => '127.0.0.1', - 'database' => [ - 'host' => '127.0.0.1', - 'primary_replica' => ['host' => '127.0.0.1'], - ], - 'secondary_replica' => '127.0.0.1', - ]; - $this->assertSame($expectedOptions, $actualOptions); - } - - /** - * @group legacy - */ - public function testLegacyAccessToParentOptionFromNestedNormalizerAndLazyOption() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver->setDefaults([ - 'debug' => true, - 'database' => function (OptionsResolver $resolver, Options $parent) { - $resolver - ->setDefined('logging') - ->setDefault('profiling', fn (Options $options) => $parent['debug']) - ->setNormalizer('logging', fn (Options $options, $value) => false === $parent['debug'] ? true : $value); - }, - ]); - $actualOptions = $this->resolver->resolve([ - 'debug' => false, - 'database' => ['logging' => false], - ]); - $expectedOptions = [ - 'debug' => false, - 'database' => ['profiling' => false, 'logging' => true], - ]; - $this->assertSame($expectedOptions, $actualOptions); - } - public function testFailsIfOptionIsAlreadyDefined() { $this->expectException(OptionDefinitionException::class); @@ -2721,49 +2195,6 @@ public function testInfoOnInvalidValue() $this->resolver->resolve(['expires' => new \DateTimeImmutable('-1 hour')]); } - /** - * @group legacy - */ - public function testLegacyInvalidValueForPrototypeDefinition() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver - ->setDefault('connections', static function (OptionsResolver $resolver) { - $resolver - ->setPrototype(true) - ->setDefined(['table', 'user', 'password']); - }); - - $this->expectException(InvalidOptionsException::class); - $this->expectExceptionMessage('The value of the option "connections" is expected to be of type array of array, but is of type array of "string".'); - - $this->resolver->resolve(['connections' => ['foo']]); - } - - /** - * @group legacy - */ - public function testLegacyMissingOptionForPrototypeDefinition() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver - ->setDefault('connections', static function (OptionsResolver $resolver) { - $resolver - ->setPrototype(true) - ->setRequired('table'); - }); - - $this->expectException(MissingOptionsException::class); - $this->expectExceptionMessage('The required option "connections[1][table]" is missing.'); - - $this->resolver->resolve(['connections' => [ - ['table' => 'default'], - [], // <- missing required option "table" - ]]); - } - public function testAccessExceptionOnPrototypeDefinition() { $this->expectException(AccessException::class); @@ -2772,53 +2203,6 @@ public function testAccessExceptionOnPrototypeDefinition() $this->resolver->setPrototype(true); } - /** - * @group legacy - */ - public function testLegacyPrototypeDefinition() - { - $this->expectUserDeprecationMessage('Since symfony/options-resolver 7.3: Defining nested options via "Symfony\Component\OptionsResolver\OptionsResolver::setDefault()" is deprecated and will be removed in Symfony 8.0, use "setOptions()" method instead.'); - - $this->resolver - ->setDefault('connections', static function (OptionsResolver $resolver) { - $resolver - ->setPrototype(true) - ->setRequired('table') - ->setDefaults(['user' => 'root', 'password' => null]) - ; - }) - ; - - $actualOptions = $this->resolver->resolve([ - 'connections' => [ - 'default' => [ - 'table' => 'default', - ], - 'custom' => [ - 'user' => 'foo', - 'password' => 'pa$$', - 'table' => 'symfony', - ], - ], - ]); - $expectedOptions = [ - 'connections' => [ - 'default' => [ - 'user' => 'root', - 'password' => null, - 'table' => 'default', - ], - 'custom' => [ - 'user' => 'foo', - 'password' => 'pa$$', - 'table' => 'symfony', - ], - ], - ]; - - $this->assertSame($expectedOptions, $actualOptions); - } - public function testPrototypeDefinition() { $this->resolver pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy