示例#1
0
 public function testReadReturnsCache()
 {
     $file = $this->getFile();
     $signature = new Signature(PHP_VERSION, '2.0', true, array('foo', 'bar'));
     $cache = new Cache($signature);
     file_put_contents($file, $cache->toJson());
     $handler = new FileHandler($file);
     $cached = $handler->read();
     $this->assertInstanceOf('PhpCsFixer\\Cache\\CacheInterface', $cached);
     $this->assertTrue($cached->getSignature()->equals($signature));
 }
示例#2
0
 public function read()
 {
     if (!file_exists($this->file)) {
         return;
     }
     $content = file_get_contents($this->file);
     try {
         $cache = Cache::fromJson($content);
     } catch (\InvalidArgumentException $exception) {
         return;
     }
     return $cache;
 }
示例#3
0
 public function testCanConvertToAndFromJson()
 {
     $signature = new Signature(PHP_VERSION, '2.0', true, array('foo', 'bar'));
     $cache = new Cache($signature);
     $file = 'test.php';
     $hash = crc32('hello');
     $cache->set($file, $hash);
     /* @var Cache $cached */
     $cached = Cache::fromJson($cache->toJson());
     $this->assertTrue($cached->getSignature()->equals($signature));
     $this->assertTrue($cached->has($file));
     $this->assertSame($hash, $cached->get($file));
 }