|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Deploy\Test\Unit\Collector; |
| 9 | + |
| 10 | +use Magento\Deploy\Collector\Collector; |
| 11 | +use Magento\Deploy\Source\SourcePool; |
| 12 | +use Magento\Deploy\Package\PackageFactory; |
| 13 | +use Magento\Deploy\Source\SourceInterface; |
| 14 | +use Magento\Deploy\Package\PackageFile; |
| 15 | +use Magento\Framework\Module\Manager; |
| 16 | +use Magento\Framework\View\Asset\PreProcessor\FileNameResolver; |
| 17 | +use PHPUnit\Framework\MockObject\MockObject; |
| 18 | +use PHPUnit\Framework\TestCase; |
| 19 | + |
| 20 | +class CollectorTest extends TestCase |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @var SourcePool|MockObject |
| 24 | + */ |
| 25 | + private $sourcePool; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var FileNameResolver|MockObject |
| 29 | + */ |
| 30 | + private $fileNameResolver; |
| 31 | + |
| 32 | + /** |
| 33 | + * @var PackageFactory|MockObject |
| 34 | + */ |
| 35 | + private $packageFactory; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var Manager|MockObject |
| 39 | + */ |
| 40 | + private $moduleManager; |
| 41 | + |
| 42 | + /** |
| 43 | + * @var SourceInterface|MockObject |
| 44 | + */ |
| 45 | + private $source; |
| 46 | + |
| 47 | + /** |
| 48 | + * @var PackageFile|MockObject |
| 49 | + */ |
| 50 | + private $fileWithName; |
| 51 | + |
| 52 | + /** |
| 53 | + * @var PackageFile|MockObject |
| 54 | + */ |
| 55 | + private $fileWithoutName; |
| 56 | + |
| 57 | + /** |
| 58 | + * @var Collector |
| 59 | + */ |
| 60 | + private $model; |
| 61 | + |
| 62 | + /** |
| 63 | + * @inheritdoc |
| 64 | + */ |
| 65 | + protected function setUp(): void |
| 66 | + { |
| 67 | + $this->sourcePool = $this->getMockBuilder(SourcePool::class) |
| 68 | + ->disableOriginalConstructor() |
| 69 | + ->getMock(); |
| 70 | + $this->fileNameResolver = $this->getMockBuilder(FileNameResolver::class) |
| 71 | + ->disableOriginalConstructor() |
| 72 | + ->getMock(); |
| 73 | + $this->packageFactory = $this->getMockBuilder(PackageFactory::class) |
| 74 | + ->disableOriginalConstructor() |
| 75 | + ->getMock(); |
| 76 | + $this->moduleManager = $this->getMockBuilder(Manager::class) |
| 77 | + ->disableOriginalConstructor() |
| 78 | + ->getMock(); |
| 79 | + $this->source = $this->getMockBuilder(SourceInterface::class) |
| 80 | + ->getMockForAbstractClass(); |
| 81 | + $this->fileWithName = $this->getMockBuilder(PackageFile::class) |
| 82 | + ->disableOriginalConstructor() |
| 83 | + ->getMock(); |
| 84 | + $this->fileWithName->expects($this->any()) |
| 85 | + ->method('getFileName') |
| 86 | + ->willReturn('name'); |
| 87 | + $this->fileWithoutName = $this->getMockBuilder(PackageFile::class) |
| 88 | + ->disableOriginalConstructor() |
| 89 | + ->getMock(); |
| 90 | + $this->fileWithoutName->expects($this->any()) |
| 91 | + ->method('getFileName') |
| 92 | + ->willReturn(''); |
| 93 | + |
| 94 | + $this->model = new Collector( |
| 95 | + $this->sourcePool, |
| 96 | + $this->fileNameResolver, |
| 97 | + $this->packageFactory, |
| 98 | + $this->moduleManager |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + public function testCollect(): void |
| 103 | + { |
| 104 | + $this->sourcePool->expects($this->once()) |
| 105 | + ->method('getAll') |
| 106 | + ->willReturn([$this->source]); |
| 107 | + $this->source->expects($this->once()) |
| 108 | + ->method('get') |
| 109 | + ->willReturn([$this->fileWithoutName, $this->fileWithName]); |
| 110 | + $this->fileWithoutName->expects($this->exactly(0)) |
| 111 | + ->method('setDeployedFileName'); |
| 112 | + $this->fileWithName->expects($this->exactly(1)) |
| 113 | + ->method('setDeployedFileName'); |
| 114 | + $this->model->collect(); |
| 115 | + } |
| 116 | +} |
0 commit comments