51 private $serializerMock;
60 $this->cacheMock = $this->createMock(\
Magento\Framework\
App\CacheInterface::class);
61 $this->typeFactoryMock = $this->getMockBuilder(\
Magento\Eav\Model\Entity\TypeFactory::class)
62 ->setMethods([
'create'])
63 ->disableOriginalConstructor()
65 $this->collectionFactoryMock =
67 ->setMethods([
'create'])
68 ->disableOriginalConstructor()
70 $this->cacheStateMock = $this->createMock(\
Magento\Framework\
App\
Cache\StateInterface::class);
71 $this->universalFactoryMock = $this->getMockBuilder(\
Magento\Framework\
Validator\UniversalFactory::class)
72 ->setMethods([
'create'])
73 ->disableOriginalConstructor()
76 $this->serializerMock = $this->createMock(SerializerInterface::class);
78 $this->typeMock = $this->createMock(Type::class);
80 $this->config =
new Config(
82 $this->typeFactoryMock,
83 $this->collectionFactoryMock,
84 $this->cacheStateMock,
85 $this->universalFactoryMock,
93 'attribute_code' =>
'attribute_code_1',
96 $attributeCollectionMock = $this->getMockBuilder(
98 )->disableOriginalConstructor()
99 ->setMethods([
'getData',
'setEntityTypeFilter'])
101 $attributeCollectionMock->expects($this->any())
102 ->method(
'setEntityTypeFilter')
103 ->will($this->returnSelf());
104 $attributeCollectionMock->expects($this->any())
107 $entityAttributeMock = $this->getMockBuilder(Attribute::class)
108 ->setMethods([
'setData',
'loadByCode',
'toArray'])
109 ->disableOriginalConstructor()
111 $entityAttributeMock->expects($this->atLeastOnce())->method(
'setData')
113 $entityAttributeMock->expects($this->atLeastOnce())->method(
'loadByCode')
120 $attributeCollectionMock
130 'entity_type_id' =>
'entity_type_id',
131 'entity_type_code' =>
'entity_type_code' 133 $collectionStub =
new DataObject([$entityTypeData]);
134 $this->collectionFactoryMock
135 ->expects($this->any())
137 ->willReturn($collectionStub);
140 ->setMethods([
'getEntity',
'setData',
'getData',
'getEntityTypeCode',
'getId'])
141 ->disableOriginalConstructor()
144 ->willReturn(
'entity_type_code');
148 $this->typeFactoryMock
149 ->expects($this->any())
153 $this->universalFactoryMock
154 ->expects($this->atLeastOnce())
156 ->will($this->returnValueMap($factoryCalls));
158 $this->assertInstanceOf(Attribute::class, $this->config->getAttribute(
$entityType,
'attribute_code_1'));
167 'cache-disabled' => [
183 'attribute serialzied data',
199 'attribute_code' =>
'attribute_code_1',
202 $attributeCollectionMock = $this->getMockBuilder(
204 )->disableOriginalConstructor()
205 ->setMethods([
'getData',
'setEntityTypeFilter'])
207 $attributeCollectionMock
208 ->expects($this->any())
209 ->method(
'setEntityTypeFilter')
210 ->will($this->returnSelf());
211 $attributeCollectionMock
212 ->expects($this->any())
215 $entityAttributeMock = $this->getMockBuilder(Attribute::class)
216 ->setMethods([
'setData',
'load',
'toArray'])
217 ->disableOriginalConstructor()
219 $entityAttributeMock->method(
'setData')
221 $entityAttributeMock->method(
'load')
223 $entityAttributeMock->method(
'toArray')
229 $attributeCollectionMock
238 $this->cacheStateMock
239 ->expects($this->atLeastOnce())
240 ->method(
'isEnabled')
241 ->with(Cache::TYPE_IDENTIFIER)
242 ->willReturn($cacheEnabled);
245 'entity_type_id' =>
'entity_type_id',
246 'entity_type_code' =>
'entity_type_code' 248 $collectionStub =
new DataObject([$entityTypeData]);
249 $this->collectionFactoryMock
250 ->expects($this->any())
252 ->willReturn($collectionStub);
255 ->setMethods([
'getEntity',
'setData',
'getData',
'getEntityTypeCode',
'getId'])
256 ->disableOriginalConstructor()
259 ->willReturn(
'entity_type_code');
263 $this->typeFactoryMock
264 ->expects($this->any())
268 $this->universalFactoryMock
269 ->expects($this->atLeastOnce())
271 ->will($this->returnValueMap($factoryCalls));
273 $this->assertEquals([
'attribute_code_1' => $entityAttributeMock], $this->config->getAttributes(
$entityType));
278 $this->cacheMock->expects($this->once())
288 $this->config->clear();
295 $this->config->getEntityType($this->typeMock)
304 'entity_type_id' => 1
307 $serializedData =
'serialized data';
308 $this->cacheStateMock->expects($this->once())
309 ->method(
'isEnabled')
310 ->with(Cache::TYPE_IDENTIFIER)
312 $this->cacheMock->expects($this->once())
315 ->willReturn($serializedData);
316 $this->serializerMock->expects($this->once())
317 ->method(
'unserialize')
318 ->with($serializedData)
320 $this->typeMock->expects($this->exactly(2))
323 $this->typeMock->expects($this->once())
324 ->method(
'getEntityTypeCode')
326 $this->typeFactoryMock->expects($this->once())
329 ->willReturn($this->typeMock);
330 $this->assertInstanceOf(
341 'entity_type_id' => 1,
347 'entity_type_id' => 1,
349 'attribute_model' => Attribute::class
352 $serializedData =
'serialized data';
353 $this->cacheStateMock->expects($this->once())
354 ->method(
'isEnabled')
355 ->with(Cache::TYPE_IDENTIFIER)
357 $this->cacheMock->expects($this->once())
361 $this->serializerMock->expects($this->never())
362 ->method(
'unserialize');
363 $attributeCollectionMock = $this->createMock(Collection::class);
364 $this->collectionFactoryMock->expects($this->once())
366 ->willReturn($attributeCollectionMock);
367 $attributeCollectionMock->expects($this->once())
369 ->willReturn($collectionData);
370 $this->serializerMock->expects($this->once())
371 ->method(
'serialize')
373 ->willReturn($serializedData);
374 $this->cacheMock->expects($this->once())
384 $this->typeMock->expects($this->exactly(2))
387 $this->typeMock->expects($this->once())
388 ->method(
'getEntityTypeCode')
390 $this->typeFactoryMock->expects($this->once())
393 ->willReturn($this->typeMock);
394 $this->assertInstanceOf(
testGetEntityTypeCacheExists()
getAttributeCacheDataProvider()
testGetEntityTypeInstanceOfTypePassed()
testGetAttributes($cacheEnabled)
testGetEntityTypeCacheDoesNotExist()