Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 8 additions & 22 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,21 @@ jobs:
strategy:
matrix:
php:
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
dependency:
- ''
symfony:
- '4.4.*'
- '5.3.*'
- '5.4.*'
- '6.2.*'
include:
- php: '7.1'
symfony: '4.4.*'
- php: '8.1'
symfony: '5.4.*'
dependency: 'lowest'
- php: '8.0'
symfony: '6.0.*'
exclude:
- php: '7.1'
symfony: '5.3.*'
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -42,18 +34,12 @@ jobs:
extensions: pcov
tools: flex

- name: Prefer unstable Composer dependencies for Symfony 6.0
if: matrix.symfony == '6.0.*'
run: |
composer config prefer-stable false
composer config minimum-stability dev

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
Expand Down
26 changes: 8 additions & 18 deletions Partial/PartialNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,30 +99,20 @@ private static function childNode(ArrayNode $node, $childNodeName)
*/
private static function nodeChildrenProperty()
{
if (!isset(self::$nodeChildrenProperty)) {
self::$nodeChildrenProperty = new \ReflectionProperty(
ArrayNode::class,
'children'
);
self::$nodeChildrenProperty->setAccessible(true);
}

return self::$nodeChildrenProperty;
return self::$nodeChildrenProperty ??= new \ReflectionProperty(
ArrayNode::class,
'children'
);
}

/**
* @return \ReflectionProperty
*/
private static function nodePrototypeProperty()
{
if (!isset(self::$nodePrototypeProperty)) {
self::$nodePrototypeProperty = new \ReflectionProperty(
PrototypedArrayNode::class,
'prototype'
);
self::$nodePrototypeProperty->setAccessible(true);
}

return self::$nodePrototypeProperty;
return self::$nodePrototypeProperty ??= new \ReflectionProperty(
PrototypedArrayNode::class,
'prototype'
);
}
}
4 changes: 0 additions & 4 deletions PhpUnit/AbstractConfigurationConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ abstract class AbstractConfigurationConstraint extends Constraint

public function __construct(ConfigurationInterface $configuration, $breadcrumbPath = null)
{
if (is_callable([Constraint::class, '__construct'])) {
parent::__construct();
}

$this->configuration = $configuration;
$this->breadcrumbPath = $breadcrumbPath;
}
Expand Down
26 changes: 26 additions & 0 deletions PhpUnit/ConfigurationValuesAreInvalidConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
namespace Matthias\SymfonyConfigTest\PhpUnit;

use PHPUnit\Framework\Constraint\ExceptionMessage;
use PHPUnit\Framework\Constraint\ExceptionMessageIsOrContains;
use PHPUnit\Framework\Constraint\ExceptionMessageMatchesRegularExpression;
use PHPUnit\Framework\Constraint\ExceptionMessageRegularExpression;
use PHPUnit\Framework\Constraint\MessageIsOrContains;
use PHPUnit\Framework\Constraint\MessageMatchesRegularExpression;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;

Expand Down Expand Up @@ -67,9 +71,31 @@ private function evaluateException(\Exception $exception, $description, $returnR
private function createPhpUnitConstraint()
{
if ($this->useRegExp) {
// Available since PHPUnit 10.0.15
if (class_exists(ExceptionMessageMatchesRegularExpression::class)) {
return new ExceptionMessageMatchesRegularExpression($this->expectedMessage);
}

// Available between PHPUnit 10.0.0 and 10.0.14 (inclusive)
if (class_exists(MessageMatchesRegularExpression::class)) {
return new MessageMatchesRegularExpression('exception', $this->expectedMessage);
}

// Available in PHPUnit 9.6
return new ExceptionMessageRegularExpression($this->expectedMessage);
}

// Available since PHPUnit 10.0.15
if (class_exists(ExceptionMessageIsOrContains::class)) {
return new ExceptionMessageIsOrContains($this->expectedMessage);
}

// Available between PHPUnit 10.0.0 and 10.0.14 (inclusive)
if (class_exists(MessageIsOrContains::class)) {
return new MessageIsOrContains('exception', $this->expectedMessage);
}

// Available in PHPUnit 9.6
return new ExceptionMessage($this->expectedMessage);
}
}
6 changes: 1 addition & 5 deletions Tests/Partial/Fixtures/ConfigurationStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ class ConfigurationStub implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('root');
if (method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
$root = $treeBuilder->root('root');
}
$root = $treeBuilder->getRootNode();
$root
->children()
->arrayNode('only_test_this_node')
Expand Down
37 changes: 6 additions & 31 deletions Tests/Partial/PartialNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ class PartialNodeTest extends TestCase
public function it_strips_children_that_are_not_in_the_given_path_with_one_name()
{
$treeBuilder = new TreeBuilder('root');
if (method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
$root = $treeBuilder->root('root');
}
$root = $treeBuilder->getRootNode();
$root
->children()
->arrayNode('node_1')
Expand All @@ -49,11 +45,7 @@ public function it_strips_children_that_are_not_in_the_given_path_with_one_name(
public function it_strips_children_that_are_not_in_the_given_path_with_several_names()
{
$treeBuilder = new TreeBuilder('root');
if (method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
$root = $treeBuilder->root('root');
}
$root = $treeBuilder->getRootNode();
$root
->children()
->arrayNode('node_1')
Expand Down Expand Up @@ -91,11 +83,7 @@ public function it_strips_children_that_are_not_in_the_given_path_with_several_n
public function it_strips_children_when_leaf_node_is_not_an_array()
{
$treeBuilder = new TreeBuilder('root');
if (method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
$root = $treeBuilder->root('root');
}
$root = $treeBuilder->getRootNode();
$root
->children()
->arrayNode('node_1')
Expand All @@ -122,11 +110,7 @@ public function it_strips_children_when_leaf_node_is_not_an_array()
public function it_does_not_crash_on_prototypes()
{
$treeBuilder = new TreeBuilder('root');
if (method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
$root = $treeBuilder->root('root');
}
$root = $treeBuilder->getRootNode();
$root
->prototype('array')
->children()
Expand Down Expand Up @@ -156,11 +140,7 @@ public function it_does_not_crash_on_prototypes()
public function it_fails_when_a_requested_child_node_does_not_exist()
{
$treeBuilder = new TreeBuilder('root');
if (method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
$root = $treeBuilder->root('root');
}
$root = $treeBuilder->getRootNode();
$root
->children()
->arrayNode('sub_node')
Expand All @@ -181,11 +161,7 @@ public function it_fails_when_a_requested_child_node_does_not_exist()
public function it_fails_when_a_requested_child_node_is_no_array_node_itself_and_path_not_empty()
{
$treeBuilder = new TreeBuilder('root');
if (method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
$root = $treeBuilder->root('root');
}
$root = $treeBuilder->getRootNode();
$root
->children()
->arrayNode('sub_node')
Expand All @@ -203,7 +179,6 @@ public function it_fails_when_a_requested_child_node_is_no_array_node_itself_and
private function nodeOnlyHasChild(ArrayNode $node, $nodeName)
{
$property = new \ReflectionProperty($node, 'children');
$property->setAccessible(true);
$children = $property->getValue($node);

$this->assertCount(1, $children);
Expand Down
12 changes: 5 additions & 7 deletions Tests/Partial/PartialProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ class PartialProcessorTest extends TestCase
public function it_processes_only_the_values_in_the_breadcrumb_path_for_a_given_node()
{
$treeBuilder = new TreeBuilder('root');
if (method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
$root = $treeBuilder->root('root');
}
$root = $treeBuilder->getRootNode();
$root
->children()
->arrayNode('only_test_this_node')
Expand Down Expand Up @@ -55,7 +51,8 @@ public function it_processes_only_the_values_in_the_breadcrumb_path_for_a_given_
'only_test_this_node' => [
'scalar_node' => 'yes',
],
], $processedConfig
],
$processedConfig
);
}

Expand Down Expand Up @@ -83,7 +80,8 @@ public function it_processes_only_the_values_in_the_given_breadcrumb_path_for_a_
'only_test_this_node' => [
'scalar_node' => 'yes',
],
], $processedConfig
],
$processedConfig
);
}
}
6 changes: 1 addition & 5 deletions Tests/PhpUnit/ConfigurationTestCaseTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ public function it_fails_when_a_configuration_is_invalid_when_it_should_have_bee
{
$this->expectException(ExpectationFailedException::class);

if (method_exists($this, 'expectExceptionMessageMatches')) {
$this->expectExceptionMessageMatches('/^The child (config|node) "required_value" (at path|under) "root" must be configured/');
} else {
$this->expectExceptionMessageRegExp('/^The child (config|node) "required_value" (at path|under) "root" must be configured/');
}
$this->expectExceptionMessageMatches('/^The child (config|node) "required_value" (at path|under) "root" must be configured/');

$this->assertConfigurationIsValid(
[
Expand Down
7 changes: 1 addition & 6 deletions Tests/PhpUnit/Fixtures/AlwaysValidConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ class AlwaysValidConfiguration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('root');
if (!method_exists($treeBuilder, 'getRootNode')) {
$treeBuilder->root('root');
}

return $treeBuilder;
return new TreeBuilder('root');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ class ConfigurationWithMultipleArrayKeys implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('root');
if (method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
$root = $treeBuilder->root('root');
}
$root = $treeBuilder->getRootNode();
$root
->children()
->arrayNode('array_node_1')
Expand Down
6 changes: 1 addition & 5 deletions Tests/PhpUnit/Fixtures/ConfigurationWithRequiredValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ class ConfigurationWithRequiredValue implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('root');
if (method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
$root = $treeBuilder->root('root');
}
$root = $treeBuilder->getRootNode();
$root
->isRequired()
->children()
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
}
],
"require": {
"php": "^7.1 || ^8.0",
"symfony/config": "^4.4 || ^5.3 || ^6.0"
"php": "^8.1",
"symfony/config": "^5.4 || ^6.2"
},
"require-dev": {
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0"
"phpunit/phpunit": "^9.6 || ^10.0"
},
"conflict": {
"phpunit/phpunit": "<7.0"
"phpunit/phpunit": "<9.6 || >=11.0"
},
"autoload": {
"psr-4" : { "Matthias\\SymfonyConfigTest\\" : "" }
},
"extra": {
"branch-alias": {
"dev-master": "4.0.x-dev"
"dev-master": "5.0.x-dev"
}
}
}
24 changes: 12 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.0/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
colors="true"
verbose="true">
>
<testsuites>
<testsuite name="MatthiasSymfonyConfigTest">
<directory suffix="Test.php">Tests</directory>
<directory>Tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">.</directory>
<exclude>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<coverage>
<include>
<directory suffix=".php">./</directory>
</include>
<exclude>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
</phpunit>