diff --git a/src/Base/Factory/PdkFactory.php b/src/Base/Factory/PdkFactory.php index 0cb307fed..1655c6100 100644 --- a/src/Base/Factory/PdkFactory.php +++ b/src/Base/Factory/PdkFactory.php @@ -6,6 +6,7 @@ use DI\Container; use DI\ContainerBuilder; +use DI\Definition\Source\SourceCache; use InvalidArgumentException; use MyParcelNL\Pdk\Base\Concern\PdkInterface; use MyParcelNL\Pdk\Base\Contract\PdkFactoryInterface; @@ -76,7 +77,7 @@ protected function getMode(): string */ protected function setupCache(ContainerBuilder $builder): void { - if (function_exists('apcu_fetch')) { + if (SourceCache::isSupported()) { $builder->enableDefinitionCache('pdk-definition-cache'); } diff --git a/tests/Unit/Facade/PdkTest.php b/tests/Unit/Facade/PdkTest.php index 39bf84b1a..83020e65d 100644 --- a/tests/Unit/Facade/PdkTest.php +++ b/tests/Unit/Facade/PdkTest.php @@ -8,6 +8,7 @@ use MyParcelNL\Pdk\Api\Contract\ApiServiceInterface; use MyParcelNL\Pdk\Base\Exception\PdkConfigException; use MyParcelNL\Pdk\Base\Factory\PdkFactory; +use MyParcelNL\Pdk\Base\Pdk as PdkBase; use MyParcelNL\Pdk\Tests\Bootstrap\MockPdkConfig; use function DI\value; @@ -34,15 +35,23 @@ ->toBe(! $isDevelopment); })->with([ 'production' => [ - 'mode' => \MyParcelNL\Pdk\Base\Pdk::MODE_PRODUCTION, + 'mode' => PdkBase::MODE_PRODUCTION, 'isDevelopment' => false, ], 'development' => [ - 'mode' => \MyParcelNL\Pdk\Base\Pdk::MODE_DEVELOPMENT, + 'mode' => PdkBase::MODE_DEVELOPMENT, 'isDevelopment' => true, ], ]); +it('sets up cache when required', function () { + putenv('PDK_DISABLE_CACHE=0'); + PdkFactory::create(MockPdkConfig::create(['mode' => 'production'])); + putenv('PDK_DISABLE_CACHE=1'); + + expect(scandir(PdkBase::CACHE_DIR))->toContain('CompiledContainer.php'); +}); + it('throws error if appInfo is missing', function () { PdkFactory::create();