示例#1
0
 /**
  * Write down contents to a temporary file and return its absolute path
  *
  * @param string $relativePath
  * @param string $contents
  * @return string
  */
 public function createFile($relativePath, $contents)
 {
     $filePath = $this->config->getMaterializationRelativePath() . '/' . $relativePath;
     if (!$this->tmpDirectory->isExist($filePath)) {
         $this->tmpDirectory->writeFile($filePath, $contents);
     }
     return $this->tmpDirectory->getAbsolutePath($filePath);
 }
 public function testGenerateFileTree()
 {
     $lessDirectory = 'path/to/less';
     $expectedContent = 'updated content';
     $expectedRelativePath = 'some/file.less';
     $expectedPath = $lessDirectory . '/some/file.less';
     $asset = $this->getMock('Magento\\Framework\\View\\Asset\\File', [], [], '', false);
     $chain = $this->getMock('Magento\\Framework\\View\\Asset\\PreProcessor\\Chain', [], [], '', false);
     $this->config->expects($this->any())->method('getLessDirectory')->willReturn($lessDirectory);
     $this->tmpDirectory->expects($this->once())->method('isExist')->willReturn(true);
     $this->magentoImport->expects($this->once())->method('process')->with($chain);
     $this->import->expects($this->once())->method('process')->with($chain);
     $this->relatedGenerator->expects($this->once())->method('generate')->with($this->import);
     $asset->expects($this->once())->method('getPath')->will($this->returnValue('some/file.css'));
     $chain->expects($this->once())->method('getContent')->willReturn($expectedContent);
     $chain->expects($this->once())->method('getAsset')->willReturn($asset);
     $chain->expects($this->once())->method('getContentType')->willReturn('less');
     $this->temporaryFile->expects($this->once())->method('createFile')->with($expectedRelativePath, $expectedContent)->willReturn($expectedPath);
     $this->assertSame($expectedPath, $this->object->generateFileTree($chain));
 }
 /**
  * Check whether generation process has already locked
  *
  * @return bool
  */
 protected function isProcessLocked()
 {
     $lockFilePath = $this->config->getMaterializationRelativePath() . '/' . self::LOCK_FILE;
     if ($this->tmpDirectory->isExist($lockFilePath)) {
         $lockTime = time() - (int) $this->tmpDirectory->readFile($lockFilePath);
         if ($lockTime >= self::MAX_LOCK_TIME) {
             $this->tmpDirectory->delete($lockFilePath);
             return false;
         }
         return true;
     }
     return false;
 }