Skip to content

Commit 0fb9964

Browse files
author
Olexii Korshenko
committed
MAGETWO-34143: DB Foreign Keys Management on the Application Level. Builds Stabilization
- fixed unit tests
1 parent 7c42442 commit 0fb9964

File tree

4 files changed

+47
-35
lines changed

4 files changed

+47
-35
lines changed

app/code/Magento/Eav/Model/Entity/Context.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Magento\Eav\Model\Entity;
88

9-
class Context
9+
class Context implements \Magento\Framework\ObjectManager\ContextInterface
1010
{
1111
/**
1212
* @var \Magento\Eav\Model\Config

dev/tests/unit/testsuite/Magento/Catalog/Model/Resource/AbstractTest.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
namespace Magento\Catalog\Model\Resource;
1111

12+
use Magento\TestFramework\Helper\ObjectManager;
13+
1214
class AbstractTest extends \PHPUnit_Framework_TestCase
1315
{
1416
/**
@@ -41,6 +43,8 @@ protected function _getAttributes()
4143

4244
public function testWalkAttributes()
4345
{
46+
$objectManager = new ObjectManager($this);
47+
4448
$code = 'test_attr';
4549
$set = 10;
4650

@@ -78,20 +82,11 @@ public function testWalkAttributes()
7882
$attributes[$code] = $attribute;
7983

8084
/** @var $model \Magento\Catalog\Model\Resource\AbstractResource */
85+
$arguments = $objectManager->getConstructArguments('Magento\Catalog\Model\Resource\AbstractResource');
8186
$model = $this->getMock(
8287
'Magento\Catalog\Model\Resource\AbstractResource',
8388
['getAttributesByCode'],
84-
[
85-
$this->getMock('Magento\Framework\App\Resource', [], [], '', false, false),
86-
$this->getMock('Magento\Eav\Model\Config', [], [], '', false, false),
87-
$this->getMock('Magento\Eav\Model\Entity\Attribute\Set', [], [], '', false, false),
88-
$this->getMock('Magento\Framework\Locale\FormatInterface'),
89-
$this->getMock('Magento\Eav\Model\Resource\Helper', [], [], '', false, false),
90-
$this->getMock('Magento\Framework\Validator\UniversalFactory', [], [], '', false, false),
91-
$this->getMock('Magento\Framework\Store\StoreManagerInterface', [], [], '', false),
92-
$this->getMock('Magento\Catalog\Model\Factory', [], [], '', false),
93-
[]
94-
]
89+
$arguments
9590
);
9691

9792
$model->expects($this->once())->method('getAttributesByCode')->will($this->returnValue($attributes));

dev/tests/unit/testsuite/Magento/Eav/Model/Entity/AbstractTest.php

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Eav\Model\Entity;
77

8+
use Magento\TestFramework\Helper\ObjectManager;
9+
810
class AbstractTest extends \PHPUnit_Framework_TestCase
911
{
1012
/**
@@ -18,17 +20,15 @@ class AbstractTest extends \PHPUnit_Framework_TestCase
1820

1921
protected function setUp()
2022
{
23+
$objectManager = new ObjectManager($this);
2124
$this->eavConfig = $this->getMock('Magento\Eav\Model\Config', [], [], '', false);
25+
$arguments = $objectManager->getConstructArguments(
26+
'Magento\Eav\Model\Entity\AbstractEntity',
27+
['eavConfig' => $this->eavConfig]
28+
);
2229
$this->_model = $this->getMockForAbstractClass(
2330
'Magento\Eav\Model\Entity\AbstractEntity',
24-
[
25-
$this->getMock('Magento\Framework\App\Resource', [], [], '', false),
26-
$this->eavConfig,
27-
$this->getMock('Magento\Eav\Model\Entity\Attribute\Set', [], [], '', false),
28-
$this->getMock('\Magento\Framework\Locale\FormatInterface'),
29-
$this->getMock('Magento\Eav\Model\Resource\Helper', [], [], '', false),
30-
$this->getMock('Magento\Framework\Validator\UniversalFactory', [], [], '', false)
31-
]
31+
$arguments
3232
);
3333
}
3434

@@ -272,18 +272,23 @@ public function testSave($attributeCode, $attributeSetId, $productData, $product
272272
->disableOriginalConstructor()
273273
->getMock();
274274

275-
$data = [
276-
$this->getMock('Magento\Framework\App\Resource', [], [], '', false),
277-
$eavConfig,
278-
$this->getMock('Magento\Eav\Model\Entity\Attribute\Set', [], [], '', false),
279-
$this->getMock('Magento\Framework\Locale\FormatInterface'),
280-
$this->getMock('Magento\Eav\Model\Resource\Helper', [], [], '', false),
281-
$this->getMock('Magento\Framework\Validator\UniversalFactory', [], [], '', false),
282-
['type' => $entityType, 'entityTable' => 'entityTable', 'attributesByCode' => $attributes],
283-
];
275+
$objectManager = new ObjectManager($this);
276+
$this->eavConfig = $this->getMock('Magento\Eav\Model\Config', [], [], '', false);
277+
$arguments = $objectManager->getConstructArguments(
278+
'Magento\Eav\Model\Entity\AbstractEntity',
279+
[
280+
'eavConfig' => $eavConfig,
281+
'data' => [
282+
'type' => $entityType,
283+
'entityTable' => 'entityTable',
284+
'attributesByCode' => $attributes
285+
]
286+
]
287+
);
288+
284289
/** @var $model \Magento\Framework\Model\AbstractModel|\PHPUnit_Framework_MockObject_MockObject */
285290
$model = $this->getMockBuilder('Magento\Eav\Model\Entity\AbstractEntity')
286-
->setConstructorArgs($data)
291+
->setConstructorArgs($arguments)
287292
->setMethods(['_getValue', 'beginTransaction', 'commit', 'rollback'])
288293
->getMock();
289294

dev/tests/unit/testsuite/Magento/Framework/App/Resource/ConfigTest.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,18 @@ protected function setUp()
6565
$this->returnValue(serialize($this->_resourcesConfig))
6666
);
6767

68+
$deploymentConfigMock = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false);
69+
$deploymentConfigMock->expects($this->once())
70+
->method('getSegment')
71+
->with('resource')
72+
->willReturn($this->_initialResources);
73+
6874
$this->_model = new \Magento\Framework\App\Resource\Config(
6975
$this->_readerMock,
7076
$this->_scopeMock,
7177
$this->_cacheMock,
72-
'cacheId',
73-
$this->_initialResources
78+
$deploymentConfigMock,
79+
'cacheId'
7480
);
7581
}
7682

@@ -89,12 +95,18 @@ public function testGetConnectionName($resourceName, $connectionName)
8995
*/
9096
public function testExceptionConstructor()
9197
{
98+
$deploymentConfigMock = $this->getMock('\Magento\Framework\App\DeploymentConfig', [], [], '', false);
99+
$deploymentConfigMock->expects($this->once())
100+
->method('getSegment')
101+
->with('resource')
102+
->willReturn(['validResource' => ['somekey' => 'validConnectionName']]);
103+
92104
new \Magento\Framework\App\Resource\Config(
93105
$this->_readerMock,
94106
$this->_scopeMock,
95107
$this->_cacheMock,
96-
'cacheId',
97-
['validResource' => ['somekey' => 'validConnectionName']]
108+
$deploymentConfigMock,
109+
'cacheId'
98110
);
99111
}
100112

@@ -110,7 +122,7 @@ public function getConnectionNameDataProvider()
110122
'resourceName' => 'brokenResourceName',
111123
'connectionName' => \Magento\Framework\App\Resource\Config::DEFAULT_SETUP_CONNECTION
112124
],
113-
['resourceName' => 'extendedResourceName', 'connectionName' => 'default'],
125+
['resourceName' => 'extendedResourceName', 'connectionName' => 'validConnectionName'],
114126
['resourceName' => 'validResource', 'connectionName' => 'validConnectionName']
115127
];
116128
}

0 commit comments

Comments
 (0)