Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Symfony Config Test Laravel Package

matthiasnoback/symfony-config-test

PHPUnit helpers for testing Symfony Config definitions. Provides a test case trait and assertions to validate config trees, ensuring required nodes, types, and constraints behave as expected by asserting valid and invalid configuration arrays.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony Config Component Integration: The package is designed specifically for testing Symfony’s Config component, which is a common dependency in Laravel applications using Symfony bundles (e.g., Symfony Mailer, Symfony HTTP Client, or custom Symfony-based packages). If the Laravel application leverages Symfony’s configuration system (e.g., via spatie/laravel-config or custom Symfony bundles), this package provides a direct fit for validating configuration logic.
  • Laravel Compatibility: While Laravel does not natively use Symfony’s Config component, the package can still be useful in:
    • Hybrid Symfony/Laravel apps (e.g., API platforms using Symfony components).
    • Laravel packages that abstract Symfony’s configuration (e.g., for microservices or modular setups).
    • Testing complex validation logic in Laravel’s config/ files (via custom ConfigurationInterface implementations).
  • Test-Driven Validation: The package excels at assertion-based testing of configuration trees, which is valuable for ensuring correctness in:
    • Required/optional fields.
    • Default values.
    • Merging logic (e.g., environment-specific overrides).
    • Prototype nodes (e.g., repeated configurations like database connections).

Integration Feasibility

  • Low Coupling: The package is dev-only (installed via --dev) and does not modify runtime behavior. It integrates via PHPUnit traits, requiring minimal boilerplate.
  • Symfony Dependency: Requires the symfony/config package (v4.4+ or v5.0–5.3). If the Laravel app already uses Symfony components, this is a non-issue. Otherwise, adding it as a dev dependency is straightforward.
  • PHPUnit Dependency: Requires PHPUnit 9.6–13.x. Most modern Laravel projects already meet this requirement.
  • Laravel-Specific Workarounds:
    • If testing Laravel’s native config/ files, a wrapper class would need to implement ConfigurationInterface to bridge Symfony’s TreeBuilder with Laravel’s array-based config.
    • For packages using Symfony’s Config component (e.g., spatie/laravel-symfony-mailer), integration is seamless.

Technical Risk

Risk Area Assessment Mitigation Strategy
Symfony Dependency Adds symfony/config to dev dependencies; may conflict with existing Symfony versions. Pin to a compatible version (e.g., ^5.4) and audit for version conflicts.
Laravel Config Gap Native Laravel config is not Symfony-compatible; requires abstraction layer. Create a thin adapter class to translate Laravel config arrays to Symfony’s TreeBuilder.
Test Complexity Advanced features (e.g., prototype nodes, breadcrumb paths) may require steep learning curve. Start with basic assertions (assertConfigurationIsInvalid, assertProcessedConfigurationEquals) and gradually adopt advanced features.
Maintenance Overhead Package is actively maintained (last release: 2026), but Laravel’s config system evolves separately. Monitor Symfony Config Component updates and adapt wrapper classes as needed.

Key Questions for the TPM

  1. Use Case Clarity:
    • Is this package being considered for Symfony-integrated Laravel packages (e.g., API platforms) or native Laravel config validation?
    • If the latter, what is the scope of the configuration logic needing validation (e.g., app-wide, package-specific)?
  2. Dependency Impact:
    • Does the Laravel app or its packages already use symfony/config? If not, what is the justification for adding it?
    • Are there existing PHPUnit constraints or custom test helpers for config validation that could be deprecated?
  3. Adoption Strategy:
    • Should this be adopted project-wide (for all config-related tests) or incrementally (for critical packages first)?
    • Are there performance implications for running Symfony’s Config component in a Laravel test suite?
  4. Alternative Evaluation:
    • Could Laravel’s native testing tools (e.g., phpunit/assertions) or custom assertions achieve similar goals with less overhead?
    • Are there other packages (e.g., phpunit/phpunit, symfony/yaml) that could complement or replace this?
  5. Long-Term Viability:
    • How would this package interact with Laravel’s upcoming features (e.g., config caching, livewire config, or Vapor deployments)?
    • Is the team comfortable maintaining a custom adapter layer for Laravel-specific use cases?

Integration Approach

Stack Fit

  • Primary Fit:
    • Symfony/Laravel Hybrid Apps: Ideal for projects using Symfony components (e.g., Symfony Mailer, HTTP Client, or custom bundles).
    • Laravel Packages with Symfony Config: Packages like spatie/laravel-symfony-mailer or custom packages using symfony/config can directly leverage this package.
  • Secondary Fit:
    • Native Laravel Config Testing: Requires a wrapper class to bridge Laravel’s config/ arrays with Symfony’s TreeBuilder. Example:
      class LaravelConfigAdapter implements ConfigurationInterface {
          public function getConfigTreeBuilder(): TreeBuilder {
              $treeBuilder = new TreeBuilder();
              $rootNode = $treeBuilder->root('app');
              // Map Laravel's config structure to Symfony's TreeBuilder
              return $treeBuilder;
          }
      }
      
  • Non-Fit:
    • Projects relying exclusively on Laravel’s native config system without Symfony dependencies.

Migration Path

  1. Assessment Phase:
    • Audit existing config validation logic (e.g., manual assertions, custom helpers).
    • Identify critical configuration trees that need rigorous testing (e.g., database, queue, cache).
  2. Dependency Setup:
    • Add symfony/config and matthiasnoback/symfony-config-test to composer.json under require-dev.
    • Pin versions to avoid conflicts (e.g., symfony/config: ^5.4, phpunit/phpunit: ^10.0).
  3. Adapter Layer (If Needed):
    • For native Laravel config, create a ConfigurationInterface implementation that mirrors config/app.php or package-specific config.
    • Example:
      class AppConfiguration implements ConfigurationInterface {
          public function getConfigTreeBuilder(): TreeBuilder {
              $treeBuilder = new TreeBuilder();
              $rootNode = $treeBuilder->root('app');
              $rootNode
                  ->children()
                      ->scalarNode('timezone')->defaultValue('UTC')->end()
                      ->arrayNode('queues')
                          ->useAttributeAsKey('connector')
                          ->prototype('array')
                              ->children()
                                  ->scalarNode('driver')->isRequired()->end()
                              ->end()
                          ->end()
                      ->end()
                  ->end();
              return $treeBuilder;
          }
      }
      
  4. Test Migration:
    • Replace manual config validation with the package’s assertions:
      // Before: Manual assertion
      $config = config('app');
      $this->assertArrayHasKey('timezone', $config);
      
      // After: Using SymfonyConfigTest
      $this->assertProcessedConfigurationEquals(
          [['app' => ['timezone' => 'America/New_York']]],
          ['timezone' => 'America/New_York']
      );
      
  5. Incremental Adoption:
    • Start with high-risk configurations (e.g., database, queues) before applying to all tests.
    • Use breadcrumb paths to isolate tests for complex prototype nodes (e.g., database.connections.*).

Compatibility

Component Compatibility Status Notes
PHP 8.1+ (per Symfony 6+ requirements) Laravel 10+ supports this; older versions may need PHP upgrades.
PHPUnit 9.6–13.x Laravel’s default PHPUnit (v9+) is compatible.
Symfony Config 4.4–5.3 or 6.x Ensure no conflicts with existing Symfony bundles.
Laravel Config Requires adapter layer Native Laravel config arrays must be mapped to TreeBuilder.
CI/CD No known conflicts Tests run in isolation; no runtime dependencies.

Sequencing

  1. Phase 1: Dependency Setup
    • Add dependencies and configure composer.json.
    • Update phpunit.xml to ensure PHPUnit version compatibility.
  2. Phase 2: Adapter Development
    • Create ConfigurationInterface implementations for critical config sections.
    • Example: DatabaseConfiguration, QueueConfiguration.
  3. Phase 3: Test Migration
    • Convert 1–2 high-priority test suites to use the new assertions.
    • Validate that existing tests pass with the new approach.
  4. Phase 4: Full Adoption
    • Roll out to remaining config-related tests.
    • Deprecate old validation logic in favor of the new assertions.
  5. **Phase 5: Optimization
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
directorytree/privacy-filter-classifier
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi