Skip to content

Commit

Permalink
tests(phpcs,phpunit): fix currently failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelAlphonso committed Nov 24, 2023
1 parent 42aaf9f commit 7c40540
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function run(RequestInterface $request, ResponseInterface $response)
} else {
$message = $translator->translate('Failed to clear Twig cache.');
}

} elseif ($cacheType === 'mustache') {
$result = $this->clearMustacheCache();

Expand All @@ -74,7 +73,6 @@ public function run(RequestInterface $request, ResponseInterface $response)
} else {
$message = $translator->translate('Failed to clear Mustache cache.');
}

} elseif ($cacheType === 'item') {
$message = $translator->translate('Deleting cache items is unsupported, for now.');
} else {
Expand Down Expand Up @@ -130,7 +128,7 @@ private function clearObjectsCache()
return $result;
}

private function clearTwigCache() : bool
private function clearTwigCache(): bool
{
$defaultCachePath = realpath($this->twigEngine->cache());
$cachePath = $defaultCachePath ? $defaultCachePath : realpath($this->appConfig['publicPath'] . DIRECTORY_SEPARATOR . $this->twigEngine->cache());
Expand All @@ -141,7 +139,7 @@ private function clearTwigCache() : bool
return true;
}

private function clearMustacheCache() : bool
private function clearMustacheCache(): bool
{
$defaultCachePath = realpath($this->mustacheEngine->cache());
$cachePath = $defaultCachePath ? $defaultCachePath : realpath($this->appConfig['publicPath'] . DIRECTORY_SEPARATOR . $this->mustacheEngine->cache());
Expand All @@ -152,7 +150,7 @@ private function clearMustacheCache() : bool
return true;
}

private function rrmdir(string $dir, bool $deleteCurrentFolder = false) : void
private function rrmdir(string $dir, bool $deleteCurrentFolder = false): void
{
if (is_dir($dir)) {
$objects = scandir($dir);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,13 @@ private function objectsCacheInfo()
/**
* @return array<string, mixed>
*/
private function twigCacheInfo() : array
private function twigCacheInfo(): array
{
$defaultCachePath = realpath($this->twigEngine->cache());
$cachePath = $defaultCachePath ? $defaultCachePath : realpath($this->appConfig['publicPath'] . DIRECTORY_SEPARATOR . $this->twigEngine->cache());
$cachePath = $defaultCachePath
? $defaultCachePath
: realpath($this->appConfig['publicPath'] . DIRECTORY_SEPARATOR . $this->twigEngine->cache());

if (!is_dir($cachePath)) {
return [
'no_cache_folder' => true,
Expand All @@ -277,7 +280,7 @@ private function twigCacheInfo() : array
/**
* @return array<string, mixed>
*/
private function mustacheCacheInfo() : array
private function mustacheCacheInfo(): array
{
$defaultCachePath = realpath($this->mustacheEngine->cache());
$cachePath = $defaultCachePath ? $defaultCachePath : realpath($this->appConfig['publicPath'] . DIRECTORY_SEPARATOR . $this->mustacheEngine->cache());
Expand All @@ -299,7 +302,8 @@ private function mustacheCacheInfo() : array
/**
* Get the size in bytes of the directory.
*/
private function dirSize(string $directory) : int {
private function dirSize(string $directory): int
{
$size = 0;
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
$size += (int)$file->getSize();
Expand Down Expand Up @@ -429,17 +433,17 @@ public function isMemory()
return is_a($this->cache->getDriver(), Ephemeral::class);
}

public function hasTwigCache() : bool
public function hasTwigCache(): bool
{
return $this->twigEngine->config()->useCache;
}

public function hasMustacheCache() : bool
public function hasMustacheCache(): bool
{
return true;
}

public function hasViewCache() : bool
public function hasViewCache(): bool
{
return ($this->hasTwigCache() || $this->hasMustacheCache());
}
Expand Down
3 changes: 2 additions & 1 deletion packages/view/tests/Charcoal/View/Twig/TwigEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Charcoal\View\Twig\TwigEngine;
use Charcoal\View\Twig\TwigLoader;
use Charcoal\Tests\AbstractTestCase;
use Charcoal\View\ViewConfig;
use Charcoal\Tests\View\Twig\Mock\MockHelpers;

/**
Expand All @@ -31,7 +32,7 @@ public function setUp(): void
'paths' => [ 'templates' ],
]);
$this->obj = new TwigEngine([
'config' => false,
'config' => new ViewConfig(),
'loader' => $loader,
'helpers' => [],
'cache' => null,
Expand Down

0 comments on commit 7c40540

Please sign in to comment.