Skip to content

Commit 3c3168a

Browse files
committed
Merge remote-tracking branch 'ogresCE/MAGETWO-38383-Increase-Unit-Tests-Code-Coverage-of-Fixtures' into PR_Branch
2 parents 6cd43be + b105e0c commit 3c3168a

14 files changed

+1781
-5
lines changed

setup/src/Magento/Setup/Fixtures/FixtureModel.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ public function reindex(OutputInterface $output)
105105
*/
106106
public function loadFixtures()
107107
{
108-
if (!is_readable(__DIR__)) {
109-
throw new \Exception(
110-
'Fixtures set directory `' . __DIR__ . '` is not readable or does not exists.'
111-
);
112-
}
113108
$files = glob(__DIR__ . DIRECTORY_SEPARATOR . self::FIXTURE_PATTERN);
114109

115110
foreach ($files as $file) {
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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\Fixtures;
8+
9+
use \Magento\Setup\Fixtures\CartPriceRulesFixture;
10+
11+
class CartPriceRulesFixtureTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Fixtures\FixtureModel
15+
*/
16+
private $fixtureModelMock;
17+
18+
/**
19+
* @var \Magento\Setup\Fixtures\CartPriceRulesFixture
20+
*/
21+
private $model;
22+
23+
public function setUp()
24+
{
25+
$this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false);
26+
27+
$this->model = new CartPriceRulesFixture($this->fixtureModelMock);
28+
}
29+
30+
public function testExecute()
31+
{
32+
$storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
33+
$storeMock->expects($this->once())
34+
->method('getRootCategoryId')
35+
->will($this->returnValue(2));
36+
37+
$websiteMock = $this->getMock('\Magento\Store\Model\Website', [], [], '', false);
38+
$websiteMock->expects($this->once())
39+
->method('getGroups')
40+
->will($this->returnValue([$storeMock]));
41+
$websiteMock->expects($this->once())
42+
->method('getId')
43+
->will($this->returnValue('website_id'));
44+
45+
$contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false);
46+
$abstractDbMock = $this->getMockForAbstractClass(
47+
'\Magento\Framework\Model\Resource\Db\AbstractDb',
48+
[$contextMock],
49+
'',
50+
true,
51+
true,
52+
true,
53+
['getAllChildren']
54+
);
55+
$abstractDbMock->expects($this->once())
56+
->method('getAllChildren')
57+
->will($this->returnValue([1]));
58+
59+
$storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false);
60+
$storeManagerMock->expects($this->once())
61+
->method('getWebsites')
62+
->will($this->returnValue([$websiteMock]));
63+
64+
$categoryMock = $this->getMock('Magento\Catalog\Model\Category', [], [], '', false);
65+
$categoryMock->expects($this->once())
66+
->method('getResource')
67+
->will($this->returnValue($abstractDbMock));
68+
$categoryMock->expects($this->once())
69+
->method('getPath')
70+
->will($this->returnValue('path/to/file'));
71+
$categoryMock->expects($this->once())
72+
->method('getId')
73+
->will($this->returnValue('category_id'));
74+
75+
$modelMock = $this->getMock('\Magento\SalesRule\Model\Rule', [], [], '', false);
76+
$modelMock->expects($this->once())
77+
->method('getIdFieldName')
78+
->will($this->returnValue('Field Id Name'));
79+
80+
$objectValueMap = [
81+
['Magento\SalesRule\Model\Rule', $modelMock],
82+
['Magento\Catalog\Model\Category', $categoryMock]
83+
];
84+
85+
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
86+
$objectManagerMock->expects($this->once())
87+
->method('create')
88+
->will($this->returnValue($storeManagerMock));
89+
$objectManagerMock->expects($this->exactly(2))
90+
->method('get')
91+
->will($this->returnValueMap($objectValueMap));
92+
93+
$valueMap = [
94+
['cart_price_rules', 0, 1],
95+
['cart_price_rules_floor', 3, 3]
96+
];
97+
98+
$this->fixtureModelMock
99+
->expects($this->exactly(2))
100+
->method('getValue')
101+
->will($this->returnValueMap($valueMap));
102+
$this->fixtureModelMock
103+
->expects($this->exactly(3))
104+
->method('getObjectManager')
105+
->will($this->returnValue($objectManagerMock));
106+
107+
$this->model->execute();
108+
}
109+
110+
public function testNoFixtureConfigValue()
111+
{
112+
$ruleMock = $this->getMock('\Magento\SalesRule\Model\Rule', [], [], '', false);
113+
$ruleMock->expects($this->never())->method('save');
114+
115+
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
116+
$objectManagerMock->expects($this->never())
117+
->method('get')
118+
->with($this->equalTo('Magento\SalesRule\Model\Rule'))
119+
->willReturn($ruleMock);
120+
121+
$this->fixtureModelMock
122+
->expects($this->never())
123+
->method('getObjectManager')
124+
->willReturn($objectManagerMock);
125+
$this->fixtureModelMock
126+
->expects($this->once())
127+
->method('getValue')
128+
->willReturn(false);
129+
130+
$this->model->execute();
131+
}
132+
133+
public function testGetActionTitle()
134+
{
135+
$this->assertSame('Generating shopping cart price rules', $this->model->getActionTitle());
136+
}
137+
138+
public function testIntroduceParamLabels()
139+
{
140+
$this->assertSame([
141+
'cart_price_rules' => 'Cart Price Rules'
142+
], $this->model->introduceParamLabels());
143+
}
144+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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\Fixtures;
8+
9+
use \Magento\Setup\Fixtures\CatalogPriceRulesFixture;
10+
11+
class CatalogPriceRulesFixtureTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Fixtures\FixtureModel
15+
*/
16+
private $fixtureModelMock;
17+
18+
/**
19+
* @var \Magento\Setup\Fixtures\CatalogPriceRulesFixture
20+
*/
21+
private $model;
22+
23+
public function setUp()
24+
{
25+
$this->fixtureModelMock = $this->getMock('\Magento\Setup\Fixtures\FixtureModel', [], [], '', false);
26+
27+
$this->model = new CatalogPriceRulesFixture($this->fixtureModelMock);
28+
}
29+
30+
public function testExecute()
31+
{
32+
$storeMock = $this->getMock('\Magento\Store\Model\Store', [], [], '', false);
33+
$storeMock->expects($this->once())
34+
->method('getRootCategoryId')
35+
->will($this->returnValue(2));
36+
37+
$websiteMock = $this->getMock('\Magento\Store\Model\Website', [], [], '', false);
38+
$websiteMock->expects($this->once())
39+
->method('getGroups')
40+
->will($this->returnValue([$storeMock]));
41+
$websiteMock->expects($this->once())
42+
->method('getId')
43+
->will($this->returnValue('website_id'));
44+
45+
$storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false);
46+
$storeManagerMock->expects($this->once())
47+
->method('getWebsites')
48+
->will($this->returnValue([$websiteMock]));
49+
50+
$contextMock = $this->getMock('\Magento\Framework\Model\Resource\Db\Context', [], [], '', false);
51+
$abstractDbMock = $this->getMockForAbstractClass(
52+
'\Magento\Framework\Model\Resource\Db\AbstractDb',
53+
[$contextMock],
54+
'',
55+
true,
56+
true,
57+
true,
58+
['getAllChildren']
59+
);
60+
$abstractDbMock->expects($this->once())
61+
->method('getAllChildren')
62+
->will($this->returnValue([1]));
63+
64+
$categoryMock = $this->getMock('Magento\Catalog\Model\Category', [], [], '', false);
65+
$categoryMock->expects($this->once())
66+
->method('getResource')
67+
->will($this->returnValue($abstractDbMock));
68+
$categoryMock->expects($this->once())
69+
->method('getPath')
70+
->will($this->returnValue('path/to/file'));
71+
$categoryMock->expects($this->once())
72+
->method('getId')
73+
->will($this->returnValue('category_id'));
74+
75+
$modelMock = $this->getMock('Magento\CatalogRule\Model\Rule', [], [], '', false);
76+
$modelMock->expects($this->once())
77+
->method('getIdFieldName')
78+
->will($this->returnValue('Field Id Name'));
79+
80+
$valueMap = [
81+
['Magento\CatalogRule\Model\Rule', $modelMock],
82+
['Magento\Catalog\Model\Category', $categoryMock]
83+
];
84+
85+
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
86+
$objectManagerMock->expects($this->once())
87+
->method('create')
88+
->will($this->returnValue($storeManagerMock));
89+
$objectManagerMock->expects($this->exactly(2))
90+
->method('get')
91+
->will($this->returnValueMap($valueMap));
92+
93+
$this->fixtureModelMock
94+
->expects($this->once())
95+
->method('getValue')
96+
->will($this->returnValue(1));
97+
$this->fixtureModelMock
98+
->expects($this->exactly(3))
99+
->method('getObjectManager')
100+
->will($this->returnValue($objectManagerMock));
101+
102+
$this->model->execute();
103+
}
104+
105+
public function testNoFixtureConfigValue()
106+
{
107+
$ruleMock = $this->getMock('\Magento\SalesRule\Model\Rule', [], [], '', false);
108+
$ruleMock->expects($this->never())->method('save');
109+
110+
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
111+
$objectManagerMock->expects($this->never())
112+
->method('get')
113+
->with($this->equalTo('Magento\SalesRule\Model\Rule'))
114+
->willReturn($ruleMock);
115+
116+
$this->fixtureModelMock
117+
->expects($this->never())
118+
->method('getObjectManager')
119+
->willReturn($objectManagerMock);
120+
$this->fixtureModelMock
121+
->expects($this->once())
122+
->method('getValue')
123+
->willReturn(false);
124+
125+
$this->model->execute();
126+
}
127+
128+
public function testGetActionTitle()
129+
{
130+
$this->assertSame('Generating catalog price rules', $this->model->getActionTitle());
131+
}
132+
133+
public function testIntroduceParamLabels()
134+
{
135+
$this->assertSame([
136+
'catalog_price_rules' => 'Catalog Price Rules'
137+
], $this->model->introduceParamLabels());
138+
}
139+
}

0 commit comments

Comments
 (0)