This repository has been archived by the owner on Aug 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from smartbooster/2_bundle_configuration
#2 Setup Bundle Configuration.php
- Loading branch information
Showing
21 changed files
with
306 additions
and
6 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 |
---|---|---|
|
@@ -3,3 +3,5 @@ composer.lock | |
/phpmetrics/ | ||
coverage.* | ||
.php_cs.cache | ||
.phpunit.result.cache | ||
/var/ |
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
File renamed without changes.
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,6 @@ | ||
includes: | ||
- vendor/phpstan/phpstan-symfony/extension.neon | ||
- vendor/phpstan/phpstan-symfony/rules.neon | ||
|
||
parameters: | ||
checkMissingIterableValueType: false |
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,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" | ||
backupGlobals="false" | ||
colors="true" | ||
bootstrap="./vendor/autoload.php"> | ||
<php> | ||
<ini name="error_reporting" value="-1"/> | ||
<ini name="memory_limit" value="-1"/> | ||
</php> | ||
<testsuites> | ||
<testsuite name="Test suite"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<include> | ||
<directory>./src</directory> | ||
</include> | ||
<exclude> | ||
<directory>./src/SmartParameterBundle.php</directory> | ||
</exclude> | ||
</coverage> | ||
</phpunit> |
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,41 @@ | ||
<?php | ||
|
||
namespace Smart\ParameterBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
class Configuration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder('smart_parameter'); | ||
$root = $treeBuilder->getRootNode(); | ||
|
||
$root | ||
->children() | ||
->append($this->getParametersNode()) | ||
->end() | ||
; | ||
|
||
return $treeBuilder; | ||
} | ||
|
||
private function getParametersNode(): NodeDefinition | ||
{ | ||
return (new TreeBuilder('parameters'))->getRootNode() | ||
->requiresAtLeastOneElement() | ||
->useAttributeAsKey('name') | ||
->arrayPrototype() | ||
->children() | ||
->scalarNode('value')->isRequired()->end() | ||
->scalarNode('help')->end() | ||
->end() | ||
->end() | ||
; | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace Smart\ParameterBundle\DependencyInjection; | ||
|
||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
class SmartParameterExtension extends Extension | ||
{ | ||
/** | ||
* @param array<array> $configs | ||
* @param ContainerBuilder $container | ||
* @throws \Exception | ||
* @return void | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$this->processConfiguration(new Configuration(), $configs); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace Smart\ParameterBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
class SmartParameterBundle extends Bundle | ||
{ | ||
public function getPath(): string | ||
{ | ||
return \dirname(__DIR__); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Empty file.
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,26 @@ | ||
<?php | ||
|
||
namespace Smart\ParameterBundle\Tests\App; | ||
|
||
use Smart\ParameterBundle\SmartParameterBundle; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
*/ | ||
class AppKernel extends Kernel | ||
{ | ||
public function registerBundles() | ||
{ | ||
return [ | ||
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), | ||
new SmartParameterBundle(), | ||
]; | ||
} | ||
|
||
public function registerContainerConfiguration(LoaderInterface $loader): void | ||
{ | ||
$loader->load(__DIR__ . '/../fixtures/config/full.yml'); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace Smart\ParameterBundle\Tests\App; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
* | ||
* vendor/bin/phpunit tests/App/AppKernelTest.php | ||
*/ | ||
class AppKernelTest extends WebTestCase | ||
{ | ||
protected static function getKernelClass() | ||
{ | ||
return AppKernel::class; | ||
} | ||
|
||
public function testBootingKernel(): void | ||
{ | ||
self::bootKernel(); | ||
|
||
$this->assertInstanceOf(KernelInterface::class, self::$kernel); | ||
} | ||
} |
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,84 @@ | ||
<?php | ||
|
||
namespace Smart\ParameterBundle\Tests\DependencyInjection; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Smart\ParameterBundle\SmartParameterBundle; | ||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\FileLoader; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
|
||
/** | ||
* @author Mathieu Ducrot <[email protected]> | ||
* | ||
* vendor/bin/phpunit tests/DependencyInjection/DependencyInjectionTest.php | ||
*/ | ||
class DependencyInjectionTest extends TestCase | ||
{ | ||
private ContainerBuilder $container; | ||
|
||
protected function setUp(): void | ||
{ | ||
$bundle = new SmartParameterBundle(); | ||
$this->container = new ContainerBuilder(); | ||
|
||
$this->container->setParameter('kernel.debug', true); | ||
$this->container->setParameter('kernel.bundles', [ | ||
'FrameworkBundle' => \Symfony\Bundle\FrameworkBundle\FrameworkBundle::class, | ||
]); | ||
$this->container->setParameter('kernel.environment', 'test'); | ||
|
||
$this->container->registerExtension($bundle->getContainerExtension()); | ||
$bundle->build($this->container); | ||
} | ||
|
||
/** | ||
* @dataProvider invalidConfigurationProvider | ||
*/ | ||
public function testInvalidConfigurationParsing(string $resource, string $message): void | ||
{ | ||
$this->expectException(InvalidConfigurationException::class); | ||
$this->expectExceptionMessage($message); | ||
|
||
$loader = new YamlFileLoader($this->container, new FileLocator(__DIR__ . '/../fixtures/config/')); | ||
$loader->load($resource . ".yml"); | ||
$this->container->compile(); | ||
} | ||
|
||
public function invalidConfigurationProvider(): array | ||
{ | ||
return [ | ||
'invalid_no_parameter_defined' => [ | ||
'ressource' => 'invalid_no_parameter_defined', | ||
'message' => 'The path "smart_parameter.parameters" should have at least 1 element(s) defined.', | ||
], | ||
'invalid_missing_parameter_value' => [ | ||
'ressource' => 'invalid_missing_parameter_value', | ||
'message' => 'The child node "value" at path "smart_parameter.parameters.parameter_without_value" must be configured.', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider configurationProvider | ||
*/ | ||
public function testValidConfigurationParsing(string $resource): void | ||
{ | ||
$loader = new YamlFileLoader($this->container, new FileLocator(__DIR__ . '/../fixtures/config/')); | ||
$loader->load($resource . ".yml"); | ||
$this->container->compile(); | ||
// This assertion is already true with the setUp but it valid the fact that the container did compile with the given configuration | ||
$this->assertNotNull($this->container->getExtension("smart_parameter")); | ||
} | ||
|
||
public function configurationProvider(): array | ||
{ | ||
return [ | ||
'full' => ['full'], | ||
'minimal' => ['minimal'], | ||
'none' => ['none'], | ||
]; | ||
} | ||
} |
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,11 @@ | ||
# Full config fixture | ||
smart_parameter: | ||
parameters: | ||
# Textual paramter | ||
dummy_support_emails: | ||
value: "[email protected], [email protected]" | ||
help: "This parameter is used by the mailer for support recipients. Format : Separate email by comma." | ||
# Number parameter | ||
dummy_homepage_cache_duration: | ||
value: 3600 | ||
help: "This parameter is used by the backend to set the duration of cache applied to the Homepage. Set the duration in second." |
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,4 @@ | ||
# | ||
smart_parameter: | ||
parameters: | ||
parameter_without_value: |
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,3 @@ | ||
# | ||
smart_parameter: | ||
parameters: |
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,5 @@ | ||
# Config with only minimal parameter configuration | ||
smart_parameter: | ||
parameters: | ||
dummy_parameter: | ||
value: "some value" |
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,2 @@ | ||
# Empty config | ||
smart_parameter: ~ |