示例#1
0
 public function testGetDirectoryWrite()
 {
     /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $dirWriteMock */
     $dirWriteMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\WriteInterface');
     $this->_dirWriteFactoryMock->expects($this->once())->method('create')->will($this->returnValue($dirWriteMock));
     $this->assertEquals($dirWriteMock, $this->_filesystem->getDirectoryWrite(DirectoryList::ROOT));
 }
 /**
  * Create an instance of directory with write permissions
  *
  * @param string $directoryCode
  * @param string $driverCode
  * @return \Magento\Framework\Filesystem\Directory\WriteInterface
  * @throws \Magento\Framework\Exception\FileSystemException
  */
 public function getDirectoryWrite($directoryCode, $driverCode = DriverPool::FILE)
 {
     $code = $directoryCode . '_' . $driverCode;
     if (!array_key_exists($code, $this->writeInstances)) {
         $this->writeInstances[$code] = $this->writeFactory->create($this->getDirPath($directoryCode), $driverCode);
     }
     return $this->writeInstances[$code];
 }
示例#3
0
 /**
  * Publish the asset
  *
  * @param Asset\LocalInterface $asset
  * @return bool
  */
 private function publishAsset(Asset\LocalInterface $asset)
 {
     $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
     $fullSource = $asset->getSourceFile();
     $source = basename($fullSource);
     $sourceDir = $this->writeFactory->create(dirname($fullSource));
     $destination = $asset->getPath();
     $strategy = $this->materializationStrategyFactory->create($asset);
     return $strategy->publishFile($sourceDir, $targetDir, $source, $destination);
 }
示例#4
0
 /**
  * Create required directories
  *
  * @return void
  */
 protected function createDirectories()
 {
     $directories = [dirname(dirname(__DIR__)) . '/var'];
     foreach ($directories as $path) {
         $writer = $this->directoryWriteFactory->create($path);
         if (!$writer->isDirectory()) {
             $writer->create();
         }
     }
 }
示例#5
0
 protected function setUp()
 {
     $this->filesystem = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false);
     $this->materializationStrategyFactory = $this->getMock('Magento\\Framework\\App\\View\\Asset\\MaterializationStrategy\\Factory', [], [], '', false);
     $this->writeFactory = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\WriteFactory', [], [], '', false);
     $this->object = new Publisher($this->filesystem, $this->materializationStrategyFactory, $this->writeFactory);
     $this->sourceDirWrite = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\Directory\\WriteInterface');
     $this->staticDirRead = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\Directory\\ReadInterface');
     $this->staticDirWrite = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\Directory\\WriteInterface');
     $this->filesystem->expects($this->any())->method('getDirectoryRead')->with(DirectoryList::STATIC_VIEW)->will($this->returnValue($this->staticDirRead));
     $this->filesystem->expects($this->any())->method('getDirectoryWrite')->will($this->returnValue($this->staticDirWrite));
     $this->writeFactory->expects($this->any())->method('create')->willReturn($this->sourceDirWrite);
 }
示例#6
0
 public function testLaunchWithException()
 {
     $writer = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\WriteInterface');
     $writer->expects($this->any())->method('isDirectory')->will($this->returnValue(false));
     $writer->expects($this->any())->method('create')->will($this->returnValue(true));
     $this->writeFactory->expects($this->any())->method('create')->will($this->returnValue($writer));
     $shell = $this->getMock('\\Migration\\App\\Shell', ['run'], [], '', false);
     $shell->expects($this->any())->method('run')->willThrowException(new \Exception('error'));
     $this->shellFactory->expects($this->any())->method('create')->will($this->returnValue($shell));
     ob_start();
     $this->migration->launch();
     $error = ob_get_clean();
     $this->assertEquals('error', $error);
 }
示例#7
0
 /**
  * Create an instance of directory with read permissions
  *
  * @param string $code
  * @return \Magento\Framework\Filesystem\Directory\WriteInterface
  * @throws \Magento\Framework\Filesystem\FilesystemException
  */
 public function getDirectoryWrite($code)
 {
     if (!array_key_exists($code, $this->writeInstances)) {
         $config = $this->directoryList->getConfig($code);
         if (isset($config['read_only']) && $config['read_only']) {
             throw new FilesystemException(sprintf('The "%s" directory doesn\'t allow write operations', $code));
         }
         $this->writeInstances[$code] = $this->writeFactory->create($config, $this->driverFactory);
     }
     return $this->writeInstances[$code];
 }
示例#8
0
 /**
  * Constructor
  *
  * @param DirectoryList $directoryList
  * @param WriteFactory $writeFactory
  */
 public function __construct(DirectoryList $directoryList, WriteFactory $writeFactory)
 {
     $this->directoryList = $directoryList;
     $this->write = $writeFactory->create(BP);
 }