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

Time Mock Bundle Laravel Package

acts/time-mock-bundle

Symfony bundle for mocking and controlling time in tests and development. Freeze, fast-forward, and reset “now” to make time-dependent code deterministic, simplify assertions, and avoid flaky tests across DateTime/Clock usage.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The acts/time-mock-bundle is a time-mocking utility tailored for Symfony2 applications, enabling deterministic testing by replacing dynamic time calls (e.g., time(), DateTime, Carbon) with mock values. This is particularly valuable for:
    • Unit/integration testing where time-sensitive logic (e.g., expiration checks, scheduled tasks, rate limiting) must be isolated from real-world time.
    • Feature development where predictable time states (e.g., "simulate a future date") are required without manual clock adjustments.
    • CI/CD pipelines to ensure consistent test execution across environments.
  • Symfony2-Specific: The bundle is Symfony2-only, which may limit adoption in modern Laravel ecosystems unless abstracted via a facade or adapter layer. However, its core concept (time mocking) is language-agnostic and could be repurposed.
  • Laravel Compatibility: Laravel’s built-in Carbon and now() helpers already support mocking via dependency injection or testing utilities (e.g., travel() in Laravel’s Testing facade). This bundle’s value in Laravel is marginal unless it offers unique features (e.g., global time overrides, Symfony-specific integrations like Swiftmailer timestamps).

Integration Feasibility

  • Core Functionality:
    • Mocking time(): Replace PHP’s native time() with a static value (e.g., 2023-01-01).
    • Mocking DateTime/Carbon: Intercept instantiations to return predefined dates.
    • Service Container Integration: Likely uses Symfony’s DI to override time-related services (e.g., clock).
  • Laravel Workarounds:
    • Manual Mocking: Laravel’s Mockery or PHPUnit’s getMockBuilder can replicate time mocking without a bundle.
    • Testing Facades: Laravel’s Testing facade provides travel() for Carbon mocking:
      use Illuminate\Support\Facades\Time;
      Time::travel($date);
      
    • Service Providers: A custom Laravel service provider could wrap the bundle’s logic, but this introduces unnecessary complexity for a feature already natively supported.
  • Key Dependencies:
    • Symfony Components: Relies on Symfony’s HttpKernel, DependencyInjection, and possibly EventDispatcher. Laravel’s architecture differs significantly, requiring shims or wrappers for integration.

Technical Risk

Risk Area Assessment
Architecture Mismatch High. Symfony2’s event-driven, service-container-heavy architecture contrasts with Laravel’s lighter, facade-based design. Direct integration would require significant refactoring or a proxy layer.
Maintenance Overhead Medium. If adopted, the bundle would need ongoing adaptation to Laravel’s evolving APIs (e.g., Carbon updates, testing utilities).
Testing Coverage Low. The bundle’s lack of stars/dependents suggests unproven reliability. Testing edge cases (e.g., timezone handling, nested mocks) would be critical.
Performance Impact Low. Time mocking is typically lightweight, but global overrides (e.g., replacing time()) could introduce subtle bugs if not scoped properly.
Alternatives High. Laravel’s native tools (travel(), Mockery, partialMock) already solve 90% of use cases. The bundle offers no clear advantage unless targeting Symfony-specific integrations.

Key Questions

  1. Why Laravel?

    • Does the team have legacy Symfony2 codebases being incrementally migrated to Laravel, requiring a stopgap solution?
    • Are there Symfony-specific dependencies (e.g., Swiftmailer, Doctrine) that necessitate this bundle’s time-mocking behavior?
  2. Feature Gaps

    • Does the bundle support timezone-aware mocking? Laravel’s Carbon handles this natively.
    • Can it mock non-Carbon time sources (e.g., strtotime, DateTimeImmutable) without conflicts?
  3. Integration Strategy

    • Would a custom Laravel package (e.g., laravel-time-mock) be preferable to avoid Symfony dependencies?
    • Could the bundle’s logic be extracted into a standalone library (e.g., php-time-mock) for broader use?
  4. Testing Scope

    • What percentage of tests require time mocking? If <20%, native Laravel tools may suffice.
    • Are there performance-sensitive paths where mocking could introduce regressions?
  5. Long-Term Viability

    • Is Symfony2 support being actively maintained? If not, the bundle risks bitrot.
    • Would the team commit to maintaining a Laravel fork if adopted?

Integration Approach

Stack Fit

  • Symfony2 Stack: Native fit. The bundle is designed for Symfony2’s service container, event system, and HttpKernel.
  • Laravel Stack: Poor fit without abstraction. Laravel’s:
    • Service Container: Uses Illuminate\Container, not Symfony’s DependencyInjection.
    • Testing Tools: Built-in travel() and Mockery reduce need for external bundles.
    • Carbon: Already supports mocking via Testing facade.
  • Hybrid Stacks (Symfony + Laravel):
    • Possible in monolithic apps with Symfony2 microservices, but not recommended due to maintenance overhead.
    • Alternative: Use Symfony’s ClockInterface in shared libraries and mock it via Laravel’s DI.

Migration Path

Scenario Approach
Greenfield Laravel Avoid. Use Laravel’s native Time::travel() or Mockery for time mocking.
Symfony2 → Laravel Phase Out: Replace Symfony-specific time usages with Laravel equivalents before adopting this bundle.
Hybrid App Isolate: Containerize Symfony2 services and mock time at the API boundary (e.g., using Guzzle to call a Symfony2 mock endpoint with frozen time).
Legacy Codebase Wrapper Layer: Create a Laravel service provider that proxies the bundle’s logic, translating Symfony events/services to Laravel equivalents. High effort; evaluate ROI.

Compatibility

  • PHP Version: Check if the bundle supports Laravel’s PHP version (e.g., 8.0+). Older Symfony2 bundles may lag.
  • Carbon Version: Ensure compatibility with Laravel’s Carbon instance (e.g., nesbot/carbon vs. Symfony’s symfony/polyfill-php80).
  • Testing Frameworks: If using Pest or PHPUnit, confirm the bundle doesn’t conflict with Laravel’s test helpers.
  • Service Providers: The bundle likely registers as a Symfony Bundle. In Laravel, this would require:
    // Example pseudo-integration (hypothetical)
    $app->bind('time_mocker', function ($app) {
        return new TimeMockBundle(); // Would need significant adaptation
    });
    

Sequencing

  1. Assess Need:
    • Audit tests to quantify time-mocking requirements. If <10%, native tools suffice.
  2. Prototype:
    • Test the bundle in a Symfony2 subdirectory or Docker container to validate functionality.
  3. Abstraction Layer:
    • If adoption is justified, build a Laravel-compatible facade that delegates to the bundle (e.g., via process isolation).
  4. Fallback Plan:
    • Document a migration path to Laravel’s native tools if the bundle becomes unsustainable.

Operational Impact

Maintenance

  • Symfony Dependency Risk:
    • The bundle’s reliance on Symfony components (e.g., EventDispatcher, HttpKernel) could break with Laravel updates.
    • Mitigation: Pin Symfony dependencies to exact versions or use composer’s replace to avoid conflicts.
  • Testing Overhead:
    • Additional tests may be needed to verify mocking behavior across:
      • Different Carbon versions.
      • Timezone-aware operations.
      • Edge cases (e.g., DateTime::createFromFormat).
  • Documentation:
    • Lack of Laravel-specific docs means internal documentation would be required to explain:
      • How to scope mocks (e.g., per-test vs. global).
      • Handling conflicts with Laravel’s Time facade.

Support

  • Community Support:
    • Low. No stars/dependents indicate minimal community adoption. Issues would require self-reliance or Symfony2-specific forums.
  • Vendor Lock-in:
    • Tight coupling to Symfony2 patterns could make future migrations costly.
  • Debugging Complexity:
    • Time-mocking bugs (e.g., incorrect now() values in async jobs) may be harder to trace than native Laravel tools.

Scaling

  • Performance:
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.
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle
dmstr/api-platform-utils-bundle
dmstr/api-configuration-bundle
chrisdev/ux-components
baks-dev/finances
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