PhpCsFixer\Cache\FileCacheManager::setFile PHP Method

setFile() public method

public setFile ( $file, $fileContent )
    public function setFile($file, $fileContent)
    {
        $file = $this->cacheDirectory->getRelativePathTo($file);
        $hash = $this->calcHash($fileContent);
        if ($this->isDryRun && $this->cache->has($file) && $this->cache->get($file) !== $hash) {
            $this->cache->clear($file);
            return;
        }
        $this->cache->set($file, $hash);
    }

Usage Example

 public function testSetFileUsesRelativePathToFile()
 {
     $cacheFile = $this->getFile();
     $file = '/foo/bar/baz/src/hello.php';
     $relativePathToFile = 'src/hello.php';
     $fileContent = '<?php echo "Hello!"';
     $directory = $this->getDirectoryMock();
     $directory->expects($this->once())->method('getRelativePathTo')->with($this->identicalTo($file))->willReturn($relativePathToFile);
     $cachedSignature = $this->getSignatureMock();
     $signature = $this->getSignatureMock();
     $signature->expects($this->once())->method('equals')->with($this->identicalTo($cachedSignature))->willReturn(true);
     $cache = $this->getCacheMock();
     $cache->expects($this->once())->method('getSignature')->willReturn($cachedSignature);
     $cache->expects($this->once())->method('set')->with($this->identicalTo($relativePathToFile), $this->identicalTo(crc32($fileContent)));
     $handler = $this->getFileHandlerMock();
     $handler->expects($this->never())->method('getFile')->willReturn($cacheFile);
     $handler->expects($this->once())->method('read')->willReturn($cache);
     $handler->expects($this->once())->method('write')->with($this->identicalTo($cache));
     $manager = new FileCacheManager($handler, $signature, false, $directory);
     $manager->setFile($file, $fileContent);
 }