Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
accgit authored and scrs_zdenek committed Sep 8, 2023
1 parent f906b21 commit 59d8dca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class ExtraConfigurator extends Configurator
{
// Cache for found configuration files.
public const CACHING = 'drago.cacheConf';
public const Caching = 'drago.cacheConf';


/**
Expand All @@ -33,10 +33,10 @@ class ExtraConfigurator extends Configurator
public function addFindConfig(array|string $paths, array|string ...$exclude): static
{
$storage = new FileStorage($this->getCacheDirectory());
$cache = new Cache($storage, self::CACHING);
$cache = new Cache($storage, self::Caching);

// Check the stored cache.
if (!$cache->load(self::CACHING)) {
if (!$cache->load(self::Caching)) {
$items = [];
foreach (Finder::findFiles('*.neon')->from($paths)->exclude($exclude) as $key => $file) {
$items[] = $key;
Expand All @@ -46,12 +46,12 @@ public function addFindConfig(array|string $paths, array|string ...$exclude): st
$names[] = basename($row);
}
array_multisort($names, SORT_NUMERIC, $items);
$cache->save(self::CACHING, $items);
$cache->save(self::Caching, $items);
}

// Loading cached saved.
if ($cache->load(self::CACHING)) {
foreach ($cache->load(self::CACHING) as $row) {
if ($cache->load(self::Caching)) {
foreach ($cache->load(self::Caching) as $row) {
$this->addConfig($row);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
$boot = require __DIR__ . '/../bootstrap.php';


$configCache = fn(): ConfigCache => new ConfigCache($boot::CACHING, TEMP_DIR);
$configCache = fn(): ConfigCache => new ConfigCache($boot::CACHING, TempDir);


test('Find the configuration file from one place', function () use ($boot, $configCache) {
$boot->addFindConfig(CONF_DIR . '/conf');
$boot->addFindConfig(ConfDir . '/conf');
$config = $configCache()->getCache();

Assert::same('conf.neon', $config[0]);
Expand All @@ -29,8 +29,8 @@

test('Find the configuration file from multiple locations', function () use ($boot, $configCache) {
$boot->addFindConfig([
CONF_DIR . '/conf',
CONF_DIR . '/conf.2',
ConfDir . '/conf',
ConfDir . '/conf.2',
]);

$config = $configCache()->getCache();
Expand All @@ -44,7 +44,7 @@


test('Find the configuration file and exclude which we do not want', function () use ($boot, $configCache) {
$boot->addFindConfig(CONF_DIR, 'conf.2');
$boot->addFindConfig(ConfDir, 'conf.2');
$config = $configCache()->getCache();

Assert::same('conf.neon', $config[0]);
Expand Down
10 changes: 5 additions & 5 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
date_default_timezone_set('Europe/Prague');


const TEMP_DIR = __DIR__ . '/tmp';
const CONF_DIR = __DIR__ . '/file';
const TempDir = __DIR__ . '/tmp';
const ConfDir = __DIR__ . '/file';

@mkdir(dirname(TEMP_DIR));
@mkdir(TEMP_DIR);
@mkdir(dirname(TempDir));
@mkdir(TempDir);

$boot = new Drago\Bootstrap\ExtraConfigurator;
$boot->setTempDirectory(TEMP_DIR);
$boot->setTempDirectory(TempDir);
$boot->createRobotLoader()
->addDirectory(__DIR__)
->addDirectory(__DIR__ . '/../src')
Expand Down

0 comments on commit 59d8dca

Please sign in to comment.