|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Setup\Test\Unit\Model; |
| 8 | + |
| 9 | +use Magento\Setup\Model\SampleData; |
| 10 | +/** |
| 11 | + * Test Magento\Setup\Model\SampleData |
| 12 | + */ |
| 13 | +class InstallerTest extends \PHPUnit_Framework_TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var \Magento\Setup\Model\SampleData |
| 17 | + */ |
| 18 | + protected $sampleDataInstall; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject |
| 22 | + */ |
| 23 | + protected $objectManagerInterface; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var \Magento\Framework\Setup\LoggerInterface |
| 27 | + */ |
| 28 | + protected $loggerInterface; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var \Magento\Framework\App\Filesystem\DirectoryList |
| 32 | + */ |
| 33 | + protected $directoryList; |
| 34 | + |
| 35 | + protected function setUp() |
| 36 | + { |
| 37 | + $this->objectManagerInterface = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface'); |
| 38 | + $this->loggerInterface = $this->getMockForAbstractClass('Magento\Framework\Setup\LoggerInterface'); |
| 39 | + $this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false); |
| 40 | + $this->sampleDataInstall = new SampleData($this->directoryList); |
| 41 | + } |
| 42 | + |
| 43 | + public function testInstall() |
| 44 | + { |
| 45 | + $areaCode = 'adminhtml'; |
| 46 | + $userName = 'admin'; |
| 47 | + $modules = ['module_1', 'module_2']; |
| 48 | + $configData = ['config_data']; |
| 49 | + $sampleDataLogger = $this->getMock('Magento\SampleData\Model\Logger', ['setSubject'], [], '', false); |
| 50 | + $appState = $this->getMock('Magento\Framework\App\State', ['setAreaCode'], [], '', false); |
| 51 | + $configLoader = $this->getMock('Magento\Framework\App\ObjectManager\ConfigLoader', ['load'], [], '', false); |
| 52 | + $installer = $this->getMock('Magento\SampleData\Model\Installer', ['run'], [], '', false); |
| 53 | + $this->objectManagerInterface->expects($this->any())->method('get')->willReturnMap( |
| 54 | + [ |
| 55 | + ['Magento\SampleData\Model\Logger', $sampleDataLogger], |
| 56 | + ['Magento\Framework\App\State', $appState], |
| 57 | + ['Magento\Framework\App\ObjectManager\ConfigLoader', $configLoader], |
| 58 | + ['Magento\SampleData\Model\Installer', $installer] |
| 59 | + ] |
| 60 | + ); |
| 61 | + $sampleDataLogger->expects($this->any())->method('setSubject')->with($this->loggerInterface)->willReturnSelf(); |
| 62 | + $appState->expects($this->once())->method('setAreaCode')->with($areaCode)->willReturnSelf(); |
| 63 | + $configLoader->expects($this->once())->method('load')->with($areaCode)->willReturn($configData); |
| 64 | + $this->objectManagerInterface->expects($this->once())->method('configure')->with($configData) |
| 65 | + ->willReturnSelf(); |
| 66 | + $installer->expects($this->once())->method('run')->with($userName, $modules); |
| 67 | + $this->sampleDataInstall->install($this->objectManagerInterface, $this->loggerInterface, $userName, $modules); |
| 68 | + } |
| 69 | + |
| 70 | + public function testIsDeployed() |
| 71 | + { |
| 72 | + $this->directoryList->expects($this->once())->method('getPath')->with('code'); |
| 73 | + $this->sampleDataInstall->isDeployed(); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Test SampleData installation check method. |
| 78 | + * Can be tested only negative case because file_exists method used in the tested class |
| 79 | + */ |
| 80 | + public function testIsInstalledSuccessfully() |
| 81 | + { |
| 82 | + $this->assertFalse($this->sampleDataInstall->isInstalledSuccessfully()); |
| 83 | + } |
| 84 | +} |
0 commit comments