Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
77 changes: 77 additions & 0 deletions src/Testing/Concerns/InteractWithFacades.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

declare(strict_types=1);

namespace Phenix\Testing\Concerns;

use Closure;
use Phenix\App;
use Phenix\Cache\CacheManager;
use Phenix\Cache\Constants\Store;
use Phenix\Events\EventEmitter;
use Phenix\Facades\Cache;
use Phenix\Facades\Event;
use Phenix\Facades\Http;
use Phenix\Facades\Mail;
use Phenix\Facades\Queue;
use Phenix\Facades\View;
use Phenix\Http\Client\HttpClient;
use Phenix\Mail\MailManager;
use Phenix\Queue\QueueManager;
use Phenix\Views\Contracts\TemplateEngine;

trait InteractWithFacades
{
protected function clearViewCacheIfAvailable(): void
{
$this->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();
}
}
}
26 changes: 9 additions & 17 deletions src/Testing/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,8 +24,9 @@

abstract class TestCase extends AsyncTestCase
{
use InteractWithResponses;
use InteractWithFacades;
use InteractWithDatabase;
use InteractWithResponses;

protected ?AppProxy $app;
protected string $appDir;
Expand All @@ -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();
Expand Down