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 Mocker Container Laravel Package

polishsymfonycommunity/symfony-mocker-container

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Limited Laravel Compatibility: This package is Symfony-specific (targets Symfony’s DI container) and lacks native Laravel integration. Laravel uses its own Container (Illuminate\Container\Container) and Service Provider architecture, which differs fundamentally from Symfony’s ContainerInterface. The package’s core functionality (mocking services in the DI container) is theoretically useful, but the implementation is tightly coupled to Symfony’s AppKernel and Container classes.
  • Test-Driven Use Case: The package is designed for functional/integration testing (e.g., Behat, Symfony functional tests). Laravel already has robust testing tools (Mockery, PHPUnit, Laravel’s HTTP tests, and PestPHP), reducing the need for this package unless testing Symfony-like workflows (e.g., legacy monoliths or hybrid apps).
  • Opportunity for Abstraction: If the goal is mocking container services in tests, Laravel’s existing tools (e.g., partial mocks, Mockery, or Laravel’s createMock()`) may suffice. However, if the team is migrating from Symfony or needs Symfony-compatible testing, this could bridge the gap—but with trade-offs.

Integration Feasibility

  • High Effort for Laravel: Requires wrapper classes or adapters to translate Symfony’s MockerContainer into Laravel’s context. Key challenges:
    • Laravel’s Container does not extend Symfony’s ContainerInterface, so direct replacement is impossible.
    • Symfony’s AppKernel equivalent in Laravel is Kernel (or FoundationApplication), but its getContainerBaseClass() method doesn’t exist.
    • Workaround: Could extend Laravel’s Container or use a decorator pattern, but this introduces complexity and maintenance overhead.
  • Alternative Approaches:
    • Use Laravel’s built-in testing helpers (e.g., Mockery, partial mocks).
    • Leverage PestPHP’s plugins (e.g., pest-plugin-laravel for mocking).
    • For Symfony interop, consider Symfony’s HttpKernel in Laravel (e.g., via symfony/http-kernel) and mock services there.

Technical Risk

  • Breaking Changes: The package is abandoned (last release 2022) and marked as a "hack" by its maintainers. Risks include:
    • Compatibility drift with newer Symfony/Laravel versions.
    • No Laravel-specific support, leading to edge cases in integration.
    • Performance overhead if mocking is overused (Symfony’s container is optimized differently than Laravel’s).
  • Testing Quirks:
    • The warning about BrowserKitDriver dependency suggests mocking fails for HTTP-based tests (e.g., Laravel’s HttpTests). This could limit use to non-HTTP test scenarios (e.g., CLI commands, Artisan).
    • State pollution: Mocking services globally (via container replacement) may cause unintended side effects in tests.

Key Questions for TPM

  1. Why Laravel?
    • Is this for Symfony-to-Laravel migration? If so, what’s the scope (full app or partial)?
    • Are there legacy Symfony dependencies requiring this package?
  2. Testing Strategy
    • What’s the current testing stack (PHPUnit, Pest, Behat)? Does this package add unique value?
    • Are there HTTP-based tests (e.g., API routes)? If yes, this package may not work.
  3. Maintenance Burden
    • Who will maintain the integration layer (wrapper/adapters)?
    • What’s the deprecation plan if Laravel evolves away from Symfony interop?
  4. Alternatives
    • Has Laravel’s native testing (e.g., Mockery, Pest) been explored?
    • Could Symfony’s TestDoubleBundle (recommended by maintainers) be adapted instead?
  5. Performance
    • Will mocking all services in the container impact test speed?
    • Are there selective mocking requirements (e.g., only certain services)?

Integration Approach

Stack Fit

  • Laravel’s Container vs. Symfony’s Container:
    • Laravel’s Illuminate\Container\Container is not compatible with Symfony’s ContainerInterface. Direct integration is not feasible without a proxy layer.
    • Symfony Components in Laravel: If using Symfony’s HttpKernel (e.g., for legacy code), this package could work in that context, but not globally.
  • Testing Frameworks:
    • PHPUnit/Pest: Prefer native Laravel tools (Mockery, createMock()).
    • Behat: Laravel’s LaravelExtension or BehatSymfonyExtension may offer better alternatives.
  • Hybrid Apps: If Laravel shares a microkernel with Symfony, this package might fit, but requires custom bootstrapping.

Migration Path

  1. Assessment Phase:
    • Audit test dependencies to identify if this package is truly needed.
    • Benchmark alternatives (e.g., Mockery, Pest, TestDoubleBundle).
  2. Proof of Concept (PoC):
    • Create a wrapper class to adapt MockerContainer for Laravel’s Container.
    • Example:
      class LaravelMockerContainer extends Illuminate\Container\Container {
          public function resolve($id) {
              if (in_array($this->environment(), ['testing'])) {
                  return $this->mockResolve($id); // Custom logic
              }
              return parent::resolve($id);
          }
      }
      
    • Test with non-HTTP tests (e.g., Artisan commands).
  3. Limited Rollout:
    • Restrict usage to specific test suites (e.g., legacy Symfony modules).
    • Avoid global container replacement to minimize risk.
  4. Fallback Plan:
    • If integration fails, abandon the package and refactor tests to use Laravel-native tools.

Compatibility

  • Symfony 4/5/6: The package targets older Symfony (pre-5.0). No guarantee it works with Symfony 6+.
  • Laravel 8/9/10: No official support. May require PHP 8.1+ compatibility fixes.
  • Dependencies:
    • Requires symfony/dependency-injection and symfony/http-kernel.
    • Conflicts possible with Laravel’s symfony/console or symfony/http-foundation.

Sequencing

  1. Phase 1: Replace Symfony-specific tests with Laravel-native alternatives (e.g., HttpTests, Mockery).
  2. Phase 2: If Symfony interop is unavoidable, integrate MockerContainer only for legacy modules.
  3. Phase 3: Deprecate the package in favor of modern testing tools (e.g., PestPHP, Mockery 2).

Operational Impact

Maintenance

  • High Overhead:
    • Custom wrapper code will need updates for Laravel/Symfony minor versions.
    • No upstream support: Bug fixes or features require manual patches.
  • Testing Debt:
    • Mocking at the container level can obscure test failures (e.g., "Is this a mock issue or real logic?").
    • Flaky tests if mocks aren’t reset properly between runs.

Support

  • Limited Ecosystem:
    • No Laravel-specific documentation or community support.
    • Debugging issues will rely on Symfony’s DI internals, which differ from Laravel’s.
  • Onboarding:
    • Developers unfamiliar with Symfony’s Container may struggle to diagnose mocking failures.

Scaling

  • Performance:
    • Global container mocking can slow down tests (especially in CI).
    • Memory leaks possible if mocks aren’t garbage-collected.
  • Team Adoption:
    • Resistance if the team prefers Laravel’s native tools.
    • Training needed to explain why Symfony-specific code is used.

Failure Modes

  1. HTTP Tests Break:
    • As warned, any test making HTTP requests (e.g., HttpTests) will fail with this package.
  2. Container Pollution:
    • Mocks may leak into non-test code if not isolated (e.g., via AppServiceProvider booting).
  3. Version Conflicts:
    • Symfony/Laravel version mismatches could break DI resolution.
  4. Maintenance Abandonment:
    • If the team moves away from Symfony, this package becomes dead weight.

Ramp-Up

  • Learning Curve:
    • Developers must understand both Laravel and Symfony’s DI systems.
    • Debugging requires knowledge of MockerContainer internals.
  • Tooling Gaps:
    • No IDE support (e.g., PHPStorm autocompletion for mocked services).
    • No built-in test helpers (e.g., Pest plugins for container mocking).
  • Migration Cost:
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui