From 030d28259862eb78dbddd1ae4c928c888605fbfc Mon Sep 17 00:00:00 2001 From: Andrew Judd Date: Thu, 18 Nov 2021 17:03:17 -0500 Subject: [PATCH 1/2] fix(cache): cached configuration * Fixing the cached configuration so update works * Adding in a check to see if the framework is installed before registering the blade composer --- .../Providers/ConfigurationServiceProvider.php | 10 ++++++++++ .../CachedConfigurationRepository.php | 18 +++++++++--------- .../CachedConfigurationRepositoryTest.php | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Configuration/Providers/ConfigurationServiceProvider.php b/src/Configuration/Providers/ConfigurationServiceProvider.php index 11df462..5cc6eeb 100644 --- a/src/Configuration/Providers/ConfigurationServiceProvider.php +++ b/src/Configuration/Providers/ConfigurationServiceProvider.php @@ -7,6 +7,7 @@ use GamingEngine\Core\Configuration\Repositories\ConfigurationRepository; use GamingEngine\Core\Configuration\Repositories\DatabaseConfigurationRepository; use GamingEngine\Core\Configuration\SiteConfiguration; +use GamingEngine\Core\Core; use GamingEngine\Core\Framework\Http\View\Composers\ConfigurationViewComposer; use Illuminate\Support\Facades\View; use Illuminate\Support\ServiceProvider; @@ -47,6 +48,15 @@ function () { public function boot() { + /** + * @var Core $core + */ + $core = app(Core::class); + + if (! $core->installed()) { + return; + } + View::composer('*', ConfigurationViewComposer::class); } } diff --git a/src/Configuration/Repositories/CachedConfigurationRepository.php b/src/Configuration/Repositories/CachedConfigurationRepository.php index 73f6c1d..181bf44 100644 --- a/src/Configuration/Repositories/CachedConfigurationRepository.php +++ b/src/Configuration/Repositories/CachedConfigurationRepository.php @@ -26,14 +26,6 @@ public function account(): AccountConfiguration ); } - public function site(): SiteConfiguration - { - return $this->cache( - SiteConfiguration::type(), - fn () => $this->configurationRepository->site() - ); - } - private function cache(string $category, callable $values) { return Cache::rememberForever( @@ -52,13 +44,21 @@ private function cacheKey(string $category): string ); } + public function site(): SiteConfiguration + { + return $this->cache( + SiteConfiguration::type(), + fn () => $this->configurationRepository->site() + ); + } + public function update(BaseConfiguration $configuration): BaseConfiguration { $response = $this->configurationRepository->update($configuration); Cache::put( $this->cacheKey($configuration::type()), - fn () => $response, + $response, ); return $response; diff --git a/tests/Configuration/Repositories/CachedConfigurationRepositoryTest.php b/tests/Configuration/Repositories/CachedConfigurationRepositoryTest.php index b52fa3e..42f7f1c 100644 --- a/tests/Configuration/Repositories/CachedConfigurationRepositoryTest.php +++ b/tests/Configuration/Repositories/CachedConfigurationRepositoryTest.php @@ -127,7 +127,7 @@ public function cached_configuration_will_re_cache_the_data_on_update() $repository = new CachedConfigurationRepository($wrapped); Cache::shouldReceive('put') - ->withArgs(fn ($key, $c) => $configuration === $c()) + ->withArgs(fn ($key, $c) => $configuration === $c) ->andReturn($configuration); $wrapped->shouldReceive('update') From 622f1193d1e6b9eede9cc671df2522aacba36a93 Mon Sep 17 00:00:00 2001 From: Andrew Judd Date: Thu, 18 Nov 2021 17:04:50 -0500 Subject: [PATCH 2/2] fix(husky): coverage Adding in the code coverage flag --- .husky/pre-push | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.husky/pre-push b/.husky/pre-push index c8440c5..78b1c6d 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1,5 +1,5 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" -./vendor/bin/phpunit --coverage-html ./build +XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html ./build php coverage-checker.php ./build/clover.xml 95