Skip to content

Commit

Permalink
fix(caching): use apc only when enabled (#239)
Browse files Browse the repository at this point in the history
INT-224
  • Loading branch information
joerivanveen authored Nov 23, 2023
1 parent e1e2f72 commit 7b4ebbd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Base/Factory/PdkFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}

Expand Down
13 changes: 11 additions & 2 deletions tests/Unit/Facade/PdkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();

Expand Down

0 comments on commit 7b4ebbd

Please sign in to comment.