objectManager = new ObjectManager($this); $this->_backupDbMock = $this->createMock(\Magento\Framework\Backup\Db::class); $this->_backupDbMock->expects($this->any())->method('setBackupExtension')->will($this->returnSelf()); $this->_backupDbMock->expects($this->any())->method('setTime')->will($this->returnSelf()); $this->_backupDbMock->expects($this->any())->method('setBackupsDir')->will($this->returnSelf()); $this->_backupDbMock->expects($this->any())->method('setResourceModel')->will($this->returnSelf()); $this->_backupDbMock->expects( $this->any() )->method( 'getBackupPath' )->will( $this->returnValue('\unexistingpath') ); $this->_backupDbMock->expects($this->any())->method('create')->will($this->returnValue(true)); $this->_filesystemMock = $this->createMock(\Magento\Framework\Filesystem::class); $dirMock = $this->getMockForAbstractClass(\Magento\Framework\Filesystem\Directory\WriteInterface::class); $this->_filesystemMock->expects($this->any()) ->method('getDirectoryWrite') ->will($this->returnValue($dirMock)); $this->_backupFactoryMock = $this->createMock(\Magento\Framework\Backup\Factory::class); $this->_backupFactoryMock->expects( $this->once() )->method( 'create' )->will( $this->returnValue($this->_backupDbMock) ); $this->fsMock = $this->createMock(\Magento\Framework\Backup\Filesystem\Rollback\Fs::class); } /** * @param string $action * @dataProvider actionProvider */ public function testAction($action) { $this->_backupFactoryMock->expects($this->once())->method('create'); $rootDir = TESTS_TEMP_DIR . '/Magento/Backup/data'; $model = $this->objectManager->getObject( \Magento\Framework\Backup\Nomedia::class, [ 'filesystem' => $this->_filesystemMock, 'backupFactory' => $this->_backupFactoryMock, 'rollBackFs' => $this->fsMock, ] ); $model->setRootDir($rootDir); $model->setBackupsDir($rootDir); $model->{$action}(); $this->assertTrue($model->getIsSuccess()); $this->assertEquals([$rootDir, $rootDir . '/media', $rootDir . '/pub/media'], $model->getIgnorePaths()); } /** * @return array */ public static function actionProvider() { return [['create'], ['rollback']]; } }