34 private $attributeMetadataHydratorMock;
39 private $serializerMock;
44 private $attributeMetadataCache;
49 $this->cacheMock = $this->createMock(CacheInterface::class);
50 $this->stateMock = $this->createMock(StateInterface::class);
51 $this->serializerMock = $this->createMock(SerializerInterface::class);
52 $this->attributeMetadataHydratorMock = $this->createMock(AttributeMetadataHydrator::class);
54 AttributeMetadataCache::class,
56 'cache' => $this->cacheMock,
57 'state' => $this->stateMock,
58 'serializer' => $this->serializerMock,
59 'attributeMetadataHydrator' => $this->attributeMetadataHydratorMock
68 $this->stateMock->expects($this->once())
72 $this->cacheMock->expects($this->never())
84 $this->stateMock->expects($this->once())
88 $this->cacheMock->expects($this->once())
95 public function testLoad()
100 $serializedString =
'serialized string';
101 $attributeMetadataOneData = [
102 'attribute_code' =>
'attribute_code',
103 'frontend_input' =>
'hidden',
105 $attributesMetadataData = [$attributeMetadataOneData];
106 $this->stateMock->expects($this->once())
107 ->method(
'isEnabled')
110 $this->cacheMock->expects($this->once())
113 ->willReturn($serializedString);
114 $this->serializerMock->expects($this->once())
115 ->method(
'unserialize')
116 ->with($serializedString)
117 ->willReturn($attributesMetadataData);
119 $attributeMetadataMock = $this->createMock(AttributeMetadataInterface::class);
120 $this->attributeMetadataHydratorMock->expects($this->at(0))
122 ->with($attributeMetadataOneData)
123 ->willReturn($attributeMetadataMock);
125 $this->assertInternalType(
126 \PHPUnit\Framework\Constraint\IsType::TYPE_ARRAY,
129 $this->assertArrayHasKey(
133 $this->assertInstanceOf(
134 AttributeMetadataInterface::class,
135 $attributesMetadata[0]
144 $this->stateMock->expects($this->once())
145 ->method(
'isEnabled')
155 public function testSave()
160 $serializedString =
'serialized string';
161 $attributeMetadataOneData = [
162 'attribute_code' =>
'attribute_code',
163 'frontend_input' =>
'hidden',
165 $this->stateMock->expects($this->once())
166 ->method(
'isEnabled')
171 $attributeMetadataMock = $this->createMock(AttributeMetadataInterface::class);
172 $attributesMetadata = [$attributeMetadataMock];
173 $this->attributeMetadataHydratorMock->expects($this->once())
175 ->with($attributeMetadataMock)
176 ->willReturn($attributeMetadataOneData);
177 $this->serializerMock->expects($this->once())
178 ->method(
'serialize')
179 ->with([$attributeMetadataOneData])
180 ->willReturn($serializedString);
181 $this->cacheMock->expects($this->once())
201 $this->stateMock->expects($this->once())
202 ->method(
'isEnabled')
205 $this->cacheMock->expects($this->never())
207 $this->attributeMetadataCache->clean();
212 $this->stateMock->expects($this->once())
213 ->method(
'isEnabled')
216 $this->cacheMock->expects($this->once())
218 $this->attributeMetadataCache->clean();