diff --git a/CHANGELOG.md b/CHANGELOG.md index 9dc8278bc..0c663e653 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,4 +11,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Unit tests for the CommandBus `dispatch` method. - Replaced Ignition with Whoops. -- Properly detect environment from `.env` when present. \ No newline at end of file +- Properly detect environment from `.env` when present. +- `discovery:cache` command that will generate the discovery cache \ No newline at end of file diff --git a/composer.json b/composer.json index f27bcfc70..9014c52de 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ "ext-pdo": "*", "ext-readline": "*", "ext-simplexml": "*", + "filp/whoops": "^2.15", "giggsey/libphonenumber-for-php": "^8.13.40", "guzzlehttp/guzzle": "^7.8", "laminas/laminas-diactoros": "^3.3", @@ -28,8 +29,7 @@ "symfony/var-dumper": "^7.1", "symfony/var-exporter": "^7.1", "tempest/highlight": "^2.0", - "vlucas/phpdotenv": "^5.6", - "filp/whoops": "^2.15" + "vlucas/phpdotenv": "^5.6" }, "require-dev": { "aidan-casey/mock-client": "dev-master", diff --git a/src/Tempest/Console/src/Commands/DiscoveryCacheCommand.php b/src/Tempest/Console/src/Commands/DiscoveryCacheCommand.php new file mode 100644 index 000000000..739a85595 --- /dev/null +++ b/src/Tempest/Console/src/Commands/DiscoveryCacheCommand.php @@ -0,0 +1,46 @@ +kernel->discoveryClasses as $discoveryClass) { + /** @var Discovery $discovery */ + $discovery = $this->container->get($discoveryClass); + + $discovery->storeCache(); + + $this->writeln(sprintf( + '%s cached successful', + $discoveryClass, + )); + } + + $this->console->success('Done'); + } +} diff --git a/src/Tempest/Core/src/DiscoveryDiscovery.php b/src/Tempest/Core/src/DiscoveryDiscovery.php index 0223d76fd..446ba6401 100644 --- a/src/Tempest/Core/src/DiscoveryDiscovery.php +++ b/src/Tempest/Core/src/DiscoveryDiscovery.php @@ -9,7 +9,7 @@ final readonly class DiscoveryDiscovery implements Discovery { - public const string CACHE_PATH = __DIR__ . '/../../../.cache/tempest/discovery-discovery.cache.php'; + public const string CACHE_PATH = __DIR__ . '/../../../../.cache/tempest/discovery-discovery.cache.php'; public function __construct( private Kernel $kernel, diff --git a/src/Tempest/Core/src/GenericExceptionHandlerSetup.php b/src/Tempest/Core/src/GenericExceptionHandlerSetup.php index 26cce4208..4af78f709 100644 --- a/src/Tempest/Core/src/GenericExceptionHandlerSetup.php +++ b/src/Tempest/Core/src/GenericExceptionHandlerSetup.php @@ -33,8 +33,8 @@ public function setup(AppConfig $appConfig): void } // Local web - $whoops = new Run; - $whoops->pushHandler(new PrettyPageHandler); + $whoops = new Run(); + $whoops->pushHandler(new PrettyPageHandler()); $whoops->register(); } diff --git a/src/Tempest/Core/src/HandlesDiscoveryCache.php b/src/Tempest/Core/src/HandlesDiscoveryCache.php index f73899c28..e29e13a03 100644 --- a/src/Tempest/Core/src/HandlesDiscoveryCache.php +++ b/src/Tempest/Core/src/HandlesDiscoveryCache.php @@ -15,7 +15,7 @@ public function getCachePath(): string $name = array_pop($parts) . '.cache.php'; - return __DIR__ . '/../../../.cache/tempest/' . $name; + return __DIR__ . '/../../../../.cache/tempest/' . $name; } abstract public function createCachePayload(): string; diff --git a/src/Tempest/Http/src/RouteDiscovery.php b/src/Tempest/Http/src/RouteDiscovery.php index f643c0ef6..b4f632533 100644 --- a/src/Tempest/Http/src/RouteDiscovery.php +++ b/src/Tempest/Http/src/RouteDiscovery.php @@ -11,7 +11,7 @@ final readonly class RouteDiscovery implements Discovery { - private const string CACHE_PATH = __DIR__ . '/../../../.cache/tempest/route-discovery.cache.php'; + private const string CACHE_PATH = __DIR__ . '/../../../../.cache/tempest/route-discovery.cache.php'; /** @var VarExportPhpFile */ private VarExportPhpFile $routeCacheFile; diff --git a/tests/Integration/Console/Commands/MyDiscovery.php b/tests/Integration/Console/Commands/MyDiscovery.php index f84dcd389..80551bfdf 100644 --- a/tests/Integration/Console/Commands/MyDiscovery.php +++ b/tests/Integration/Console/Commands/MyDiscovery.php @@ -12,6 +12,8 @@ final class MyDiscovery implements Discovery { public static bool $cacheCleared = false; + public static bool $cached = false; + public function discover(ClassReflector $class): void { // TODO: Implement discover() method. @@ -24,7 +26,7 @@ public function hasCache(): bool public function storeCache(): void { - // TODO: Implement storeCache() method. + self::$cached = true; } public function restoreCache(Container $container): void diff --git a/tests/Integration/Framework/Commands/DiscoveryCacheCommandTest.php b/tests/Integration/Framework/Commands/DiscoveryCacheCommandTest.php new file mode 100644 index 000000000..e046c285e --- /dev/null +++ b/tests/Integration/Framework/Commands/DiscoveryCacheCommandTest.php @@ -0,0 +1,26 @@ +kernel->discoveryClasses = [MyDiscovery::class]; + + $this->console->call('discovery:cache'); + + $this->assertTrue(MyDiscovery::$cached); + } +}