thecodingmachine /
cache-utils
| 1 | <?php |
||
| 2 | |||
| 3 | namespace TheCodingMachine\CacheUtils; |
||
| 4 | |||
| 5 | use Symfony\Component\Cache\Adapter\ArrayAdapter; |
||
| 6 | use function clearstatcache; |
||
| 7 | use function file_get_contents; |
||
| 8 | use function file_put_contents; |
||
| 9 | use ReflectionClass; |
||
| 10 | use function sleep; |
||
| 11 | use function str_replace; |
||
| 12 | use Symfony\Component\Cache\Simple\ArrayCache; |
||
| 13 | use function sys_get_temp_dir; |
||
| 14 | use PHPUnit\Framework\TestCase; |
||
| 15 | use TheCodingMachine\CacheUtils\Fixtures\A; |
||
| 16 | use TheCodingMachine\CacheUtils\Fixtures\B; |
||
| 17 | use TheCodingMachine\CacheUtils\Fixtures\C; |
||
| 18 | use TheCodingMachine\CacheUtils\Fixtures\D; |
||
| 19 | use function touch; |
||
| 20 | |||
| 21 | class ClassBoundCacheTest extends TestCase |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @dataProvider touchFile |
||
| 25 | */ |
||
| 26 | public function testClassBoundCache($classToTouch): void |
||
| 27 | { |
||
| 28 | $cache = new ArrayAdapter(); |
||
| 29 | $fileBoundCache = new FileBoundCache($cache, 'prefix'); |
||
| 30 | $classBoundCache = new ClassBoundCache($fileBoundCache, true, true, true); |
||
| 31 | |||
| 32 | $classBoundCache->set('foo', 'bar', new ReflectionClass(A::class)); |
||
| 33 | |||
| 34 | $this->assertSame('bar', $classBoundCache->get('foo')); |
||
| 35 | |||
| 36 | $classToTouch = new ReflectionClass($classToTouch); |
||
| 37 | sleep(1); |
||
| 38 | clearstatcache($classToTouch->getFileName()); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 39 | touch($classToTouch->getFileName()); |
||
| 40 | |||
| 41 | $this->assertNull($classBoundCache->get('foo')); |
||
| 42 | } |
||
| 43 | |||
| 44 | public function touchFile() |
||
| 45 | { |
||
| 46 | return [ |
||
| 47 | [ B::class ], |
||
| 48 | [ C::class ], |
||
| 49 | [ D::class ], |
||
| 50 | ]; |
||
| 51 | } |
||
| 52 | } |
||
| 53 |