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

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

A simple bundle for Symfony2 which enables the current time to be mocked.

Frequently asked questions about Time Mock Bundle
Can I use acts/time-mock-bundle in Laravel, or is it only for Symfony?
This bundle is designed for Symfony, but its core time-mocking logic can be adapted for Laravel via a facade or service provider wrapper. Laravel already has built-in tools like `Time::travel()` for Carbon, so direct integration isn’t seamless without extra work. If you’re migrating from Symfony or need Symfony-specific integrations (e.g., Swiftmailer timestamps), it might still be useful.
How do I freeze time at a specific date in Laravel using this bundle?
Since this bundle isn’t natively Laravel-compatible, you’d need to wrap its functionality in a Laravel service provider or facade. For example, you could override `now()` or Carbon’s `create()` methods to use the bundle’s time-mocking logic. Laravel’s native `Time::freeze()` (via `laravel/time`) is a simpler alternative for most cases.
Does acts/time-mock-bundle support timezone-aware time mocking?
The bundle’s Symfony-centric design may not handle timezones as elegantly as Laravel’s Carbon, which natively supports timezone-aware mocking. You’d need to verify if the bundle’s mocking layer accounts for timezone offsets or if you’d need to manually adjust mocked dates. Laravel’s `Time::travel($date->setTimezone('UTC'))` is often more straightforward.
Will this bundle work with Laravel’s testing utilities like `travel()`?
No, this bundle doesn’t integrate with Laravel’s testing utilities. Laravel’s `Time::travel()` is designed specifically for Carbon and works out of the box, while this bundle would require custom setup to interact with Laravel’s time helpers. Using both simultaneously could lead to conflicts or unpredictable behavior.
Can I mock non-Carbon time functions like `strtotime()` or `DateTimeImmutable` with this package?
The bundle primarily targets Symfony’s time services and may not cover all PHP time functions like `strtotime()` or `DateTimeImmutable` out of the box. Laravel’s native tools or a standalone library like `mockery` would be more reliable for mocking these functions. You’d need to test if the bundle’s overrides extend to these cases.
Is acts/time-mock-bundle actively maintained? How often are updates released?
The bundle’s maintenance status isn’t clear from available data, and it has limited adoption (few stars/dependents). If you rely on it, monitor its GitHub activity or consider alternatives like Laravel’s built-in testing tools or standalone libraries. Symfony’s ecosystem shifts may also affect compatibility if you later migrate away from Symfony.
How do I install acts/time-mock-bundle in a Laravel project?
You can’t install it directly via Composer for Laravel—it’s a Symfony bundle. You’d need to manually integrate it by creating a Laravel service provider to bridge its functionality. For example, you could publish its configuration and override Laravel’s time-related services. This adds complexity and isn’t recommended unless you have specific Symfony dependencies.
Are there performance concerns with globally mocking time in Laravel?
Globally mocking time can introduce subtle bugs if not scoped properly, especially in long-running processes or multi-threaded environments. Laravel’s `Time::travel()` is designed to be safe for testing and resets automatically after assertions. This bundle’s global overrides might require careful cleanup to avoid test pollution or production issues.
What’s a better alternative to acts/time-mock-bundle for Laravel?
For Laravel, use the built-in `Time` facade (e.g., `Time::travel()`, `Time::freeze()`) or `Mockery` for granular control. Packages like `laravel-time` or `spatie/laravel-test-factories` also simplify time mocking. If you need Symfony-specific features, consider abstracting the bundle’s logic into a standalone library or using a Laravel-compatible wrapper.
Can acts/time-mock-bundle help with testing token expiration logic in Laravel?
Yes, but only if you adapt it for Laravel. The bundle’s core strength is making time deterministic, which is perfect for testing expirations. However, Laravel’s `Time::travel()` already handles this natively for Carbon-based logic. For non-Carbon cases (e.g., custom expiration handlers), you’d need to ensure the bundle’s mocking layer covers all relevant time functions.
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