|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2016 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\SampleData\Model; |
| 7 | + |
| 8 | +use Magento\Framework\Composer\ComposerInformation; |
| 9 | +use Magento\Framework\Component\ComponentRegistrar; |
| 10 | +use Magento\Framework\Filesystem; |
| 11 | +use Magento\Framework\Config\Composer\PackageFactory; |
| 12 | + |
| 13 | +class DependencyTest extends \PHPUnit_Framework_TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var \Magento\SampleData\Model\Dependency |
| 17 | + */ |
| 18 | + private $model; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var ComposerInformation|\PHPUnit_Framework_MockObject_MockObject |
| 22 | + */ |
| 23 | + protected $composerInformationMock; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var ComponentRegistrar|\PHPUnit_Framework_MockObject_MockObject |
| 27 | + */ |
| 28 | + private $componentRegistrarMock; |
| 29 | + |
| 30 | + protected function setUp() |
| 31 | + { |
| 32 | + $this->composerInformationMock = $this->getMockBuilder(ComposerInformation::class) |
| 33 | + ->disableOriginalConstructor() |
| 34 | + ->disableOriginalClone() |
| 35 | + ->getMock(); |
| 36 | + $this->componentRegistrarMock = $this->getMockBuilder(ComponentRegistrar::class) |
| 37 | + ->disableOriginalConstructor() |
| 38 | + ->disableOriginalClone() |
| 39 | + ->getMock(); |
| 40 | + |
| 41 | + $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
| 42 | + $this->model = $objectManager->create( |
| 43 | + \Magento\SampleData\Model\Dependency::class, |
| 44 | + [ |
| 45 | + 'composerInformation' => $this->composerInformationMock, |
| 46 | + 'filesystem' => $objectManager->get(Filesystem::class), |
| 47 | + 'packageFactory' => $objectManager->get(PackageFactory::class), |
| 48 | + 'componentRegistrar' => $this->componentRegistrarMock |
| 49 | + ] |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + public function testGetSampleDataPackages() |
| 54 | + { |
| 55 | + $this->composerInformationMock->expects($this->once()) |
| 56 | + ->method('getSuggestedPackages') |
| 57 | + ->willReturn([]); |
| 58 | + $this->componentRegistrarMock->expects($this->once()) |
| 59 | + ->method('getPaths') |
| 60 | + ->with(ComponentRegistrar::MODULE) |
| 61 | + ->willReturn([ |
| 62 | + __DIR__ . '/../_files/Modules/FirstModule', |
| 63 | + __DIR__ . '/../_files/Modules/SecondModule', |
| 64 | + __DIR__ . '/../_files/Modules/ThirdModule', |
| 65 | + __DIR__ . '/../_files/Modules/FourthModule' |
| 66 | + ]); |
| 67 | + |
| 68 | + $this->assertSame( |
| 69 | + ['magento/module-first-sample-data' => '777.7.*'], |
| 70 | + $this->model->getSampleDataPackages() |
| 71 | + ); |
| 72 | + } |
| 73 | +} |
0 commit comments