From 45c900ce927c2c41258fc7bedcefc3a55d68b9e2 Mon Sep 17 00:00:00 2001 From: barbosa89 Date: Mon, 25 May 2026 13:05:58 +0000 Subject: [PATCH 1/2] feat: add InteractWithFacades trait for improved facade interaction in tests --- src/App.php | 5 ++ src/Testing/Concerns/InteractWithFacades.php | 77 ++++++++++++++++++++ src/Testing/TestCase.php | 26 +++---- 3 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 src/Testing/Concerns/InteractWithFacades.php diff --git a/src/App.php b/src/App.php index 30a78c1e..397d0044 100644 --- a/src/App.php +++ b/src/App.php @@ -161,6 +161,11 @@ public static function make(string $key): object return self::$container->get($key); } + public static function has(string $key): bool + { + return self::$container->has($key); + } + public static function fake(string $key, LegacyMockInterface|MockInterface $concrete): void { self::$container->extend($key)->setConcrete($concrete); diff --git a/src/Testing/Concerns/InteractWithFacades.php b/src/Testing/Concerns/InteractWithFacades.php new file mode 100644 index 00000000..1b71d9d1 --- /dev/null +++ b/src/Testing/Concerns/InteractWithFacades.php @@ -0,0 +1,77 @@ +whenBound(TemplateEngine::class, static function (): void { + View::clearCache(); + }); + } + + protected function resetEventsIfAvailable(): void + { + $this->whenBound(EventEmitter::class, static function (): void { + Event::resetFaking(); + }); + } + + protected function resetQueueIfAvailable(): void + { + $this->whenBound(QueueManager::class, static function (): void { + Queue::resetFaking(); + }); + } + + protected function resetMailIfAvailable(): void + { + $this->whenBound(MailManager::class, static function (): void { + Mail::resetSendingLog(); + }); + } + + protected function resetHttpIfAvailable(): void + { + $this->whenBound(HttpClient::class, static function (): void { + Http::resetFaking(); + }); + } + + protected function clearCacheIfAvailable(): void + { + if (config('cache.default') !== Store::FILE->value) { + return; + } + + $this->whenBound(CacheManager::class, static function (): void { + Cache::clear(); + }); + } + + protected function whenBound(string $key, Closure $callback): void + { + if (App::has($key)) { + $callback(); + } + } +} diff --git a/src/Testing/TestCase.php b/src/Testing/TestCase.php index f24b68a4..6d4b13a3 100644 --- a/src/Testing/TestCase.php +++ b/src/Testing/TestCase.php @@ -9,16 +9,10 @@ use Phenix\App; use Phenix\AppBuilder; use Phenix\AppProxy; -use Phenix\Cache\Constants\Store; use Phenix\Console\Phenix; -use Phenix\Facades\Cache; use Phenix\Facades\Config; -use Phenix\Facades\Event; -use Phenix\Facades\Http; -use Phenix\Facades\Mail; -use Phenix\Facades\Queue; -use Phenix\Facades\View; use Phenix\Testing\Concerns\InteractWithDatabase; +use Phenix\Testing\Concerns\InteractWithFacades; use Phenix\Testing\Concerns\InteractWithResponses; use Phenix\Testing\Concerns\RefreshDatabase; use Phenix\Util\Str; @@ -30,8 +24,9 @@ abstract class TestCase extends AsyncTestCase { - use InteractWithResponses; + use InteractWithFacades; use InteractWithDatabase; + use InteractWithResponses; protected ?AppProxy $app; protected string $appDir; @@ -56,21 +51,18 @@ protected function setUp(): void $this->refreshDatabase(); } - View::clearCache(); + $this->clearViewCacheIfAvailable(); } protected function tearDown(): void { parent::tearDown(); - Event::resetFaking(); - Queue::resetFaking(); - Mail::resetSendingLog(); - Http::resetFaking(); - - if (config('cache.default') === Store::FILE->value) { - Cache::clear(); - } + $this->resetEventsIfAvailable(); + $this->resetQueueIfAvailable(); + $this->resetMailIfAvailable(); + $this->resetHttpIfAvailable(); + $this->clearCacheIfAvailable(); if ($this->app instanceof AppProxy) { $this->app->stop(); From d4884301bd647ee359a685dba8f899b5ece74210 Mon Sep 17 00:00:00 2001 From: barbosa89 Date: Mon, 25 May 2026 13:17:29 +0000 Subject: [PATCH 2/2] docs: update changelog [skip ci] --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e6ecd03..8b1bd9a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Release Notes for 0.9.x +## [v0.9.1 (2026-05-25)](https://github.com/phenixphp/framework/compare/0.9.0...0.9.1) + +### Changed + +- Conditionally call to resetting facade methods. ([#135](https://github.com/phenixphp/framework/pull/135)) + ## [v0.9.0 (2026-05-25)](https://github.com/phenixphp/framework/compare/0.8.9...0.9.0) ### Added - HTTP Client. ([#132](https://github.com/phenixphp/framework/pull/132)) +### Fixed + +- Prevent duplicate rate limit headers in response. ([#131](https://github.com/phenixphp/framework/pull/131)) + # Release Notes for 0.8.x ## [v0.8.9 (2026-05-11)](https://github.com/phenixphp/framework/compare/0.8.8...0.8.9)