Skip to content

Commit 2c667a9

Browse files
author
Ian Daszkowski
committed
MAGETWO-38383: Increase Unit Test Code Coverage
- Added missing parameter type - Changed class variables to local variables - Fixed tests to properly test methods' actions
1 parent 6dda979 commit 2c667a9

13 files changed

+205
-23
lines changed

setup/src/Magento/Setup/Test/Unit/Fixtures/CartPriceRulesFixtureTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ public function testExecute()
109109

110110
public function testNoFixtureConfigValue()
111111
{
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);
112125
$this->fixtureModelMock
113126
->expects($this->once())
114127
->method('getValue')

setup/src/Magento/Setup/Test/Unit/Fixtures/CatalogPriceRulesFixtureTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ public function testExecute()
104104

105105
public function testNoFixtureConfigValue()
106106
{
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);
107120
$this->fixtureModelMock
108121
->expects($this->once())
109122
->method('getValue')

setup/src/Magento/Setup/Test/Unit/Fixtures/CategoriesFixtureTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ public function testExecute()
121121

122122
public function testNoFixtureConfigValue()
123123
{
124+
$categoryMock = $this->getMock('\Magento\Catalog\Model\Category', [], [], '', false);
125+
$categoryMock->expects($this->never())->method('save');
126+
127+
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
128+
$objectManagerMock->expects($this->never())
129+
->method('create')
130+
->with($this->equalTo('Magento\Catalog\Model\Category'))
131+
->willReturn($categoryMock);
132+
133+
$this->fixtureModelMock
134+
->expects($this->never())
135+
->method('getObjectManager')
136+
->willReturn($objectManagerMock);
124137
$this->fixtureModelMock
125138
->expects($this->once())
126139
->method('getValue')

setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigsApplyFixtureTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ public function testExecute()
5252

5353
public function testNoFixtureConfigValue()
5454
{
55+
$configMock = $this->getMock('\Magento\Framework\App\Config\ValueInterface', [], [], '', false);
56+
$configMock->expects($this->never())->method('save');
57+
58+
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
59+
$objectManagerMock->expects($this->never())
60+
->method('create')
61+
->willReturn($configMock);
62+
63+
$this->fixtureModelMock
64+
->expects($this->never())
65+
->method('getObjectManager')
66+
->will($this->returnValue($objectManagerMock));
5567
$this->fixtureModelMock
5668
->expects($this->once())
5769
->method('getValue')

setup/src/Magento/Setup/Test/Unit/Fixtures/ConfigurableProductsFixtureTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ public function testExecute()
108108

109109
public function testNoFixtureConfigValue()
110110
{
111+
$importMock = $this->getMock('\Magento\ImportExport\Model\Import', [], [], '', false);
112+
$importMock->expects($this->never())->method('validateSource');
113+
$importMock->expects($this->never())->method('importSource');
114+
115+
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
116+
$objectManagerMock->expects($this->never())
117+
->method('create')
118+
->with($this->equalTo('Magento\ImportExport\Model\Import'))
119+
->willReturn($importMock);
120+
121+
$this->fixtureModelMock
122+
->expects($this->never())
123+
->method('getObjectManager')
124+
->will($this->returnValue($objectManagerMock));
111125
$this->fixtureModelMock
112126
->expects($this->once())
113127
->method('getValue')

setup/src/Magento/Setup/Test/Unit/Fixtures/CustomersFixtureTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ public function testExecute()
7777

7878
public function testNoFixtureConfigValue()
7979
{
80+
$importMock = $this->getMock('\Magento\ImportExport\Model\Import', [], [], '', false);
81+
$importMock->expects($this->never())->method('validateSource');
82+
$importMock->expects($this->never())->method('importSource');
83+
84+
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
85+
$objectManagerMock->expects($this->never())
86+
->method('create')
87+
->with($this->equalTo('Magento\ImportExport\Model\Import'))
88+
->willReturn($importMock);
89+
90+
$this->fixtureModelMock
91+
->expects($this->never())
92+
->method('getObjectManager')
93+
->will($this->returnValue($objectManagerMock));
8094
$this->fixtureModelMock
8195
->expects($this->once())
8296
->method('getValue')

setup/src/Magento/Setup/Test/Unit/Fixtures/EavVariationsFixtureTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ public function testExecute()
9191

9292
public function testNoFixtureConfigValue()
9393
{
94+
$attributeMock = $this->getMock('Magento\Catalog\Model\Resource\Eav\Attribute', [], [], '', false);
95+
$attributeMock->expects($this->never())->method('save');
96+
97+
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
98+
$objectManagerMock->expects($this->never())
99+
->method('create')
100+
->with($this->equalTo('Magento\Catalog\Model\Resource\Eav\Attribute'))
101+
->willReturn($attributeMock);
102+
103+
$this->fixtureModelMock
104+
->expects($this->never())
105+
->method('getObjectManager')
106+
->will($this->returnValue($objectManagerMock));
94107
$this->fixtureModelMock
95108
->expects($this->once())
96109
->method('getValue')

setup/src/Magento/Setup/Test/Unit/Fixtures/FixtureModelTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function testGetValue()
8383
* The method is used in FixtureModel. loadConfig in an if statement. By overriding this method we are able to test
8484
* both of the possible cases based on the return value of is_readable.
8585
*
86-
* @param $filename
86+
* @param string $filename
8787
* @return bool
8888
*/
8989
function is_readable($filename)

setup/src/Magento/Setup/Test/Unit/Fixtures/IndexersStatesApplyFixtureTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ public function testExecute()
5252

5353
public function testNoFixtureConfigValue()
5454
{
55+
$cacheInterfaceMock = $this->getMock('Magento\Framework\App\CacheInterface', [], [], '', false);
56+
$cacheInterfaceMock->expects($this->never())->method('clean');
57+
58+
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
59+
$objectManagerMock->expects($this->never())
60+
->method('get')
61+
->willReturn($cacheInterfaceMock);
62+
63+
$this->fixtureModelMock
64+
->expects($this->never())
65+
->method('getObjectManager')
66+
->willReturn($objectManagerMock);
5567
$this->fixtureModelMock
5668
->expects($this->once())
5769
->method('getValue')

setup/src/Magento/Setup/Test/Unit/Fixtures/OrdersFixtureTest.php

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,6 @@
1010

1111
class OrdersFixtureTest extends \PHPUnit_Framework_TestCase
1212
{
13-
private $mockObjectNames = [
14-
'Magento\Quote\Model\Resource\Quote',
15-
'Magento\Quote\Model\Resource\Quote\Address',
16-
'Magento\Quote\Model\Resource\Quote\Item',
17-
'Magento\Quote\Model\Resource\Quote\Item\Option',
18-
'Magento\Quote\Model\Resource\Quote\Payment',
19-
'Magento\Quote\Model\Resource\Quote\Address\Rate',
20-
'Magento\Reports\Model\Resource\Event',
21-
'Magento\Sales\Model\Resource\Order',
22-
'Magento\Sales\Model\Resource\Order\Grid',
23-
'Magento\Sales\Model\Resource\Order\Item',
24-
'Magento\Sales\Model\Resource\Order\Payment',
25-
'Magento\Sales\Model\Resource\Order\Status\History',
26-
'\Magento\Eav\Model\Resource\Entity\Store'
27-
];
28-
29-
private $mockObjects;
3013

3114
/**
3215
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Fixtures\FixtureModel
@@ -51,7 +34,24 @@ public function setUp()
5134
*/
5235
public function testExecute()
5336
{
54-
foreach ($this->mockObjectNames as $mockObjectName) {
37+
$mockObjectNames = [
38+
'Magento\Quote\Model\Resource\Quote',
39+
'Magento\Quote\Model\Resource\Quote\Address',
40+
'Magento\Quote\Model\Resource\Quote\Item',
41+
'Magento\Quote\Model\Resource\Quote\Item\Option',
42+
'Magento\Quote\Model\Resource\Quote\Payment',
43+
'Magento\Quote\Model\Resource\Quote\Address\Rate',
44+
'Magento\Reports\Model\Resource\Event',
45+
'Magento\Sales\Model\Resource\Order',
46+
'Magento\Sales\Model\Resource\Order\Grid',
47+
'Magento\Sales\Model\Resource\Order\Item',
48+
'Magento\Sales\Model\Resource\Order\Payment',
49+
'Magento\Sales\Model\Resource\Order\Status\History',
50+
'\Magento\Eav\Model\Resource\Entity\Store'
51+
];
52+
$mockObjects = [];
53+
54+
foreach ($mockObjectNames as $mockObjectName) {
5555
$mockObject = $this->getMock($mockObjectName, [], [], '', false);
5656
$path = explode('\\', $mockObjectName);
5757
$name = array_pop($path);
@@ -64,7 +64,7 @@ public function testExecute()
6464
->method('getTable')
6565
->willReturn(strtolower($name) . '_table_name');
6666
}
67-
$this->mockObjects[] = [$mockObjectName, $mockObject];
67+
$mockObjects[] = [$mockObjectName, $mockObject];
6868
}
6969

7070
$adapterInterfaceMock = $this->getMockForAbstractClass(
@@ -182,7 +182,7 @@ public function testExecute()
182182
->willReturn([1, 1]);
183183

184184
array_push(
185-
$this->mockObjects,
185+
$mockObjects,
186186
['Magento\Store\Model\StoreManager', [], $storeManagerMock],
187187
['Magento\Catalog\Model\Category', $categoryMock],
188188
['Magento\Catalog\Model\Product', $productMock],
@@ -193,10 +193,10 @@ public function testExecute()
193193
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
194194
$objectManagerMock->expects($this->exactly(32))
195195
->method('get')
196-
->will($this->returnValueMap($this->mockObjects));
196+
->will($this->returnValueMap($mockObjects));
197197
$objectManagerMock->expects($this->exactly(2))
198198
->method('create')
199-
->will($this->returnValueMap($this->mockObjects));
199+
->will($this->returnValueMap($mockObjects));
200200

201201
$this->fixtureModelMock
202202
->expects($this->once())
@@ -212,6 +212,34 @@ public function testExecute()
212212

213213
public function testNoFixtureConfigValue()
214214
{
215+
$adapterInterfaceMock = $this->getMockForAbstractClass(
216+
'\Magento\Framework\DB\Adapter\AdapterInterface',
217+
[],
218+
'',
219+
true,
220+
true,
221+
true,
222+
[]
223+
);
224+
$adapterInterfaceMock->expects($this->never())
225+
->method('query');
226+
227+
$resourceMock = $this->getMock('Magento\Framework\App\Resource', [], [], '', false);
228+
$resourceMock->expects($this->never())
229+
->method('getConnection')
230+
->with($this->equalTo('write'))
231+
->willReturn($adapterInterfaceMock);
232+
233+
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManager\ObjectManager', [], [], '', false);
234+
$objectManagerMock->expects($this->never())
235+
->method('get')
236+
->with($this->equalTo('Magento\Framework\App\Resource'))
237+
->willReturn($resourceMock);
238+
239+
$this->fixtureModelMock
240+
->expects($this->never())
241+
->method('getObjectManagerMock')
242+
->willReturn($objectManagerMock);
215243
$this->fixtureModelMock
216244
->expects($this->once())
217245
->method('getValue')

0 commit comments

Comments
 (0)