Skip to content

Commit e26f6ae

Browse files
author
Igor Melnikov
committed
MAGETWO-64224: Remove usages of AttributeCache from customer module
- updating unit tests
1 parent d352973 commit e26f6ae

File tree

2 files changed

+17
-83
lines changed

2 files changed

+17
-83
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ protected function setUp()
236236
'indexerRegistry' => $this->indexerRegistryMock,
237237
'resource' => $this->resourceMock,
238238
'attributeCache' => $this->attributeCacheMock,
239-
'attributeMetadataCache' => $this->attributeMetadataCacheMock,
239+
'attributeMetadataCache' => $this->attributeMetadataCacheMock
240240
]
241241
);
242242
}
@@ -248,7 +248,7 @@ public function testAfterSaveEavCache()
248248
->method('clear');
249249
$this->attributeMetadataCacheMock
250250
->expects($this->once())
251-
->method('clear');
251+
->method('clean');
252252
$this->attribute->afterSave();
253253
}
254254

@@ -259,7 +259,7 @@ public function testAfterDeleteEavCache()
259259
->method('clear');
260260
$this->attributeMetadataCacheMock
261261
->expects($this->once())
262-
->method('clear');
262+
->method('clean');
263263
$this->attribute->afterDelete();
264264
}
265265

app/code/Magento/Customer/Test/Unit/Model/Metadata/AttributeMetadataCacheTest.php

Lines changed: 14 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,17 @@
55
*/
66
namespace Magento\Customer\Test\Unit\Model\Metadata;
77

8-
use Magento\Customer\Model\Metadata\AttributeMetadataHydrator;
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
99
use Magento\Framework\App\CacheInterface;
1010
use Magento\Framework\App\Cache\StateInterface;
1111
use Magento\Customer\Api\Data\AttributeMetadataInterface;
1212
use Magento\Framework\Serialize\SerializerInterface;
1313
use Magento\Eav\Model\Cache\Type;
1414
use Magento\Eav\Model\Entity\Attribute;
1515
use Magento\Config\App\Config\Type\System;
16-
use Magento\Customer\Model\Data\AttributeMetadata;
17-
use Magento\Customer\Model\Data\Option;
18-
use Magento\Customer\Model\Data\ValidationRule;
16+
use Magento\Customer\Model\Metadata\AttributeMetadataHydrator;
1917
use Magento\Customer\Model\Metadata\AttributeMetadataCache;
20-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
2118

22-
/**
23-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24-
*/
2519
class AttributeMetadataCacheTest extends \PHPUnit_Framework_TestCase
2620
{
2721
/**
@@ -34,11 +28,6 @@ class AttributeMetadataCacheTest extends \PHPUnit_Framework_TestCase
3428
*/
3529
private $stateMock;
3630

37-
/**
38-
* @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject
39-
*/
40-
private $attributeMetadataMock;
41-
4231
/**
4332
* @var AttributeMetadataHydrator|\PHPUnit_Framework_MockObject_MockObject
4433
*/
@@ -60,7 +49,6 @@ protected function setUp()
6049
$this->cacheMock = $this->getMock(CacheInterface::class);
6150
$this->stateMock = $this->getMock(StateInterface::class);
6251
$this->serializerMock = $this->getMock(SerializerInterface::class);
63-
$this->attributeMetadataMock = $this->getMock(AttributeMetadataInterface::class);
6452
$this->attributeMetadataHydratorMock = $this->getMock(
6553
AttributeMetadataHydrator::class,
6654
[],
@@ -113,31 +101,9 @@ public function testLoad()
113101
$suffix = 'none';
114102
$cacheKey = AttributeMetadataCache::ATTRIBUTE_METADATA_CACHE_PREFIX . $entityType . $suffix;
115103
$serializedString = 'serialized string';
116-
$optionOneData = [
117-
'label' => 'Label 1',
118-
'options' => null
119-
];
120-
$optionThreeData = [
121-
'label' => 'Label 3',
122-
'options' => null
123-
];
124-
$optionFourData = [
125-
'label' => 'Label 4',
126-
'options' => null
127-
];
128-
$optionTwoData = [
129-
'label' => 'Label 2',
130-
'options' => [$optionThreeData, $optionFourData]
131-
];
132-
$validationRuleOneData = [
133-
'name' => 'Name 1',
134-
'value' => 'Value 1'
135-
];
136104
$attributeMetadataOneData = [
137105
'attribute_code' => 'attribute_code',
138106
'frontend_input' => 'hidden',
139-
'options' => [$optionOneData, $optionTwoData],
140-
'validation_rules' => [$validationRuleOneData]
141107
];
142108
$attributesMetadataData = [$attributeMetadataOneData];
143109
$this->stateMock->expects($this->once())
@@ -152,49 +118,15 @@ public function testLoad()
152118
->method('unserialize')
153119
->with($serializedString)
154120
->willReturn($attributesMetadataData);
155-
156-
$optionTwoDataPartiallyConverted = [
157-
'label' => 'Label 2',
158-
'options' => [
159-
new Option($optionThreeData),
160-
new Option($optionFourData)
161-
]
162-
];
163-
164-
$validationRule = new ValidationRule($validationRuleOneData);
165-
166-
$attributeMetadataDataPartiallyConverted = [
167-
'attribute_code' => 'attribute_code',
168-
'frontend_input' => 'hidden',
169-
'options' => [
170-
new Option($optionOneData),
171-
new Option($optionTwoDataPartiallyConverted)
172-
],
173-
'validation_rules' => [$validationRule]
174-
];
175-
176-
$this->attributeMetadataHydratorMock->expects($this->once())
121+
/** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $attributeMetadataMock */
122+
$attributeMetadataMock = $this->getMock(AttributeMetadataInterface::class);
123+
$this->attributeMetadataHydratorMock->expects($this->at(0))
177124
->method('hydrate')
178125
->with($attributeMetadataOneData)
179-
->willReturn(new AttributeMetadata($attributeMetadataDataPartiallyConverted));
180-
181-
$attributeMetadata = $this->attributeMetadataCache->load($entityType, $suffix);
182-
183-
$this->assertEquals(
184-
$attributeMetadataOneData['attribute_code'],
185-
$attributeMetadata[0]->getAttributeCode()
186-
);
187-
$this->assertEquals(
188-
$optionOneData['label'],
189-
$attributeMetadata[0]->getOptions()[0]->getLabel()
190-
);
191-
$this->assertEquals(
192-
$optionThreeData['label'],
193-
$attributeMetadata[0]->getOptions()[1]->getOptions()[0]->getLabel()
194-
);
195-
$this->assertEquals(
196-
$validationRuleOneData['name'],
197-
$attributeMetadata[0]->getValidationRules()[0]->getName()
126+
->willReturn($attributeMetadataMock);
127+
$this->assertInstanceOf(
128+
AttributeMetadataInterface::class,
129+
$this->attributeMetadataCache->load($entityType, $suffix)[0]
198130
);
199131
}
200132

@@ -228,10 +160,13 @@ public function testSave()
228160
->method('isEnabled')
229161
->with(Type::TYPE_IDENTIFIER)
230162
->willReturn(true);
231-
$this->attributeMetadataMock = $this->getMock(AttributeMetadataInterface::class);
163+
164+
/** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $attributeMetadataMock */
165+
$attributeMetadataMock = $this->getMock(AttributeMetadataInterface::class);
166+
$attributesMetadata = [$attributeMetadataMock];
232167
$this->attributeMetadataHydratorMock->expects($this->once())
233168
->method('extract')
234-
->with($this->attributeMetadataMock)
169+
->with($attributeMetadataMock)
235170
->willReturn($attributeMetadataOneData);
236171
$this->serializerMock->expects($this->once())
237172
->method('serialize')
@@ -248,7 +183,6 @@ public function testSave()
248183
System::CACHE_TAG
249184
]
250185
);
251-
$attributesMetadata = [$this->attributeMetadataMock];
252186
$this->attributeMetadataCache->save($entityType, $attributesMetadata, $suffix);
253187
$this->assertSame(
254188
$attributesMetadata,

0 commit comments

Comments
 (0)