Skip to content

Commit efbeb89

Browse files
authored
Merge pull request #900 from magento-jackalopes/MAGETWO-58633-eav
[Jackalopes] Magetwo-58633 remove usages of attributecache from eav module
2 parents dc47c06 + 59f858a commit efbeb89

File tree

23 files changed

+1030
-514
lines changed

23 files changed

+1030
-514
lines changed

app/code/Magento/Catalog/Setup/UpgradeData.php

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use Magento\Catalog\Api\Data\ProductAttributeInterface;
99
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
10-
use Magento\Eav\Model\Entity\AttributeCache;
1110
use Magento\Framework\Setup\UpgradeDataInterface;
1211
use Magento\Framework\Setup\ModuleContextInterface;
1312
use Magento\Framework\Setup\ModuleDataSetupInterface;
@@ -35,26 +34,16 @@ class UpgradeData implements UpgradeDataInterface
3534
*/
3635
private $eavSetupFactory;
3736

38-
/**
39-
* @var AttributeCache
40-
*/
41-
private $attributeCache;
42-
4337
/**
4438
* Init
4539
*
4640
* @param CategorySetupFactory $categorySetupFactory
4741
* @param EavSetupFactory $eavSetupFactory
48-
* @param AttributeCache $attributeCache
4942
*/
50-
public function __construct(
51-
CategorySetupFactory $categorySetupFactory,
52-
EavSetupFactory $eavSetupFactory,
53-
AttributeCache $attributeCache
54-
) {
43+
public function __construct(CategorySetupFactory $categorySetupFactory, EavSetupFactory $eavSetupFactory)
44+
{
5545
$this->categorySetupFactory = $categorySetupFactory;
5646
$this->eavSetupFactory = $eavSetupFactory;
57-
$this->attributeCache = $attributeCache;
5847
}
5948

6049
/**
@@ -146,24 +135,19 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
146135
}
147136

148137
if (version_compare($context->getVersion(), '2.0.4') < 0) {
149-
$mediaBackendType = 'static';
150-
$mediaBackendModel = null;
151138
/** @var \Magento\Catalog\Setup\CategorySetup $categorySetup */
152139
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
153140
$categorySetup->updateAttribute(
154141
'catalog_product',
155142
'media_gallery',
156143
'backend_type',
157-
$mediaBackendType
144+
'static'
158145
);
159146
$categorySetup->updateAttribute(
160147
'catalog_product',
161148
'media_gallery',
162-
'backend_model',
163-
$mediaBackendModel
149+
'backend_model'
164150
);
165-
166-
$this->changeMediaGalleryAttributeInCache($mediaBackendType, $mediaBackendModel);
167151
}
168152

169153
if (version_compare($context->getVersion(), '2.0.5', '<')) {
@@ -397,25 +381,4 @@ private function changePriceAttributeDefaultScope($categorySetup)
397381

398382
}
399383
}
400-
401-
/**
402-
* @param string $mediaBackendType
403-
* @param string $mediaBackendModel
404-
* @return void
405-
*/
406-
private function changeMediaGalleryAttributeInCache($mediaBackendType, $mediaBackendModel)
407-
{
408-
// need to do, because media_gallery has backend model in cache.
409-
$catalogProductAttributes = $this->attributeCache->getAttributes('catalog_product', '0-0');
410-
411-
if (is_array($catalogProductAttributes)) {
412-
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $catalogProductAttribute */
413-
foreach ($catalogProductAttributes as $catalogProductAttribute) {
414-
if ($catalogProductAttribute->getAttributeCode() == 'media_gallery') {
415-
$catalogProductAttribute->setBackendModel($mediaBackendModel);
416-
$catalogProductAttribute->setBackendType($mediaBackendType);
417-
}
418-
}
419-
}
420-
}
421384
}

app/code/Magento/Catalog/Test/Unit/Model/Entity/AttributeTest.php

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
7-
// @codingStandardsIgnoreFile
8-
96
namespace Magento\Catalog\Test\Unit\Model\Entity;
107

118
use Magento\Catalog\Model\Entity\Attribute;
@@ -20,72 +17,72 @@ class AttributeTest extends \PHPUnit_Framework_TestCase
2017
/**
2118
* @var \Magento\Catalog\Model\Entity\Attribute
2219
*/
23-
protected $attribute;
20+
private $attribute;
2421

2522
/**
2623
* @var \Magento\Framework\Model\Context|\PHPUnit_Framework_MockObject_MockObject
2724
*/
28-
protected $contextMock;
25+
private $contextMock;
2926

3027
/**
3128
* @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject
3229
*/
33-
protected $registryMock;
30+
private $registryMock;
3431

3532
/**
3633
* @var \Magento\Framework\Api\MetadataServiceInterface|\PHPUnit_Framework_MockObject_MockObject
3734
*/
38-
protected $metadataServiceMock;
35+
private $metadataServiceMock;
3936

4037
/**
4138
* @var \Magento\Framework\Api\AttributeValueFactory|\PHPUnit_Framework_MockObject_MockObject
4239
*/
43-
protected $attributeValueFactoryMock;
40+
private $attributeValueFactoryMock;
4441

4542
/**
4643
* @var \Magento\Eav\Model\Config|\PHPUnit_Framework_MockObject_MockObject
4744
*/
48-
protected $configMock;
45+
private $configMock;
4946

5047
/**
5148
* @var \Magento\Eav\Model\Entity\TypeFactory|\PHPUnit_Framework_MockObject_MockObject
5249
*/
53-
protected $typeFactoryMock;
50+
private $typeFactoryMock;
5451

5552
/**
5653
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
5754
*/
58-
protected $storeManagerMock;
55+
private $storeManagerMock;
5956

6057
/**
6158
* @var \Magento\Eav\Model\ResourceModel\Helper|\PHPUnit_Framework_MockObject_MockObject
6259
*/
63-
protected $helperMock;
60+
private $helperMock;
6461

6562
/**
6663
* @var \Magento\Framework\Validator\UniversalFactory|\PHPUnit_Framework_MockObject_MockObject
6764
*/
68-
protected $universalFactoryMock;
65+
private $universalFactoryMock;
6966

7067
/**
7168
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
7269
*/
73-
protected $timezoneMock;
70+
private $timezoneMock;
7471

7572
/**
7673
* @var \Magento\Catalog\Model\Product\ReservedAttributeList|\PHPUnit_Framework_MockObject_MockObject
7774
*/
78-
protected $reservedAttributeListMock;
75+
private $reservedAttributeListMock;
7976

8077
/**
8178
* @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject
8279
*/
83-
protected $resolverMock;
80+
private $resolverMock;
8481

8582
/**
8683
* @var \Magento\Catalog\Model\Attribute\LockValidatorInterface|\PHPUnit_Framework_MockObject_MockObject
8784
*/
88-
protected $lockValidatorMock;
85+
private $lockValidatorMock;
8986

9087
/**
9188
* @var \Magento\Framework\Model\ResourceModel\AbstractResource|\PHPUnit_Framework_MockObject_MockObject
@@ -199,9 +196,6 @@ protected function setUp()
199196
->expects($this->any())
200197
->method('getEventDispatcher')
201198
->willReturn($this->eventDispatcher);
202-
$attributeCacheMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\AttributeCache::class)
203-
->disableOriginalConstructor()
204-
->getMock();
205199
$objectManagerHelper = new ObjectManagerHelper($this);
206200
$this->attribute = $objectManagerHelper->getObject(
207201
Attribute::class,
@@ -222,8 +216,7 @@ protected function setUp()
222216
'reservedAttributeList' => $this->reservedAttributeListMock,
223217
'resolver' => $this->resolverMock,
224218
'dateTimeFormatter' => $this->dateTimeFormatter,
225-
'resource' => $this->resourceMock,
226-
'attributeCache' => $attributeCacheMock
219+
'resource' => $this->resourceMock
227220
]
228221
);
229222
}

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Eav/AttributeTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,6 @@ protected function setUp()
113113
->method('getConnection')
114114
->will($this->returnValue($dbAdapterMock));
115115

116-
$attributeCacheMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\AttributeCache::class)
117-
->disableOriginalConstructor()
118-
->getMock();
119-
120116
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
121117
$this->_model = $objectManager->getObject(
122118
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class,
@@ -126,8 +122,7 @@ protected function setUp()
126122
'indexerEavProcessor' => $this->_eavProcessor,
127123
'resource' => $this->resourceMock,
128124
'data' => ['id' => 1],
129-
'eavConfig' => $this->eavConfigMock,
130-
'attributeCache' => $attributeCacheMock
125+
'eavConfig' => $this->eavConfigMock
131126
]
132127
);
133128
}

app/code/Magento/Customer/Test/Unit/Model/AttributeTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ class AttributeTest extends \PHPUnit_Framework_TestCase
125125
*/
126126
private $dateTimeFormatter;
127127

128-
/**
129-
* @var \PHPUnit_Framework_MockObject_MockObject
130-
*/
131-
private $attributeCacheMock;
132-
133128
/**
134129
* @var \Magento\Customer\Model\Metadata\AttributeMetadataCache|\PHPUnit_Framework_MockObject_MockObject
135130
*/
@@ -208,9 +203,6 @@ protected function setUp()
208203
$this->indexerRegistryMock = $this->getMockBuilder(\Magento\Framework\Indexer\IndexerRegistry::class)
209204
->disableOriginalConstructor()
210205
->getMock();
211-
$this->attributeCacheMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\AttributeCache::class)
212-
->disableOriginalConstructor()
213-
->getMock();
214206
$this->attributeMetadataCacheMock = $this->getMockBuilder(AttributeMetadataCache::class)
215207
->disableOriginalConstructor()
216208
->getMock();
@@ -235,7 +227,6 @@ protected function setUp()
235227
'dateTimeFormatter' => $this->dateTimeFormatter,
236228
'indexerRegistry' => $this->indexerRegistryMock,
237229
'resource' => $this->resourceMock,
238-
'attributeCache' => $this->attributeCacheMock,
239230
'attributeMetadataCache' => $this->attributeMetadataCacheMock
240231
]
241232
);

0 commit comments

Comments
 (0)