From 147ce1610922de319d76ca894a5ef220b4c73d5a Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Tue, 14 Jan 2025 09:24:05 -0500 Subject: [PATCH] Always disable spatie/once cache during testing (#613) * Always disable spatie/once cache during testing * Require the package for development --- CHANGELOG.md | 4 ++++ composer.json | 1 + src/mantle/testing/class-test-case.php | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index beacf8c5..a2cd5b01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- Disable `spatie/once`'s cache if found during unit testing. + ## v1.3.3 - 2025-01-10 ### Added diff --git a/composer.json b/composer.json index b701143b..865ab27c 100644 --- a/composer.json +++ b/composer.json @@ -57,6 +57,7 @@ "phpstan/phpstan": "1.10.67", "phpunit/phpunit": "^9.3.3 || ^10.0.7 || ^11.0", "rector/rector": "^1.0", + "spatie/once": "^3.1", "spatie/ray": "^1.41", "squizlabs/php_codesniffer": "^3.7", "symplify/monorepo-builder": "^10.3.3", diff --git a/src/mantle/testing/class-test-case.php b/src/mantle/testing/class-test-case.php index abacf69a..a84ca737 100644 --- a/src/mantle/testing/class-test-case.php +++ b/src/mantle/testing/class-test-case.php @@ -92,6 +92,13 @@ abstract public function create_application(): Application; * Runs the routine before setting up all tests. */ public static function setUpBeforeClass(): void { + parent::setUpBeforeClass(); + + // Disable the Spatie once cache for tests. + if ( class_exists( \Spatie\Once\Once::class ) ) { + \Spatie\Once\Cache::getInstance()->disable(); + } + static::register_traits(); if ( ! empty( static::$test_uses ) ) {