|
5 | 5 | */
|
6 | 6 | namespace Magento\Developer\Test\Unit\Model\Css\PreProcessor\FileGenerator;
|
7 | 7 |
|
| 8 | +use Magento\Framework\App\State; |
| 9 | +use Magento\Framework\App\View\Asset\Publisher; |
| 10 | +use Magento\Framework\Css\PreProcessor\Instruction\Import; |
8 | 11 | use Magento\Framework\Filesystem;
|
9 | 12 | use Magento\Framework\App\Config\ScopeConfigInterface;
|
10 | 13 | use Magento\Framework\Css\PreProcessor\File\Temporary;
|
11 | 14 | use Magento\Developer\Model\Css\PreProcessor\FileGenerator\PublicationDecorator;
|
| 15 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 16 | +use Magento\Framework\View\Asset\File; |
| 17 | +use Magento\Framework\View\Asset\LocalInterface; |
| 18 | +use Magento\Framework\View\Asset\Repository; |
12 | 19 |
|
13 | 20 | /**
|
14 |
| - * Class PublicationDecoratorTest |
| 21 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
15 | 22 | */
|
16 | 23 | class PublicationDecoratorTest extends \PHPUnit_Framework_TestCase
|
17 | 24 | {
|
18 | 25 | /**
|
19 |
| - * Calls generate method to access protected method generateRelatedFile |
| 26 | + * @var PublicationDecorator |
20 | 27 | */
|
21 |
| - public function testGenerateRelatedFile() |
| 28 | + private $model; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var Filesystem|\PHPUnit_Framework_MockObject_MockObject |
| 32 | + */ |
| 33 | + private $filesystemMock; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var Temporary|\PHPUnit_Framework_MockObject_MockObject |
| 37 | + */ |
| 38 | + private $temporaryFileMock; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var Publisher|\PHPUnit_Framework_MockObject_MockObject |
| 42 | + */ |
| 43 | + private $publisherMock; |
| 44 | + |
| 45 | + /** |
| 46 | + * @var Repository|\PHPUnit_Framework_MockObject_MockObject |
| 47 | + */ |
| 48 | + private $assetRepositoryMock; |
| 49 | + |
| 50 | + /** |
| 51 | + * @var File|\PHPUnit_Framework_MockObject_MockObject |
| 52 | + */ |
| 53 | + private $relatedAssetMock; |
| 54 | + |
| 55 | + /** |
| 56 | + * @var Import|\PHPUnit_Framework_MockObject_MockObject |
| 57 | + */ |
| 58 | + private $importGeneratorMock; |
| 59 | + |
| 60 | + /** |
| 61 | + * @var LocalInterface|\PHPUnit_Framework_MockObject_MockObject |
| 62 | + */ |
| 63 | + private $localAssetMock; |
| 64 | + |
| 65 | + /** |
| 66 | + * @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject |
| 67 | + */ |
| 68 | + private $scopeConfigMock; |
| 69 | + |
| 70 | + /** |
| 71 | + * @var State|\PHPUnit_Framework_MockObject_MockObject |
| 72 | + */ |
| 73 | + private $stateMock; |
| 74 | + |
| 75 | + protected function setUp() |
22 | 76 | {
|
23 |
| - $filesystemMock = $this->getMockBuilder(Filesystem::class) |
| 77 | + $this->filesystemMock = $this->getMockBuilder(Filesystem::class) |
24 | 78 | ->disableOriginalConstructor()
|
25 | 79 | ->getMock();
|
26 |
| - $fileTemporaryMock = $this->getMockBuilder(Temporary::class) |
| 80 | + $this->temporaryFileMock = $this->getMockBuilder(Temporary::class) |
27 | 81 | ->disableOriginalConstructor()
|
28 | 82 | ->getMock();
|
29 |
| - |
30 |
| - $publisherMock = $this->getMockBuilder(\Magento\Framework\App\View\Asset\Publisher::class) |
| 83 | + $this->publisherMock = $this->getMockBuilder(Publisher::class) |
31 | 84 | ->disableOriginalConstructor()
|
32 | 85 | ->getMock();
|
33 |
| - $assetRepoMock = $this->getMockBuilder(\Magento\Framework\View\Asset\Repository::class) |
| 86 | + $this->assetRepositoryMock = $this->getMockBuilder(Repository::class) |
34 | 87 | ->disableOriginalConstructor()
|
35 | 88 | ->getMock();
|
36 |
| - $relatedAssetMock = $this->getMockBuilder(\Magento\Framework\View\Asset\File::class) |
| 89 | + $this->relatedAssetMock = $this->getMockBuilder(File::class) |
37 | 90 | ->disableOriginalConstructor()
|
38 | 91 | ->getMock();
|
39 |
| - $importGeneratorMock = $this->getMockBuilder(\Magento\Framework\Css\PreProcessor\Instruction\Import::class) |
| 92 | + $this->importGeneratorMock = $this->getMockBuilder(Import::class) |
40 | 93 | ->disableOriginalConstructor()
|
41 | 94 | ->getMock();
|
42 |
| - $localAssetMock = $this->getMockBuilder(\Magento\Framework\View\Asset\LocalInterface::class) |
| 95 | + $this->localAssetMock = $this->getMockBuilder(LocalInterface::class) |
43 | 96 | ->disableOriginalConstructor()
|
44 | 97 | ->getMock();
|
45 |
| - $scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) |
| 98 | + $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) |
46 | 99 | ->getMockForAbstractClass();
|
| 100 | + $this->stateMock = $this->getMockBuilder(State::class) |
| 101 | + ->disableOriginalConstructor() |
| 102 | + ->getMock(); |
47 | 103 |
|
48 |
| - $relatedFileId = 'file_id'; |
| 104 | + $this->model = (new ObjectManager($this))->getObject(PublicationDecorator::class, [ |
| 105 | + 'filesystem' => $this->filesystemMock, |
| 106 | + 'assetRepository' => $this->assetRepositoryMock, |
| 107 | + 'temporaryFile' => $this->temporaryFileMock, |
| 108 | + 'assetPublisher' => $this->publisherMock, |
| 109 | + 'scopeConfig' => $this->scopeConfigMock, |
| 110 | + 'state' => $this->stateMock, |
| 111 | + 'hasRelatedPublishing' => true |
| 112 | + ]); |
| 113 | + } |
49 | 114 |
|
50 |
| - $relatedFiles = [[$relatedFileId, $localAssetMock]]; |
| 115 | + /** |
| 116 | + * Calls generate method to access protected method generateRelatedFile |
| 117 | + */ |
| 118 | + public function testGenerateRelatedFile() |
| 119 | + { |
| 120 | + $relatedFileId = 'file_id'; |
| 121 | + $relatedFiles = [[$relatedFileId, $this->localAssetMock]]; |
51 | 122 |
|
52 |
| - $importGeneratorMock->expects(self::any()) |
| 123 | + $this->importGeneratorMock->expects($this->any()) |
53 | 124 | ->method('getRelatedFiles')
|
54 |
| - ->will(self::onConsecutiveCalls($relatedFiles, [])); |
55 |
| - |
56 |
| - $assetRepoMock->expects(self::any()) |
| 125 | + ->willReturnOnConsecutiveCalls($relatedFiles, []); |
| 126 | + $this->assetRepositoryMock->expects($this->any()) |
57 | 127 | ->method('createRelated')
|
58 |
| - ->willReturn($relatedAssetMock); |
59 |
| - |
60 |
| - $publisherMock->expects(self::once()) |
| 128 | + ->willReturn($this->relatedAssetMock); |
| 129 | + $this->publisherMock->expects($this->once()) |
61 | 130 | ->method('publish')
|
62 |
| - ->with($relatedAssetMock); |
63 |
| - |
64 |
| - $model = new PublicationDecorator( |
65 |
| - $filesystemMock, |
66 |
| - $assetRepoMock, |
67 |
| - $fileTemporaryMock, |
68 |
| - $publisherMock, |
69 |
| - $scopeConfigMock, |
70 |
| - true |
71 |
| - ); |
72 |
| - |
73 |
| - $model->generate($importGeneratorMock); |
| 131 | + ->with($this->relatedAssetMock); |
| 132 | + |
| 133 | + $this->model->generate($this->importGeneratorMock); |
74 | 134 | }
|
75 | 135 | }
|
0 commit comments