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]; }
/** * 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); }
/** * 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(); } } }
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); }
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); }
/** * 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]; }
/** * Constructor * * @param DirectoryList $directoryList * @param WriteFactory $writeFactory */ public function __construct(DirectoryList $directoryList, WriteFactory $writeFactory) { $this->directoryList = $directoryList; $this->write = $writeFactory->create(BP); }