root = vfsStream::setup('cache'); Configuration::getInstance()->file_cache_location = vfsStream::url('cache'); $this->file_cache = new FileCache; } public function testFileCacheCanInstantiate() { $this->assertInstanceOf(FileCache::class, new FileCache); } public function testFileCacheCheckCacheDirectory() { $this->assertTrue($this->file_cache->checkCacheDirectory()); } public function testFileCacheBuildsRelativePathWithoutQueryString() { $path = $this->file_cache->buildRelativePath('/test'); $this->assertEquals('vfs://cache/test//', $path); } public function testFileCacheBuildsRelativePathWithQueryString() { $path = $this->file_cache->buildRelativePath('/test', 'foo=bar'); $this->assertEquals('vfs://cache/test/2fb8f40115dd1e695cbe23d4f97ce5b1fb697eee/', $path); } public function testFileCacheFailsCreatingDirectoryOnInvalidPath() { $this->expectException(CachePathException::class); if (substr(PHP_OS, 0, 3) == 'WIN') $invalid_path = '/completely:invalid?path'; else $invalid_path = '/completely/invalid/path'; Configuration::getInstance() ->file_cache_location = $invalid_path; new FileCache(); } /** * @param $input * @param $output * * @dataProvider providerTestFileCacheSafePathValues */ public function testFileCacheSafePathValues($input, $output) { $result = $this->file_cache->safePath($input); $this->assertEquals($output, $result); } /** * @return array */ public function providerTestFileCacheSafePathValues() { return [ ['A/B/C', 'A/B/C'], ['\'A/B/C', 'A/B/C'], ['`A/B/C`', 'A/B/C'], ['|&*A%/$B!/C', 'A/B/C'], ]; } }