Skip to content

Commit 096a798

Browse files
Add tests
1 parent ca26014 commit 096a798

File tree

9 files changed

+314
-5
lines changed

9 files changed

+314
-5
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\Config\ArrayValuesConfig;
13+
14+
return static function (ArrayValuesConfig $config) {
15+
$config->transports('foo')->dsn('bar');
16+
$config->transports('bar', ['dsn' => 'foobar']);
17+
18+
$config->errorPages()->withTrace(false);
19+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
return [
13+
'transports' => [
14+
'foo' => [
15+
'dsn' => 'bar',
16+
],
17+
'bar' => [
18+
'dsn' => 'foobar',
19+
],
20+
],
21+
'error_pages' => [
22+
'with_trace' => false,
23+
]
24+
];
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Symfony\Component\Config\Tests\Builder\Fixtures;
4+
5+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6+
use Symfony\Component\Config\Definition\ConfigurationInterface;
7+
8+
class ArrayValues implements ConfigurationInterface
9+
{
10+
public function getConfigTreeBuilder(): TreeBuilder
11+
{
12+
$tb = new TreeBuilder('array_values');
13+
$rootNode = $tb->getRootNode();
14+
$rootNode
15+
->children()
16+
->arrayNode('transports')
17+
->normalizeKeys(false)
18+
->useAttributeAsKey('name')
19+
->arrayPrototype()
20+
->beforeNormalization()
21+
->ifString()
22+
->then(function (string $dsn) {
23+
return ['dsn' => $dsn];
24+
})
25+
->end()
26+
->fixXmlConfig('option')
27+
->children()
28+
->scalarNode('dsn')->end()
29+
->end()
30+
->end()
31+
->end()
32+
->arrayNode('error_pages')
33+
->canBeEnabled()
34+
->children()
35+
->booleanNode('with_trace')->end()
36+
->end()
37+
->end()
38+
->end();
39+
40+
return $tb;
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace Symfony\Config\ArrayValues;
4+
5+
use Symfony\Component\Config\Loader\ParamConfigurator;
6+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
7+
8+
/**
9+
* This class is automatically generated to help in creating a config.
10+
*/
11+
class ErrorPagesConfig
12+
{
13+
private $enabled;
14+
private $withTrace;
15+
private $_usedProperties = [];
16+
17+
/**
18+
* @default false
19+
* @param ParamConfigurator|bool $value
20+
* @return $this
21+
*/
22+
public function enabled($value): static
23+
{
24+
$this->_usedProperties['enabled'] = true;
25+
$this->enabled = $value;
26+
27+
return $this;
28+
}
29+
30+
/**
31+
* @default null
32+
* @param ParamConfigurator|bool $value
33+
* @return $this
34+
*/
35+
public function withTrace($value): static
36+
{
37+
$this->_usedProperties['withTrace'] = true;
38+
$this->withTrace = $value;
39+
40+
return $this;
41+
}
42+
43+
public function __construct(array $value = [])
44+
{
45+
if (array_key_exists('enabled', $value)) {
46+
$this->_usedProperties['enabled'] = true;
47+
$this->enabled = $value['enabled'];
48+
unset($value['enabled']);
49+
}
50+
51+
if (array_key_exists('with_trace', $value)) {
52+
$this->_usedProperties['withTrace'] = true;
53+
$this->withTrace = $value['with_trace'];
54+
unset($value['with_trace']);
55+
}
56+
57+
if ([] !== $value) {
58+
throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value)));
59+
}
60+
}
61+
62+
public function toArray(): array
63+
{
64+
$output = [];
65+
if (isset($this->_usedProperties['enabled'])) {
66+
$output['enabled'] = $this->enabled;
67+
}
68+
if (isset($this->_usedProperties['withTrace'])) {
69+
$output['with_trace'] = $this->withTrace;
70+
}
71+
72+
return $output;
73+
}
74+
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Symfony\Config\ArrayValues;
4+
5+
use Symfony\Component\Config\Loader\ParamConfigurator;
6+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
7+
8+
/**
9+
* This class is automatically generated to help in creating a config.
10+
*/
11+
class TransportsConfig
12+
{
13+
private $dsn;
14+
private $_usedProperties = [];
15+
16+
/**
17+
* @default null
18+
* @param ParamConfigurator|mixed $value
19+
* @return $this
20+
*/
21+
public function dsn($value): static
22+
{
23+
$this->_usedProperties['dsn'] = true;
24+
$this->dsn = $value;
25+
26+
return $this;
27+
}
28+
29+
public function __construct(array $value = [])
30+
{
31+
if (array_key_exists('dsn', $value)) {
32+
$this->_usedProperties['dsn'] = true;
33+
$this->dsn = $value['dsn'];
34+
unset($value['dsn']);
35+
}
36+
37+
if ([] !== $value) {
38+
throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value)));
39+
}
40+
}
41+
42+
public function toArray(): array
43+
{
44+
$output = [];
45+
if (isset($this->_usedProperties['dsn'])) {
46+
$output['dsn'] = $this->dsn;
47+
}
48+
49+
return $output;
50+
}
51+
52+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
namespace Symfony\Config;
4+
5+
require_once __DIR__.\DIRECTORY_SEPARATOR.'ArrayValues'.\DIRECTORY_SEPARATOR.'TransportsConfig.php';
6+
require_once __DIR__.\DIRECTORY_SEPARATOR.'ArrayValues'.\DIRECTORY_SEPARATOR.'ErrorPagesConfig.php';
7+
8+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
9+
10+
/**
11+
* This class is automatically generated to help in creating a config.
12+
*/
13+
class ArrayValuesConfig implements \Symfony\Component\Config\Builder\ConfigBuilderInterface
14+
{
15+
private $transports;
16+
private $errorPages;
17+
private $_usedProperties = [];
18+
19+
/**
20+
* @template TValue of string|array
21+
* @param TValue $value
22+
* @return \Symfony\Config\ArrayValues\TransportsConfig|$this
23+
* @psalm-return (TValue is array ? \Symfony\Config\ArrayValues\TransportsConfig : static)
24+
*/
25+
public function transports(string $name, string|array $value = []): \Symfony\Config\ArrayValues\TransportsConfig|static
26+
{
27+
if (!\is_array($value)) {
28+
$this->_usedProperties['transports'] = true;
29+
$this->transports[$name] = $value;
30+
31+
return $this;
32+
}
33+
34+
if (!isset($this->transports[$name]) || !$this->transports[$name] instanceof \Symfony\Config\ArrayValues\TransportsConfig) {
35+
$this->_usedProperties['transports'] = true;
36+
$this->transports[$name] = new \Symfony\Config\ArrayValues\TransportsConfig($value);
37+
} elseif (1 < \func_num_args()) {
38+
throw new InvalidConfigurationException('The node created by "transports()" has already been initialized. You cannot pass values the second time you call transports().');
39+
}
40+
41+
return $this->transports[$name];
42+
}
43+
44+
/**
45+
* @default {"enabled":false}
46+
*/
47+
public function errorPages(array $value = []): \Symfony\Config\ArrayValues\ErrorPagesConfig
48+
{
49+
if (null === $this->errorPages) {
50+
$this->_usedProperties['errorPages'] = true;
51+
$this->errorPages = new \Symfony\Config\ArrayValues\ErrorPagesConfig($value);
52+
} elseif (0 < \func_num_args()) {
53+
throw new InvalidConfigurationException('The node created by "errorPages()" has already been initialized. You cannot pass values the second time you call errorPages().');
54+
}
55+
56+
return $this->errorPages;
57+
}
58+
59+
public function getExtensionAlias(): string
60+
{
61+
return 'array_values';
62+
}
63+
64+
public function __construct(array $value = [])
65+
{
66+
if (array_key_exists('transports', $value)) {
67+
$this->_usedProperties['transports'] = true;
68+
$this->transports = array_map(fn ($v) => \is_array($v) ? new \Symfony\Config\ArrayValues\TransportsConfig($v) : $v, $value['transports']);
69+
unset($value['transports']);
70+
}
71+
72+
if (array_key_exists('error_pages', $value)) {
73+
$this->_usedProperties['errorPages'] = true;
74+
$this->errorPages = \is_array($value['error_pages']) ? new \Symfony\Config\ArrayValues\ErrorPagesConfig($value['error_pages']) : $value['error_pages'];
75+
unset($value['error_pages']);
76+
}
77+
78+
if ([] !== $value) {
79+
throw new InvalidConfigurationException(sprintf('The following keys are not supported by "%s": ', __CLASS__).implode(', ', array_keys($value)));
80+
}
81+
}
82+
83+
public function toArray(): array
84+
{
85+
$output = [];
86+
if (isset($this->_usedProperties['transports'])) {
87+
$output['transports'] = array_map(fn ($v) => $v instanceof \Symfony\Config\ArrayValues\TransportsConfig ? $v->toArray() : $v, $this->transports);
88+
}
89+
if (isset($this->_usedProperties['errorPages'])) {
90+
$output['error_pages'] = $this->errorPages instanceof \Symfony\Config\ArrayValues\ErrorPagesConfig ? $this->errorPages->toArray() : $this->errorPages;
91+
}
92+
93+
return $output;
94+
}
95+
96+
}

src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypes/NestedConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class NestedConfig
1717
private $_usedProperties = [];
1818

1919
/**
20-
* @template TValue
20+
* @template TValue of mixed
2121
* @param TValue $value
2222
* @default {"enabled":null}
2323
* @return \Symfony\Config\ScalarNormalizedTypes\Nested\NestedObjectConfig|$this
@@ -43,7 +43,7 @@ public function nestedObject(mixed $value = []): \Symfony\Config\ScalarNormalize
4343
}
4444

4545
/**
46-
* @template TValue
46+
* @template TValue of mixed
4747
* @param TValue $value
4848
* @return \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig|$this
4949
* @psalm-return (TValue is array ? \Symfony\Config\ScalarNormalizedTypes\Nested\NestedListObjectConfig : static)

src/Symfony/Component/Config/Tests/Builder/Fixtures/ScalarNormalizedTypes/Symfony/Config/ScalarNormalizedTypesConfig.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function keyedArray(string $name, ParamConfigurator|string|array $value):
4848
}
4949

5050
/**
51-
* @template TValue
51+
* @template TValue of mixed
5252
* @param TValue $value
5353
* @default {"enabled":null}
5454
* @return \Symfony\Config\ScalarNormalizedTypes\ObjectConfig|$this
@@ -74,7 +74,7 @@ public function object(mixed $value = []): \Symfony\Config\ScalarNormalizedTypes
7474
}
7575

7676
/**
77-
* @template TValue
77+
* @template TValue of mixed
7878
* @param TValue $value
7979
* @return \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig|$this
8080
* @psalm-return (TValue is array ? \Symfony\Config\ScalarNormalizedTypes\ListObjectConfig : static)
@@ -92,7 +92,7 @@ public function listObject(mixed $value = []): \Symfony\Config\ScalarNormalizedT
9292
}
9393

9494
/**
95-
* @template TValue
95+
* @template TValue of mixed
9696
* @param TValue $value
9797
* @return \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig|$this
9898
* @psalm-return (TValue is array ? \Symfony\Config\ScalarNormalizedTypes\KeyedListObjectConfig : static)

src/Symfony/Component/Config/Tests/Builder/GeneratedConfigTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public static function fixtureNames()
6262
'AddToList' => 'add_to_list',
6363
'NodeInitialValues' => 'node_initial_values',
6464
'ArrayExtraKeys' => 'array_extra_keys',
65+
'ArrayValues' => 'array_values',
6566
];
6667

6768
foreach ($array as $name => $alias) {

0 commit comments

Comments
 (0)
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