Files
archived-web-bugs/tests/Unit/Utils/CacheTest.php
Pieter Hordijk f762db348d Add tests fixes
- Added filter to phpunit config
- This enables support for coverage support
- Moved unit tests to dedicated directory
- Also created constants for the locations of the fixtures and mocks for
  testing so we do not have to use relative paths in tests
- Updated phpunit to 8
- Added type information to tests
- Added return type and parameter type declarations for tests
- Added strict types to tests
- CS fixes in tests
- Aligning arrays, consistent string concatenation, removed unused local
  vars
- Added constant for test cache directory
- Make the autoloader also properly work on windows
- Windows does not care about the directory separator used so just trim
  both variant from the end.
2019-05-16 22:05:30 +02:00

45 lines
991 B
PHP

<?php declare(strict_types=1);
namespace App\Tests\Unit\Utils;
use App\Utils\Cache;
use PHPUnit\Framework\TestCase;
class CacheTest extends TestCase
{
/** @var string */
private $cacheDir = TEST_VAR_DIRECTORY . '/cache/test';
/** @var Cache */
private $cache;
public function setUp(): void
{
$this->cache = new Cache($this->cacheDir);
$this->cache->clear();
}
public function tearDown(): void
{
$this->cache->clear();
rmdir($this->cacheDir);
}
public function testHas(): void
{
$this->assertFalse($this->cache->has('foo'));
$this->cache->set('foo', [1, 2, 3]);
$this->assertTrue($this->cache->has('foo'));
}
public function testDelete(): void
{
$this->cache->set('bar', [1, 2, 3]);
$this->assertFileExists($this->cacheDir.'/bar.php');
$this->cache->delete('bar');
$this->assertFalse(file_exists($this->cacheDir.'/bar.php'));
}
}