validatorMock = $this->getMockBuilder(Locale::class) ->disableOriginalConstructor() ->getMock(); $this->assetPublisherMock = $this->getMockBuilder(Publisher::class) ->disableOriginalConstructor() ->getMock(); $this->assetRepositoryMock = $this->getMockBuilder(Repository::class) ->disableOriginalConstructor() ->getMock(); $this->sourceThemeDeployCommand = new SourceThemeDeployCommand( $this->validatorMock, $this->assetPublisherMock, $this->assetRepositoryMock ); } /** * Run test for execute method */ public function testExecute() { /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject $outputMock */ $outputMock = $this->getMockBuilder(OutputInterface::class) ->getMockForAbstractClass(); $assetMock = $this->getMockBuilder(LocalInterface::class) ->getMockForAbstractClass(); $this->validatorMock->expects(self::once()) ->method('isValid') ->with(self::LOCALE_TEST_VALUE) ->willReturn(true); $message = sprintf( 'Processed Area: %s, Locale: %s, Theme: %s, File type: %s.', self::AREA_TEST_VALUE, self::LOCALE_TEST_VALUE, self::THEME_TEST_VALUE, self::TYPE_TEST_VALUE ); $outputMock->expects(self::at(0)) ->method('writeln') ->with($message); $outputMock->expects(self::at(1)) ->method('writeln') ->with('-> file-test-value/test/file'); $outputMock->expects(self::at(2)) ->method('writeln') ->with('Successfully processed.'); $this->assetRepositoryMock->expects(self::once()) ->method('createAsset') ->with( 'file-test-value/test' . DIRECTORY_SEPARATOR . 'file' . '.' . self::TYPE_TEST_VALUE, [ 'area' => self::AREA_TEST_VALUE, 'theme' => self::THEME_TEST_VALUE, 'locale' => self::LOCALE_TEST_VALUE, ] )->willReturn($assetMock); $this->assetPublisherMock->expects(self::once()) ->method('publish') ->with($assetMock); $assetMock->expects(self::once()) ->method('getFilePath') ->willReturn(self::FILE_TEST_VALUE); $this->sourceThemeDeployCommand->run($this->getInputMock(), $outputMock); } /** * Run test for execute method with incorrect theme value * * @expectedException \InvalidArgumentException * @expectedExceptionMessage Value "theme-value" of the option "theme" has invalid format. The format should be */ public function testExecuteIncorrectThemeFormat() { /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject $outputMock */ $outputMock = $this->getMockBuilder(OutputInterface::class) ->getMockForAbstractClass(); $this->validatorMock->expects(self::once()) ->method('isValid') ->with(self::LOCALE_TEST_VALUE) ->willReturn(true); $valueMap = [ ['area', self::AREA_TEST_VALUE], ['locale', self::LOCALE_TEST_VALUE], ['theme', self::THEME_INCORRECT_FORMAT_VALUE], ['type', self::TYPE_TEST_VALUE] ]; $this->sourceThemeDeployCommand->run( $this->getInputMock($valueMap), $outputMock ); } /** * Run test for execute method with non existing theme * * @expectedException \InvalidArgumentException * @expectedExceptionMessage Verify entered values of the argument and options. */ public function testExecuteNonExistingValue() { /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject $outputMock */ $outputMock = $this->getMockBuilder(OutputInterface::class) ->getMockForAbstractClass(); $assetMock = $this->getMockBuilder(LocalInterface::class) ->getMockForAbstractClass(); $this->validatorMock->expects(self::once()) ->method('isValid') ->with(self::LOCALE_TEST_VALUE) ->willReturn(true); $this->assetRepositoryMock->expects(self::once()) ->method('createAsset') ->with( 'file-test-value/test' . DIRECTORY_SEPARATOR . 'file' . '.' . self::TYPE_TEST_VALUE, [ 'area' => self::AREA_TEST_VALUE, 'theme' => self::THEME_NONEXISTING_VALUE, 'locale' => self::LOCALE_TEST_VALUE, ] )->willReturn($assetMock); $this->assetPublisherMock->expects(self::once()) ->method('publish') ->with($assetMock) ->willThrowException(new \Magento\Framework\View\Asset\File\NotFoundException); $valueMap = [ ['area', self::AREA_TEST_VALUE], ['locale', self::LOCALE_TEST_VALUE], ['theme', self::THEME_NONEXISTING_VALUE], ['type', self::TYPE_TEST_VALUE] ]; $this->sourceThemeDeployCommand->run( $this->getInputMock($valueMap), $outputMock ); } /** * @return InputInterface|\PHPUnit_Framework_MockObject_MockObject */ private function getInputMock(array $valueMap = []) { $inputMock = $this->getMockBuilder(InputInterface::class) ->getMockForAbstractClass(); $defaultValueMap = [ ['area', self::AREA_TEST_VALUE], ['locale', self::LOCALE_TEST_VALUE], ['theme', self::THEME_TEST_VALUE], ['type', self::TYPE_TEST_VALUE] ]; $valueMap = empty($valueMap) ? $defaultValueMap : $valueMap; $inputMock->expects(self::exactly(4)) ->method('getOption') ->willReturnMap( $valueMap ); $inputMock->expects(self::once()) ->method('getArgument') ->with('file') ->willReturn([self::FILE_TEST_VALUE]); return $inputMock; } }