{"id":15600678,"url":"https://github.com/symfonytest/symfonyconfigtest","last_synced_at":"2025-04-13T18:37:47.729Z","repository":{"id":10337147,"uuid":"12470120","full_name":"SymfonyTest/SymfonyConfigTest","owner":"SymfonyTest","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-08T10:18:10.000Z","size":131,"stargazers_count":162,"open_issues_count":2,"forks_count":35,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-06T15:09:43.916Z","etag":null,"topics":["symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SymfonyTest.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-08-29T20:15:20.000Z","updated_at":"2025-03-10T14:57:08.000Z","dependencies_parsed_at":"2025-02-28T12:08:51.887Z","dependency_job_id":"2f6f33ee-c4e0-4557-95f5-37bd1f7c27dc","html_url":"https://github.com/SymfonyTest/SymfonyConfigTest","commit_stats":{"total_commits":85,"total_committers":31,"mean_commits":"2.7419354838709675","dds":0.6470588235294117,"last_synced_commit":"e7db0f5ea98817c7ba1b9266f8039c085e673db4"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymfonyTest%2FSymfonyConfigTest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymfonyTest%2FSymfonyConfigTest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymfonyTest%2FSymfonyConfigTest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymfonyTest%2FSymfonyConfigTest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SymfonyTest","download_url":"https://codeload.github.com/SymfonyTest/SymfonyConfigTest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248762418,"owners_count":21157733,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["symfony","symfony-bundle"],"created_at":"2024-10-03T02:05:31.138Z","updated_at":"2025-04-13T18:37:47.691Z","avatar_url":"https://github.com/SymfonyTest.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Symfony Config Test\n\n*By Matthias Noback and contributors*\n\n[![Build Status](https://github.com/SymfonyTest/SymfonyConfigTest/actions/workflows/ci.yaml/badge.svg)](https://github.com/SymfonyTest/SymfonyConfigTest/actions/workflows/ci.yaml)\n\nWriting configuration classes using the [Symfony Config\nComponent](https://symfony.com/doc/current/components/config/definition.html) can be quite hard. To help you verify the\nvalidity of the resulting config node tree, this library provides a PHPUnit test case and some custom assertions.\n\n## Installation\n\nUsing Composer:\n\n    composer require --dev matthiasnoback/symfony-config-test\n\n## Usage\n\nCreate a test case and use the trait from ``Matthias\\SymfonyConfigTest\\PhpUnit\\ConfigurationTestCaseTrait``.\nThen implement ``getConfiguration()``:\n\n```php\n\u003c?php\n\nuse Matthias\\SymfonyConfigTest\\PhpUnit\\ConfigurationTestCaseTrait;\nuse PHPUnit\\Framework\\TestCase;\nuse App\\Configuration;\n\nclass ConfigurationTest extends TestCase\n{\n    use ConfigurationTestCaseTrait;\n\n    protected function getConfiguration(): Configuration\n    {\n        return new Configuration();\n    }\n}\n```\n\n### Test invalid configuration values\n\nLet's assume the ``Configuration`` class you want to test looks like this:\n\n```php\n\u003c?php\n\nuse Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder;\nuse Symfony\\Component\\Config\\Definition\\ConfigurationInterface;\n\nclass ConfigurationWithRequiredValue implements ConfigurationInterface\n{\n    public function getConfigTreeBuilder(): TreeBuilder\n    {\n        $treeBuilder = new TreeBuilder();\n\n        $rootNode = $treeBuilder-\u003eroot('root');\n        $rootNode\n            -\u003eisRequired()\n            -\u003echildren()\n                -\u003escalarNode('required_value')\n                    -\u003eisRequired()\n                -\u003eend()\n            -\u003eend();\n\n        return $treeBuilder;\n    }\n}\n```\n\nWhen you provide an empty array as the value for this configuration, you would expect an exception since the\n``required_value`` node is required. You can assert that a given set of configuration values is invalid using the\n``assertConfigurationIsInvalid()`` method:\n\n```php\n\u003c?php\n\nuse Matthias\\SymfonyConfigTest\\PhpUnit\\ConfigurationTestCaseTrait;\nuse PHPUnit\\Framework\\TestCase;\n\nclass ConfigurationTest extends TestCase\n{\n    use ConfigurationTestCaseTrait;\n\n    /**\n     * @test\n     */\n    public function values_are_invalid_if_required_value_is_not_provided(): void\n    {\n        $this-\u003eassertConfigurationIsInvalid(\n            [\n                [] // no values at all\n            ],\n            'required_value' // (part of) the expected exception message - optional\n        );\n    }\n}\n```\n\n### Test processed configuration values\n\nYou may also want to verify that after processing an array of configuration values the result will be as expected:\n\n```php\n\u003c?php\n\nuse Matthias\\SymfonyConfigTest\\PhpUnit\\ConfigurationTestCaseTrait;\nuse PHPUnit\\Framework\\TestCase;\n\nclass ConfigurationTest extends TestCase\n{\n    use ConfigurationTestCaseTrait;\n\n    /**\n     * @test\n     */\n    public function processed_value_contains_required_value(): void\n    {\n        $this-\u003eassertProcessedConfigurationEquals([\n            ['required_value' =\u003e 'first value'],\n            ['required_value' =\u003e 'last value']\n        ], [\n            'required_value'=\u003e 'last value'\n        ]);\n    }\n}\n```\n\nPlease note: the first argument of each of the ``assert*`` methods is an *array of arrays*. The extra nesting level\nallows you to test the merge process. See also the section [Merging\noptions](https://symfony.com/doc/current/components/config/definition.html#merging-options) of the Config Component\ndocumentation.\n\n### Test a subset of the configuration tree\n\nUsing this library it's possible to test just one branch of your configuration tree. Consider the following node tree\ndefinition, which contains the branches `array_node_1` and `array_node_2`:\n\n```php\n\u003c?php\n\nuse Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder;\nuse Symfony\\Component\\Config\\Definition\\ConfigurationInterface;\n\nclass ConfigurationWithTwoBranches implements ConfigurationInterface\n{\n    public function getConfigTreeBuilder(): TreeBuilder\n    {\n        $treeBuilder = new TreeBuilder();\n\n        $rootNode = $treeBuilder-\u003eroot('root');\n        $rootNode\n            -\u003echildren()\n                -\u003earrayNode('array_node_1')\n                    -\u003eisRequired()\n                    -\u003echildren()\n                        -\u003escalarNode('required_value_1')\n                            -\u003eisRequired()\n                        -\u003eend()\n                    -\u003eend()\n                -\u003eend()\n                -\u003earrayNode('array_node_2')\n                    -\u003eisRequired()\n                    -\u003echildren()\n                        -\u003escalarNode('required_value_2')\n                            -\u003eisRequired()\n                        -\u003eend()\n                    -\u003eend()\n                -\u003eend()\n            -\u003eend();\n\n        return $treeBuilder;\n    }\n}\n```\n\nIf you want to test, for instance, only the `array_node_1` branch from the example below, and ignore the `array_node_2`,\nprovide `array_node_1` as the argument for the `$breadcrumbPath` parameter of the test helper functions, for example:\n\n```php\n/**\n * @test\n */\npublic function processed_configuration_for_array_node_1(): void\n{\n    $this-\u003eassertProcessedConfigurationEquals(\n        [\n            ['array_node_1' =\u003e ['required_value_1' =\u003e 'original value']],\n            ['array_node_1' =\u003e ['required_value_1' =\u003e 'final value']]\n        ],\n        [\n            'array_node_1' =\u003e [\n                'required_value_1' =\u003e 'final value'\n            ]\n        ],\n        // the path of the nodes you want to focus on in this test:\n        'array_node_1'\n    );\n}\n```\n\nThis would trigger no validation errors for any value in the `array_node_2` branch.\n\nNote that the `$breadcrumbPath` can be even more specific, e.g. `\"doctrine.orm\"` (which would skip configuration\nprocessing for branch `\"doctrine.dbal\"`, etc.).\n\nAlso note that you can only traverse over array nodes using the `.` in the breadcrumb path. The last part of the breadcrumb path can be any other type of node.\n\n#### Test a subset of the prototyped configuration tree\n\nYou can traverse through prototype array nodes using `*` as its name in the breadcrumb path.\n\n```php\n\u003c?php\n\nuse Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder;\nuse Symfony\\Component\\Config\\Definition\\ConfigurationInterface;\n\nclass PrototypedConfiguration implements ConfigurationInterface\n{\n    public function getConfigTreeBuilder(): TreeBuilder\n    {\n        $treeBuilder = new TreeBuilder();\n\n        $rootNode = $treeBuilder-\u003eroot('root');\n        $rootNode\n            -\u003echildren()\n                -\u003earrayNode('array_node')\n                    -\u003euseAttributeAsKey('name')\n                    -\u003eprototype('array')\n                        -\u003echildren()\n                            -\u003escalarNode('default_value')-\u003ecannotBeEmpty()-\u003edefaultValue('foobar')-\u003eend()\n                            -\u003escalarNode('required_value')-\u003eisRequired()-\u003eend()\n                        -\u003eend()\n                    -\u003eend()\n                -\u003eend()\n            -\u003eend();\n\n        return $treeBuilder;\n    }\n}\n```\n\nIf you want to test whether `default_value` is set to `foobar` by default, but don't want the test to be affected by\nrequirements on `required_value` node, you can define its path as `array_node.*.default_value`, for example:\n\n```php\n/**\n * @test\n */\npublic function processed_configuration_for_array_node_1(): void\n{\n    $this-\u003eassertProcessedConfigurationEquals(\n        [\n            ['array_node' =\u003e ['prototype_name' =\u003e null]],\n        ],\n        [\n            'array_node' =\u003e [\n                'prototype_name' =\u003e [\n                    'default_value' =\u003e 'foobar'\n                ]\n            ]\n        ],\n        // the path of the nodes you want to focus on in this test:\n        'array_node.*.default_value'\n    );\n}\n```\n\n## Version Guidance\n\n| Version | Released     | PHPUnit                | Status   |\n|---------|--------------|------------------------|----------|\n| 6.x     | Feb 7, 2025  | 10.5 and 11.x and 12.x | Latest   |\n| 5.x     | Jun 2, 2023  | 9.6 and 10.x and 11.x  | Bugfixes |\n| 4.x     | Mar 5, 2018  | 7.x and 8.x and 9.x    | EOL      |\n| 3.x     | Nov 30, 2017 | 6.x                    | EOL      |\n| 2.x     | Jun 18, 2016 | 4.x and 5.x            | EOL      |\n| 1.x     | Oct 12, 2014 | 3.x                    | EOL      |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymfonytest%2Fsymfonyconfigtest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsymfonytest%2Fsymfonyconfigtest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymfonytest%2Fsymfonyconfigtest/lists"}