Skip to content

Commit fc68a8e

Browse files
author
Olexii Korshenko
committed
MAGETWO-34143: DB Foreign Keys Management on the Application Level. Builds Stabilization
- fixed unit tests
1 parent 6dc01ee commit fc68a8e

File tree

3 files changed

+24
-51
lines changed

3 files changed

+24
-51
lines changed

dev/tests/unit/testsuite/Magento/Indexer/Model/Resource/AbstractResourceTest.php

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,55 +17,20 @@ class AbstractResourceTest extends \PHPUnit_Framework_TestCase
1717
*/
1818
protected $_resourceMock;
1919

20-
/**
21-
* @var \Magento\Catalog\Model\CategoryFactory|\PHPUnit_Framework_MockObject_MockObject
22-
*/
23-
protected $_categoryFactoryMock;
24-
25-
/**
26-
* @var \Magento\Catalog\Model\Resource\Category\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
27-
*/
28-
protected $_categoryCollectionFactoryMock;
29-
30-
/**
31-
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
32-
*/
33-
protected $_storeManagerMock;
34-
35-
/**
36-
* @var \Magento\Catalog\Model\Config|\PHPUnit_Framework_MockObject_MockObject
37-
*/
38-
protected $_catalogConfigMock;
39-
40-
/**
41-
* @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
42-
*/
43-
protected $_eventManagerMock;
4420

4521
protected function setUp()
4622
{
4723
$this->_resourceMock = $this->getMockBuilder('Magento\Framework\App\Resource')
4824
->disableOriginalConstructor()
4925
->getMock();
50-
$this->_categoryFactoryMock = $this->getMockBuilder('Magento\Catalog\Model\CategoryFactory')
51-
->disableOriginalConstructor()
52-
->getMock();
53-
$this->_categoryCollectionFactoryMock = $this->getMockBuilder(
54-
'Magento\Catalog\Model\Resource\Category\CollectionFactory'
55-
)->disableOriginalConstructor()->getMock();
56-
$this->_storeManagerMock = $this->getMock('Magento\Store\Model\StoreManagerInterface');
57-
$this->_catalogConfigMock = $this->getMockBuilder('Magento\Catalog\Model\Config')
58-
->disableOriginalConstructor()
59-
->getMock();
60-
$this->_eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface');
61-
62-
$this->model = new \Magento\Indexer\Model\Resource\AbstractResourceStub(
63-
$this->_resourceMock,
64-
$this->_categoryFactoryMock,
65-
$this->_categoryCollectionFactoryMock,
66-
$this->_storeManagerMock,
67-
$this->_catalogConfigMock,
68-
$this->_eventManagerMock
26+
27+
$objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
28+
$arguments = $objectManager->getConstructArguments('\Magento\Indexer\Model\Resource\AbstractResourceStub',
29+
['resource' => $this->_resourceMock]
30+
);
31+
$this->model = $objectManager->getObject(
32+
'\Magento\Indexer\Model\Resource\AbstractResourceStub',
33+
$arguments
6934
);
7035
}
7136

@@ -86,9 +51,7 @@ public function testUseIdxTable()
8651
public function testClearTemporaryIndexTable()
8752
{
8853
$connectionMock = $this->getMock('Magento\Framework\DB\Adapter\AdapterInterface', [], [], '', false);
89-
$storeMock = $this->getMock('Magento\Store\Model\Store', [], [], '', false);
9054
$this->_resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
91-
$this->_storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
9255
$connectionMock->expects($this->once())->method('delete')->will($this->returnSelf());
9356
$this->model->clearTemporaryIndexTable();
9457
}
@@ -101,7 +64,6 @@ public function testSyncData()
10164

10265
$selectMock = $this->getMock('Magento\Framework\DB\Select', [], [], '', false);
10366
$connectionMock = $this->getMock('Magento\Framework\DB\Adapter\AdapterInterface', [], [], '', false);
104-
$storeMock = $this->getMock('Magento\Store\Model\Store', [], [], '', false);
10567

10668
$connectionMock->expects($this->any())->method('describeTable')->will($this->returnValue($describeTable));
10769
$connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock));
@@ -112,7 +74,6 @@ public function testSyncData()
11274
$resultColumns
11375
)->will($this->returnSelf());
11476

115-
$this->_storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
11677
$this->_resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
11778
$this->_resourceMock->expects($this->any())->method('getTableName')->will($this->returnArgument(0));
11879

@@ -147,13 +108,11 @@ public function testInsertFromTable($readToIndex)
147108

148109
$selectMock = $this->getMock('Magento\Framework\DB\Select', [], [], '', false);
149110
$connectionMock = $this->getMock('Magento\Framework\DB\Adapter\AdapterInterface', [], [], '', false);
150-
$storeMock = $this->getMock('Magento\Store\Model\Store', [], [], '', false);
151111

152112
$connectionMock->expects($this->any())->method('describeTable')->will($this->returnValue($tableColumns));
153113
$connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock));
154114
$selectMock->expects($this->any())->method('from')->will($this->returnSelf());
155115

156-
$this->_storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($storeMock));
157116
if ($readToIndex) {
158117
$connectionCustomMock = $this->getMock(
159118
'Magento\Framework\DB\Adapter\CustomAdapterInterface',

dev/tests/unit/testsuite/Magento/Indexer/Model/Resource/Indexer/StateTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ public function testConstruct()
2121
'',
2222
false
2323
);
24-
$this->model = new \Magento\Indexer\Model\Resource\Indexer\State($resourceMock);
24+
$objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
25+
$arguments = $objectManager->getConstructArguments('\Magento\Indexer\Model\Resource\Indexer\State',
26+
['resource' => $resourceMock]
27+
);
28+
$this->model = $objectManager->getObject(
29+
'\Magento\Indexer\Model\Resource\Indexer\State',
30+
$arguments
31+
);
2532
$this->assertEquals(
2633
[['field' => ['indexer_id'], 'title' => __('State for the same indexer')]],
2734
$this->model->getUniqueFields()

dev/tests/unit/testsuite/Magento/Indexer/Model/Resource/Mview/View/StateTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ public function testConstruct()
2121
'',
2222
false
2323
);
24-
$this->model = new \Magento\Indexer\Model\Resource\Mview\View\State($resourceMock);
24+
$objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
25+
$arguments = $objectManager->getConstructArguments('\Magento\Indexer\Model\Resource\Mview\View\State',
26+
['resource' => $resourceMock]
27+
);
28+
$this->model = $objectManager->getObject(
29+
'\Magento\Indexer\Model\Resource\Mview\View\State',
30+
$arguments
31+
);
2532
$this->assertEquals(
2633
[['field' => ['view_id'], 'title' => __('State for the same view')]],
2734
$this->model->getUniqueFields()

0 commit comments

Comments
 (0)