/** * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { $this->filesystemMock = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false); $this->driverMock = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\DriverInterface', [], '', false, false, true, ['getRealPath']); $this->driverMock->expects($this->any())->method('getRealPath')->will($this->returnArgument(0)); $this->directoryMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', ['delete', 'getDriver', 'create'], [], '', false); $this->directoryMock->expects($this->any())->method('getDriver')->will($this->returnValue($this->driverMock)); $this->filesystemMock = $this->getMock('Magento\\Framework\\Filesystem', ['getDirectoryWrite'], [], '', false); $this->filesystemMock->expects($this->any())->method('getDirectoryWrite')->with(DirectoryList::MEDIA)->will($this->returnValue($this->directoryMock)); $this->adapterFactoryMock = $this->getMock('Magento\\Framework\\Image\\AdapterFactory', [], [], '', false); $this->imageHelperMock = $this->getMock('Magento\\Cms\\Helper\\Wysiwyg\\Images', ['getStorageRoot'], [], '', false); $this->imageHelperMock->expects($this->any())->method('getStorageRoot')->will($this->returnValue(self::STORAGE_ROOT_DIR)); $this->resizeParameters = ['width' => 100, 'height' => 50]; $this->storageCollectionFactoryMock = $this->getMock('Magento\\Cms\\Model\\Wysiwyg\\Images\\Storage\\CollectionFactory', ['create'], [], '', false); $this->storageFileFactoryMock = $this->getMock('Magento\\MediaStorage\\Model\\File\\Storage\\FileFactory', [], [], '', false); $this->storageDatabaseFactoryMock = $this->getMock('Magento\\MediaStorage\\Model\\File\\Storage\\DatabaseFactory', [], [], '', false); $this->directoryDatabaseFactoryMock = $this->getMock('Magento\\MediaStorage\\Model\\File\\Storage\\Directory\\DatabaseFactory', ['create'], [], '', false); $this->directoryCollectionMock = $this->getMock('Magento\\MediaStorage\\Model\\File\\Storage\\Directory\\Database', [], [], '', false); $this->uploaderFactoryMock = $this->getMockBuilder('Magento\\MediaStorage\\Model\\File\\UploaderFactory')->disableOriginalConstructor()->getMock(); $this->sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', [], [], '', false); $this->backendUrlMock = $this->getMock('Magento\\Backend\\Model\\Url', [], [], '', false); $this->coreFileStorageMock = $this->getMockBuilder('Magento\\MediaStorage\\Helper\\File\\Storage\\Database')->disableOriginalConstructor()->getMock(); $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->imagesStorage = $this->objectManagerHelper->getObject('Magento\\Cms\\Model\\Wysiwyg\\Images\\Storage', ['session' => $this->sessionMock, 'backendUrl' => $this->backendUrlMock, 'cmsWysiwygImages' => $this->imageHelperMock, 'coreFileStorageDb' => $this->coreFileStorageMock, 'filesystem' => $this->filesystemMock, 'imageFactory' => $this->adapterFactoryMock, 'assetRepo' => $this->getMock('Magento\\Framework\\View\\Asset\\Repository', [], [], '', false), 'storageCollectionFactory' => $this->storageCollectionFactoryMock, 'storageFileFactory' => $this->storageFileFactoryMock, 'storageDatabaseFactory' => $this->storageDatabaseFactoryMock, 'directoryDatabaseFactory' => $this->directoryDatabaseFactoryMock, 'uploaderFactory' => $this->uploaderFactoryMock, 'resizeParameters' => $this->resizeParameters, 'dirs' => ['exclude' => [], 'include' => []]]); }
/** * Cover createHistoryReport(). * * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Source file coping failed */ public function testCreateHistoryReportThrowException() { $sourceFileRelative = null; $entity = ''; $extension = ''; $result = ''; $gmtTimestamp = 1234567; $this->import->expects($this->once())->method('isReportEntityType')->with($entity)->willReturn(true); $this->_varDirectory->expects($this->never())->method('getRelativePath'); $phrase = $this->getMock('\\Magento\\Framework\\Phrase', [], [], '', false); $this->_driver->expects($this->any())->method('fileGetContents')->willReturnCallback(function () use($phrase) { throw new \Magento\Framework\Exception\FileSystemException($phrase); }); $this->dateTime->expects($this->once())->method('gmtTimestamp')->willReturn($gmtTimestamp); $args = [$sourceFileRelative, $entity, $extension, $result]; $actualResult = $this->invokeMethod($this->import, 'createHistoryReport', $args); $this->assertEquals($this->import, $actualResult); }
/** * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { $this->_filesystemMock = $this->getMock('Magento\\Framework\\App\\Filesystem', array(), array(), '', false); $this->_driverMock = $this->getMockForAbstractClass('Magento\\Framework\\Filesystem\\DriverInterface', array(), '', false, false, true, array('getRealPath')); $this->_driverMock->expects($this->any())->method('getRealPath')->will($this->returnArgument(0)); $this->_directoryMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Write', array('delete', 'getDriver'), array(), '', false); $this->_directoryMock->expects($this->any())->method('getDriver')->will($this->returnValue($this->_driverMock)); $this->_filesystemMock = $this->getMock('Magento\\Framework\\App\\Filesystem', array('getDirectoryWrite'), array(), '', false); $this->_filesystemMock->expects($this->any())->method('getDirectoryWrite')->with(\Magento\Framework\App\Filesystem::MEDIA_DIR)->will($this->returnValue($this->_directoryMock)); $this->_adapterFactoryMock = $this->getMock('Magento\\Framework\\Image\\AdapterFactory', array(), array(), '', false); $this->_imageHelperMock = $this->getMock('Magento\\Cms\\Helper\\Wysiwyg\\Images', array('getStorageRoot'), array(), '', false); $this->_imageHelperMock->expects($this->any())->method('getStorageRoot')->will($this->returnValue(self::STORAGE_ROOT_DIR)); $this->_resizeParameters = array('width' => 100, 'height' => 50); $this->_storageCollectionFactoryMock = $this->getMock('Magento\\Cms\\Model\\Wysiwyg\\Images\\Storage\\CollectionFactory'); $this->_storageFileFactoryMock = $this->getMock('Magento\\Core\\Model\\File\\Storage\\FileFactory'); $this->_storageDatabaseFactoryMock = $this->getMock('Magento\\Core\\Model\\File\\Storage\\DatabaseFactory'); $this->_directoryDatabaseFactoryMock = $this->getMock('Magento\\Core\\Model\\File\\Storage\\Directory\\DatabaseFactory'); $this->_uploaderFactoryMock = $this->getMock('Magento\\Core\\Model\\File\\UploaderFactory'); $this->_sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', array(), array(), '', false); $this->_backendUrlMock = $this->getMock('Magento\\Backend\\Model\\Url', array(), array(), '', false); $objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this); $this->_model = $objectManagerHelper->getObject('Magento\\Cms\\Model\\Wysiwyg\\Images\\Storage', array('session' => $this->_sessionMock, 'backendUrl' => $this->_backendUrlMock, 'cmsWysiwygImages' => $this->_imageHelperMock, 'coreFileStorageDb' => $this->getMock('Magento\\Core\\Helper\\File\\Storage\\Database', array(), array(), '', false), 'filesystem' => $this->_filesystemMock, 'imageFactory' => $this->_adapterFactoryMock, 'assetRepo' => $this->getMock('Magento\\Framework\\View\\Asset\\Repository', array(), array(), '', false), 'storageCollectionFactory' => $this->_storageCollectionFactoryMock, 'storageFileFactory' => $this->_storageFileFactoryMock, 'storageDatabaseFactory' => $this->_storageDatabaseFactoryMock, 'directoryDatabaseFactory' => $this->_directoryDatabaseFactoryMock, 'uploaderFactory' => $this->_uploaderFactoryMock, 'resizeParameters' => $this->_resizeParameters)); }