Add first-class PHP configuration format - #6946
#6946Open
TavoNiievez wants to merge 1 commit into
Open
Add first-class PHP configuration format#6946TavoNiievez wants to merge 1 commit into
TavoNiievez wants to merge 1 commit into
Conversation
TavoNiievez
force-pushed
the
php_config
branch
2 times, most recently
from
July 7, 2026 23:42
8ddfeaf to
17c7e25
Compare
- Introduced support for PHP configuration files alongside YAML. - Updated Api, Unit, and Bootstrap templates to generate PHP config files. - Added methods to handle PHP config generation and validation. - Enhanced test cases to validate the new PHP configuration format. - Migrated existing YAML configurations to PHP format in tests. - Improved error handling and output for configuration validation. - Added new test cases to ensure compatibility and correctness of the new configuration system.
Member
Author
|
I added this example PR to demonstrate the functionality and the new API: Codeception/symfony-module-tests#66 |
Member
Author
|
cc. @ThomasLandauer , @burned42 & @samsonasik |
Member
|
Moving away from YAML is an excellent idea IMO! Symfony just moved away from PHP methods to PHP arrays (e.g. |
Member
|
Detail while looking at Codeception/symfony-module-tests#66 (comment) |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a PHP configuration format as a first-class alternative to YAML, designed to become the canonical way to configure Codeception in future versions. A
codeception.php(or*.suite.php/ env file) returns a fluent builder — or a raw array — instead of YAML. This unlocks IDE autocomplete, PHPStan-checkable config,::classconstants, nativegetenv(), and real PHP expressions (E_ALL & ~E_DEPRECATED), while keeping a 1:1 mapping to every existing YAML key. YAML is untouched and remains the default — the PHP format is fully opt-in.What's new
Builder API (
src/Codeception/Config/, namespaceCodeception\Config\):GlobalConfig,SuiteConfig(bothfinal),ConfigInterface(forever-contract =toArray()only),AbstractConfigBuilder(@internal),Params.module(),moduleConfig(),extension(),suite(),env(),commands()) + one raw escape hatchmerge().settings()uses explicit named nullable params (camelCase → snake_case) for autocomplete.Loader (
Configuration.php): per role (global / suite / env), if any.phpvariant exists, PHP wins and YAML is ignored — one rule everywhere. Config files are loaded exactly once, inside an isolated closure wrapped in output buffering (strayechocan't corrupt--xml/--jsonoutput), with concrete-type guards (aSuiteConfigreturned in global position throws a clear error naming the file and expected type). Cross-formatextendsworks both directions.Params:
%param%stays YAML-only; PHP configs usegetenv()in the global file andParams::get()in suite/env files (with a self-explaining exception ifParams::get()is called too early during global load).Tooling & scaffolding:
config:validatenow reports the loaded config file path.config:to-php— new command migrating existing YAML projects to builder-style PHP (--dry-runprints without writing; rendererLib/Generator/PhpConfigFile.php).bootstrap,init,g:suite,g:envgain PHP output;g:suite/g:envdetect the project format and no longer risk generating a silently-shadowed file when the other extension already exists.Design notes
Codeception\Config\namespace deliberately avoids colliding with the existingCodeception\Configurationclass.$defaultConfig/$defaultSuiteSettingskey gains no builder method — the canonical API can't silently lag core.merge()renamed fromwith()sincewith*implies immutable clone in PHP.lib-configpackage,var_exportarray generation. (Rationale available on request.)Backward compatibility
Non-breaking and additive. YAML behavior is unchanged; YAML remains the default scaffold. Flipping the default to PHP, and any future YAML deprecation, is left as a maintainer decision — not smuggled in here.
Tests
tests/unit/Codeception/Config/): every builder method → expected key/value, snake_case mapping, guards,merge()order, drift-guards,Params::get()timing.tests/cli/ConfigPhpFormatCest.php): discovery, php-wins, env-wins, cross-format extends, type/echo/invalid-return errors, inline-suite shadowing,config:to-phpmigrate → build → run.run cli,unit,coverage), plusphpstan analyse srcandcomposer cs-testsclean.Unrelated changes (disclosed)
This commit also bumps CI actions:
actions/checkout@v6 → v7andactions/cache@v3 → v6in.github/workflows/build.yml. Not history-rewritten; called out here for review.