1<?php 2 3declare(strict_types=1); 4 5namespace Metadata\Tests\Cache; 6 7use Metadata\Cache\FileCache; 8use Metadata\ClassMetadata; 9use Metadata\Tests\Fixtures\TestObject; 10use PHPUnit\Framework\TestCase; 11 12class FileCacheTest extends TestCase 13{ 14 private $dir; 15 16 public function setUp() 17 { 18 $this->dir = sys_get_temp_dir() . '/jms-' . md5(__CLASS__); 19 if (is_dir($this->dir)) { 20 array_map('unlink', glob($this->dir . '/*')); 21 } else { 22 mkdir($this->dir); 23 } 24 } 25 26 public function testLoadEvictPutClassMetadataFromInCache() 27 { 28 $cache = new FileCache($this->dir); 29 30 $this->assertNull($cache->load(TestObject::class)); 31 $cache->put($metadata = new ClassMetadata(TestObject::class)); 32 33 $this->assertEquals($metadata, $cache->load(TestObject::class)); 34 35 $cache->evict(TestObject::class); 36 $this->assertNull($cache->load(TestObject::class)); 37 } 38} 39