sebastian/global-state
sebastian/global-state snapshots and restores PHP global state (globals, superglobals, ini settings, etc.), extracted from PHPUnit as a standalone component. Useful for test isolation and detecting side effects by capturing state before and after code runs.
--process-isolation, TestCase::refreshApplication()). Direct use of sebastian/global-state would be redundant unless addressing edge cases like:
$_SERVER, $_ENV) in application logic.TestCase already provides isolation via refreshApplication() or process isolation.$_SERVER, $_ENV, or $_SESSION in production-like code could introduce vulnerabilities (e.g., path traversal via $_SERVER manipulation).$_SESSION) in concurrent test environments can cause race conditions.$GLOBALS or large superglobals can slow tests significantly.TestCase::refreshApplication(), --process-isolation) instead?Mockery, Faker, or custom test doubles) that reduce reliance on global state?--no-process-isolation for performance and needing fine-grained state control.refreshApplication() (resets all state, including caches).Mockery/Faker (prefer dependency injection over global state).$_SERVER, $_ENV, static properties, or $GLOBALS modifications.dev dependency: composer require --dev sebastian/global-state.Snapshot::snapshot(['globals' => ['$_ENV']])).Snapshot.refreshApplication() and Snapshot may lead to redundant state resets.Snapshot only for granular control (e.g., $_ENV in CLI tests).$_SESSION/$_COOKIE not snapshotted by default (risk of race conditions).$_SERVER/$_ENV require explicit inclusion.Snapshot with Mockery/Faker for test doubles.restore() in a try/catch block leaks state.dev dependency with PHP version constraints.$_ENV).$GLOBALS or large superglobals can 10x test execution time.Snapshot::snapshot(['globals' => ['$_ENV']])).$_SESSION in parallel tests can cause race conditions (e.g., session file locks).| Scenario | Risk | Impact |
|---|---|---|
| Unrestored snapshot | State leakage between tests | Flaky tests, production defects. |
| PHP version mismatch | Package fails to load | CI/CD pipeline breaks. |
| Over-reliance on snapshots | Tests pass but mask bugs | False confidence in test coverage. |
$_SESSION restoration |
Race conditions in parallel tests | Test failures or session corruption. |
| Static property omission | Undetected state changes | Silent test failures. |
setUp()/tearDown()).Mockery for dependencies).How can I help you explore Laravel packages today?