|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Developer\Test\Unit\Console\Command; |
| 7 | + |
| 8 | +use Magento\Framework\Validator\Locale; |
| 9 | +use Magento\Framework\View\Asset\Repository; |
| 10 | +use Magento\Framework\App\View\Asset\Publisher; |
| 11 | +use Magento\Framework\View\Asset\LocalInterface; |
| 12 | +use Symfony\Component\Console\Input\InputInterface; |
| 13 | +use Symfony\Component\Console\Output\OutputInterface; |
| 14 | +use Magento\Developer\Console\Command\SourceThemeDeployCommand; |
| 15 | + |
| 16 | +/** |
| 17 | + * Class SourceThemeDeployCommandTest |
| 18 | + * |
| 19 | + * @see \Magento\Developer\Console\Command\SourceThemeDeployCommand |
| 20 | + */ |
| 21 | +class SourceThemeDeployCommandTest extends \PHPUnit_Framework_TestCase |
| 22 | +{ |
| 23 | + const AREA_TEST_VALUE = 'area-test-value'; |
| 24 | + |
| 25 | + const LOCALE_TEST_VALUE = 'locale-test-value'; |
| 26 | + |
| 27 | + const THEME_TEST_VALUE = 'theme-test-value'; |
| 28 | + |
| 29 | + const TYPE_TEST_VALUE = 'type-test-value'; |
| 30 | + |
| 31 | + const FILE_TEST_VALUE = 'file-test-value/test/file'; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var SourceThemeDeployCommand |
| 35 | + */ |
| 36 | + private $sourceThemeDeployCommand; |
| 37 | + |
| 38 | + /** |
| 39 | + * @var Locale|\PHPUnit_Framework_MockObject_MockObject |
| 40 | + */ |
| 41 | + private $validatorMock; |
| 42 | + |
| 43 | + /** |
| 44 | + * @var Publisher|\PHPUnit_Framework_MockObject_MockObject |
| 45 | + */ |
| 46 | + private $assetPublisherMock; |
| 47 | + |
| 48 | + /** |
| 49 | + * @var Repository|\PHPUnit_Framework_MockObject_MockObject |
| 50 | + */ |
| 51 | + private $assetRepositoryMock; |
| 52 | + |
| 53 | + /** |
| 54 | + * Set up |
| 55 | + */ |
| 56 | + protected function setUp() |
| 57 | + { |
| 58 | + $this->validatorMock = $this->getMockBuilder(Locale::class) |
| 59 | + ->disableOriginalConstructor() |
| 60 | + ->getMock(); |
| 61 | + $this->assetPublisherMock = $this->getMockBuilder(Publisher::class) |
| 62 | + ->disableOriginalConstructor() |
| 63 | + ->getMock(); |
| 64 | + $this->assetRepositoryMock = $this->getMockBuilder(Repository::class) |
| 65 | + ->disableOriginalConstructor() |
| 66 | + ->getMock(); |
| 67 | + |
| 68 | + $this->sourceThemeDeployCommand = new SourceThemeDeployCommand( |
| 69 | + $this->validatorMock, |
| 70 | + $this->assetPublisherMock, |
| 71 | + $this->assetRepositoryMock |
| 72 | + ); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Run test for execute method |
| 77 | + */ |
| 78 | + public function testExecute() |
| 79 | + { |
| 80 | + /** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject $outputMock */ |
| 81 | + $outputMock = $this->getMockBuilder(OutputInterface::class) |
| 82 | + ->getMockForAbstractClass(); |
| 83 | + $assetMock = $this->getMockBuilder(LocalInterface::class) |
| 84 | + ->getMockForAbstractClass(); |
| 85 | + |
| 86 | + $this->validatorMock->expects(self::once()) |
| 87 | + ->method('isValid') |
| 88 | + ->with(self::LOCALE_TEST_VALUE) |
| 89 | + ->willReturn(true); |
| 90 | + |
| 91 | + $message = sprintf( |
| 92 | + '<info>Processed Area: %s, Locale: %s, Theme: %s, File type: %s.</info>', |
| 93 | + self::AREA_TEST_VALUE, |
| 94 | + self::LOCALE_TEST_VALUE, |
| 95 | + self::THEME_TEST_VALUE, |
| 96 | + self::TYPE_TEST_VALUE |
| 97 | + ); |
| 98 | + |
| 99 | + $outputMock->expects(self::at(0)) |
| 100 | + ->method('writeln') |
| 101 | + ->with($message); |
| 102 | + $outputMock->expects(self::at(1)) |
| 103 | + ->method('writeln') |
| 104 | + ->with('<comment>-> file-test-value/test/file</comment>'); |
| 105 | + $outputMock->expects(self::at(2)) |
| 106 | + ->method('writeln') |
| 107 | + ->with('<info>Successfully processed.</info>'); |
| 108 | + |
| 109 | + $this->assetRepositoryMock->expects(self::once()) |
| 110 | + ->method('createAsset') |
| 111 | + ->with( |
| 112 | + 'file-test-value/test' . DIRECTORY_SEPARATOR . 'file' . '.' . self::TYPE_TEST_VALUE, |
| 113 | + [ |
| 114 | + 'area' => self::AREA_TEST_VALUE, |
| 115 | + 'theme' => self::THEME_TEST_VALUE, |
| 116 | + 'locale' => self::LOCALE_TEST_VALUE, |
| 117 | + ] |
| 118 | + )->willReturn($assetMock); |
| 119 | + |
| 120 | + $this->assetPublisherMock->expects(self::once()) |
| 121 | + ->method('publish') |
| 122 | + ->with($assetMock); |
| 123 | + |
| 124 | + $assetMock->expects(self::once()) |
| 125 | + ->method('getFilePath') |
| 126 | + ->willReturn(self::FILE_TEST_VALUE); |
| 127 | + |
| 128 | + $this->sourceThemeDeployCommand->run($this->getInputMock(), $outputMock); |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * @return InputInterface|\PHPUnit_Framework_MockObject_MockObject |
| 133 | + */ |
| 134 | + private function getInputMock() |
| 135 | + { |
| 136 | + $inputMock = $this->getMockBuilder(InputInterface::class) |
| 137 | + ->getMockForAbstractClass(); |
| 138 | + |
| 139 | + $inputMock->expects(self::exactly(4)) |
| 140 | + ->method('getOption') |
| 141 | + ->willReturnMap( |
| 142 | + [ |
| 143 | + ['area', self::AREA_TEST_VALUE], |
| 144 | + ['locale', self::LOCALE_TEST_VALUE], |
| 145 | + ['theme', self::THEME_TEST_VALUE], |
| 146 | + ['type', self::TYPE_TEST_VALUE] |
| 147 | + ] |
| 148 | + ); |
| 149 | + $inputMock->expects(self::once()) |
| 150 | + ->method('getArgument') |
| 151 | + ->with('file') |
| 152 | + ->willReturn([self::FILE_TEST_VALUE]); |
| 153 | + |
| 154 | + return $inputMock; |
| 155 | + } |
| 156 | +} |
0 commit comments