Skip to content

Commit b2ed451

Browse files
author
Volodymyr Klymenko
committed
Merge branch 'master' of github.corp.ebay.com:magento2/sample-data
2 parents ed5e229 + fb41d4b commit b2ed451

File tree

4 files changed

+194
-2
lines changed

4 files changed

+194
-2
lines changed

app/code/Magento/SampleData/Console/Command/SampleDataInstallCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Magento\Setup\Model\AdminAccount;
1818
use Magento\Framework\App\Bootstrap;
1919
use Magento\Framework\App\State;
20-
use Magento\Setup\Model\SampleData;
20+
use Magento\SampleData\Model\SampleData;
2121
use Magento\Framework\Setup\ConsoleLogger;
2222

2323
/**
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\SampleData\Model;
8+
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Filesystem;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\Setup\LoggerInterface;
13+
use Magento\SampleData\Helper\State;
14+
15+
/**
16+
* Sample data installer
17+
*
18+
* Serves as an integration point between Magento Setup application and Luma sample data component
19+
*/
20+
class SampleData
21+
{
22+
/**
23+
* Filesystem Directory List
24+
*
25+
* @var DirectoryList
26+
*/
27+
private $directoryList;
28+
29+
/**
30+
* Sample Data installation state
31+
*
32+
* @var State
33+
*/
34+
private $state;
35+
36+
/**
37+
* @param DirectoryList $directoryList
38+
* @param State $state
39+
*/
40+
public function __construct(DirectoryList $directoryList, State $state)
41+
{
42+
$this->directoryList = $directoryList;
43+
$this->state = $state;
44+
}
45+
46+
/**
47+
* Check whether installation of sample data was successful
48+
*
49+
* @return bool
50+
*/
51+
public function isInstalledSuccessfully()
52+
{
53+
return State::STATE_FINISHED === $this->state->getState();
54+
}
55+
56+
/**
57+
* Check whether there was unsuccessful attempt to install Sample data
58+
*
59+
* @return bool
60+
*/
61+
public function isInstallationError()
62+
{
63+
return State::STATE_STARTED === $this->state->getState();
64+
}
65+
66+
/**
67+
* Installation routine for creating sample data
68+
*
69+
* @param ObjectManagerInterface $objectManager
70+
* @param LoggerInterface $logger
71+
* @param string $userName
72+
* @param array $modules
73+
* @throws \Exception
74+
* @return void
75+
*/
76+
public function install(
77+
ObjectManagerInterface $objectManager,
78+
LoggerInterface $logger,
79+
$userName,
80+
array $modules = []
81+
) {
82+
/** @var \Magento\SampleData\Model\Logger $sampleDataLogger */
83+
$sampleDataLogger = $objectManager->get('Magento\SampleData\Model\Logger');
84+
$sampleDataLogger->setSubject($logger);
85+
86+
$areaCode = 'adminhtml';
87+
/** @var \Magento\Framework\App\State $appState */
88+
$appState = $objectManager->get('Magento\Framework\App\State');
89+
$appState->setAreaCode($areaCode);
90+
/** @var \Magento\Framework\ObjectManager\ConfigLoaderInterface $configLoader */
91+
$configLoader = $objectManager->get('Magento\Framework\ObjectManager\ConfigLoaderInterface');
92+
$objectManager->configure($configLoader->load($areaCode));
93+
94+
/** @var \Magento\SampleData\Model\Installer $installer */
95+
$installer = $objectManager->get('Magento\SampleData\Model\Installer');
96+
$installer->run($userName, $modules);
97+
}
98+
}

app/code/Magento/SampleData/Test/Unit/Console/Command/SampleDataInstallCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function testExecute()
1515
$objectManagerFactory = $this->getMock('Magento\Framework\App\ObjectManagerFactory', [], [], '', false);
1616
$objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface', [], [], '', false);
1717

18-
$sampleData = $this->getMock('Magento\Setup\Model\SampleData', ['install'], [], '', false);
18+
$sampleData = $this->getMock('Magento\SampleData\Model\SampleData', ['install'], [], '', false);
1919
$sampleData->expects($this->once())
2020
->method('install')
2121
->with(
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\SampleData\Test\Unit\Model;
8+
9+
use Magento\SampleData\Model\SampleData;
10+
11+
/**
12+
* Test Magento\Setup\Model\SampleData
13+
*/
14+
class SampleDataTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @var \Magento\SampleData\Model\SampleData
18+
*/
19+
protected $sampleDataInstall;
20+
21+
/**
22+
* @var \Magento\Framework\App\Filesystem\DirectoryList
23+
*/
24+
protected $directoryList;
25+
26+
/**
27+
* @var \Magento\SampleData\Helper\State|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
protected $state;
30+
31+
protected function setUp()
32+
{
33+
$this->directoryList = $this->getMock('Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false);
34+
$this->state = $this->getMock('Magento\SampleData\Helper\State', [], [], '', false);
35+
$this->sampleDataInstall = new SampleData($this->directoryList, $this->state);
36+
}
37+
38+
public function testIsInstalledSuccessfullyTrue()
39+
{
40+
$this->state->expects($this->once())
41+
->method('getState')
42+
->willReturn(\Magento\SampleData\Helper\State::STATE_FINISHED);
43+
$this->assertTrue($this->sampleDataInstall->isInstalledSuccessfully());
44+
}
45+
46+
public function testIsInstalledSuccessfullyFalse()
47+
{
48+
$this->state->expects($this->once())
49+
->method('getState')
50+
->willReturn(\Magento\SampleData\Helper\State::STATE_NOT_STARTED);
51+
$this->assertFalse($this->sampleDataInstall->isInstalledSuccessfully());
52+
}
53+
54+
public function testIsInstallationErrorTrue()
55+
{
56+
$this->state->expects($this->once())
57+
->method('getState')
58+
->willReturn(\Magento\SampleData\Helper\State::STATE_STARTED);
59+
$this->assertTrue($this->sampleDataInstall->isInstallationError());
60+
}
61+
62+
public function testIsInstallationErrorFalse()
63+
{
64+
$this->state->expects($this->once())
65+
->method('getState')
66+
->willReturn(\Magento\SampleData\Helper\State::STATE_NOT_STARTED);
67+
$this->assertFalse($this->sampleDataInstall->isInstallationError());
68+
}
69+
70+
public function testInstall()
71+
{
72+
$objectManager = $this->getMockForAbstractClass('Magento\Framework\ObjectManagerInterface', [], '', false);
73+
$logger = $this->getMockForAbstractClass('Magento\Framework\Setup\LoggerInterface', [], '', false);
74+
$sampleLogger = $this->getMock('Magento\SampleData\Model\Logger', [], [], '', false);
75+
$sampleLogger->expects($this->once())->method('setSubject')->with($logger);
76+
$objectManager->expects($this->at(0))->method('get')->willReturn($sampleLogger);
77+
$state = $this->getMock('Magento\Framework\App\State', [], [], '', false);
78+
$objectManager->expects($this->at(1))->method('get')->willReturn($state);
79+
$state->expects($this->once())->method('setAreaCode')->with('adminhtml');
80+
$configLoader = $this->getMockForAbstractClass(
81+
'Magento\Framework\ObjectManager\ConfigLoaderInterface',
82+
[],
83+
'',
84+
false
85+
);
86+
$objectManager->expects($this->at(2))->method('get')->willReturn($configLoader);
87+
$configLoader->expects($this->once())->method('load')->willReturn([]);
88+
$objectManager->expects($this->at(3))->method('configure')->with([]);
89+
$installer = $this->getMock('Magento\SampleData\Model\Installer', [], [], '', false);
90+
$objectManager->expects($this->at(4))->method('get')->willReturn($installer);
91+
$installer->expects($this->once())->method('run')->with('admin', []);
92+
$this->sampleDataInstall->install($objectManager, $logger, 'admin', []);
93+
}
94+
}

0 commit comments

Comments
 (0)