-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
361 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* (c) Christian Gripp <mail@core23.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nucleos\Twig\Bridge\Symfony\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
final class Configuration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$treeBuilder = new TreeBuilder('nucleos_twig'); | ||
|
||
$rootNode = $treeBuilder->getRootNode(); | ||
|
||
$rootNode->append($this->getSecureNode()); | ||
|
||
return $treeBuilder; | ||
} | ||
|
||
private function getSecureNode(): NodeDefinition | ||
{ | ||
$node = (new TreeBuilder('secure'))->getRootNode(); | ||
|
||
$node | ||
->addDefaultsIfNotSet() | ||
->children() | ||
->arrayNode('mail') | ||
->addDefaultsIfNotSet() | ||
->children() | ||
->arrayNode('dot_text') | ||
->useAttributeAsKey('id') | ||
->requiresAtLeastOneElement() | ||
->defaultValue([' [DOT] ', ' (DOT) ', ' [.] ']) | ||
->prototype('scalar')->end() | ||
->end() | ||
->arrayNode('at_text') | ||
->useAttributeAsKey('id') | ||
->requiresAtLeastOneElement() | ||
->defaultValue([' [AT] ', ' (AT) ', ' [ÄT] ']) | ||
->prototype('scalar')->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
; | ||
|
||
return $node; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
tests/Bridge/Symfony/DependencyInjection/ConfigurationTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* (c) Christian Gripp <mail@core23.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nucleos\Twig\Tests\Bridge\Symfony\DependencyInjection; | ||
|
||
use Nucleos\Twig\Bridge\Symfony\DependencyInjection\Configuration; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Config\Definition\Processor; | ||
|
||
final class ConfigurationTest extends TestCase | ||
{ | ||
public function testDefaultOptions(): void | ||
{ | ||
$processor = new Processor(); | ||
|
||
$config = $processor->processConfiguration(new Configuration(), [[ | ||
]]); | ||
|
||
$expected = [ | ||
'secure' => [ | ||
'mail' => [ | ||
'dot_text' => [' [DOT] ', ' (DOT) ', ' [.] '], | ||
'at_text' => [' [AT] ', ' (AT) ', ' [ÄT] '], | ||
], | ||
], | ||
]; | ||
|
||
self::assertSame($expected, $config); | ||
} | ||
|
||
public function testOptions(): void | ||
{ | ||
$processor = new Processor(); | ||
|
||
$config = $processor->processConfiguration(new Configuration(), [[ | ||
'secure' => [ | ||
'mail' => [ | ||
'dot_text' => ['[DOT]'], | ||
'at_text' => ['[AT'], | ||
], | ||
], | ||
]]); | ||
|
||
$expected = [ | ||
'secure' => [ | ||
'mail' => [ | ||
'dot_text' => ['[DOT]'], | ||
'at_text' => ['[AT'], | ||
], | ||
], | ||
]; | ||
|
||
self::assertSame($expected, $config); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.