1<?php declare(strict_types=1); 2 3namespace App\Tests\Unit\Utils; 4 5use App\Utils\Cache; 6use PHPUnit\Framework\TestCase; 7 8class CacheTest extends TestCase 9{ 10 /** @var string */ 11 private $cacheDir = TEST_VAR_DIRECTORY . '/cache/test'; 12 13 /** @var Cache */ 14 private $cache; 15 16 public function setUp(): void 17 { 18 $this->cache = new Cache($this->cacheDir); 19 $this->cache->clear(); 20 } 21 22 public function tearDown(): void 23 { 24 $this->cache->clear(); 25 rmdir($this->cacheDir); 26 } 27 28 public function testHas(): void 29 { 30 $this->assertFalse($this->cache->has('foo')); 31 32 $this->cache->set('foo', [1, 2, 3]); 33 $this->assertTrue($this->cache->has('foo')); 34 } 35 36 public function testDelete(): void 37 { 38 $this->cache->set('bar', [1, 2, 3]); 39 $this->assertFileExists($this->cacheDir.'/bar.php'); 40 41 $this->cache->delete('bar'); 42 $this->assertFalse(file_exists($this->cacheDir.'/bar.php')); 43 } 44} 45