Skip to content

Commit

Permalink
Tests: improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jun 10, 2023
1 parent 2fd1c7f commit 4c7a156
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 99 deletions.
8 changes: 8 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# Folders - recursive
*.expected
*.actual

# Folders
/tmp

# Files
/*.log
/*.html
30 changes: 30 additions & 0 deletions tests/Cases/DI/CacheExtension.apcu.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types = 1);

namespace Tests\Cases\DI;

use Contributte\Tester\Environment;
use Contributte\Tester\Toolkit;
use Contributte\Tester\Utils\ContainerBuilder;
use Doctrine\Common\Cache\ApcuCache;
use Doctrine\Common\Cache\Cache;
use Nette\DI\Compiler;
use Nette\InvalidStateException;
use Nettrine\Cache\DI\CacheExtension;
use Tester\Assert;

require __DIR__ . '/../../bootstrap.php';

if (function_exists('apcu_exists')) {
Environment::skip('Exception unreachable when apcu is available');
}

Toolkit::test(function (): void {
Assert::exception(function (): void {
ContainerBuilder::of()
->withCompiler(function (Compiler $compiler): void {
$compiler->addExtension('nettrine.cache', new CacheExtension());
$compiler->addDependencies([__FILE__]);
})
->build();
}, InvalidStateException::class, 'Unable to find an available cache driver, please provide one via \'nettrine.cache > driver\' configuration.');
});
30 changes: 30 additions & 0 deletions tests/Cases/DI/CacheExtension.no-apcu.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php declare(strict_types = 1);

namespace Tests\Cases\DI;

use Contributte\Tester\Environment;
use Contributte\Tester\Toolkit;
use Contributte\Tester\Utils\ContainerBuilder;
use Doctrine\Common\Cache\ApcuCache;
use Doctrine\Common\Cache\Cache;
use Nette\DI\Compiler;
use Nettrine\Cache\DI\CacheExtension;
use Tester\Assert;

require __DIR__ . '/../../bootstrap.php';

if (!function_exists('apcu_exists')) {
Environment::skip('Autoselect driver unreachable when apcu is not available');
}

Toolkit::test(function (): void {
$container = ContainerBuilder::of()
->withCompiler(function (Compiler $compiler): void {
$compiler->addExtension('nettrine.cache', new CacheExtension());
$compiler->addDependencies([__FILE__]);
})
->build();

Assert::type(ApcuCache::class, $container->getByType(Cache::class));
Assert::type(ApcuCache::class, $container->getService('nettrine.cache.driver'));
});
49 changes: 49 additions & 0 deletions tests/Cases/DI/CacheExtension.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php declare(strict_types = 1);

namespace Tests\Cases\DI;

use Contributte\Tester\Environment;
use Contributte\Tester\Toolkit;
use Contributte\Tester\Utils\ContainerBuilder;
use Contributte\Tester\Utils\Neonkit;
use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\PhpFileCache;
use Doctrine\Common\Cache\VoidCache;
use Nette\DI\Compiler;
use Nettrine\Cache\DI\CacheExtension;
use Tester\Assert;

require __DIR__ . '/../../bootstrap.php';

Toolkit::test(function (): void {
$container = ContainerBuilder::of()
->withCompiler(function (Compiler $compiler): void {
$compiler->addExtension('nettrine.cache', new CacheExtension());
$compiler->addConfig([
'parameters' => [
'tempDir' => Environment::getTestDir(),
],
]);
$compiler->addDependencies([__FILE__]);
})
->build();

Assert::type(PhpFileCache::class, $container->getByType(Cache::class));
Assert::type(PhpFileCache::class, $container->getService('nettrine.cache.driver'));
});

Toolkit::test(function (): void {
$container = ContainerBuilder::of()
->withCompiler(function (Compiler $compiler): void {
$compiler->addExtension('nettrine.cache', new CacheExtension());
$compiler->addConfig(Neonkit::load('
nettrine.cache:
driver: Doctrine\Common\Cache\VoidCache()
'));
$compiler->addDependencies([__FILE__]);
})
->build();

Assert::type(VoidCache::class, $container->getByType(Cache::class));
Assert::type(VoidCache::class, $container->getService('nettrine.cache.driver'));
});
99 changes: 0 additions & 99 deletions tests/Cases/DI/CacheExtensionTest.php

This file was deleted.

0 comments on commit 4c7a156

Please sign in to comment.