16 class SetTest extends \PHPUnit\Framework\TestCase
56 private $serializerMock;
64 $this->resourceMock = $this->getMockBuilder(\
Magento\Framework\
App\ResourceConnection::class)
65 ->disableOriginalConstructor()
66 ->setMethods([
'getConnection',
'getTableName'])
68 $this->transactionManagerMock = $this->createMock(
71 $this->relationProcessor = $this->createMock(
75 $contextMock->expects($this->once())
76 ->method(
'getTransactionManager')
77 ->willReturn($this->transactionManagerMock);
78 $contextMock->expects($this->once())
79 ->method(
'getObjectRelationProcessor')
80 ->willReturn($this->relationProcessor);
81 $contextMock->expects($this->once())->method(
'getResources')->willReturn($this->resourceMock);
83 $this->eavConfigMock = $this->getMockBuilder(\
Magento\Eav\Model\Config::class)
84 ->setMethods([
'isCacheEnabled',
'getEntityType',
'getCache'])
85 ->disableOriginalConstructor()
88 $this->serializerMock = $this->createMock(Json::class);
90 $attributeGroupFactoryMock = $this->createMock(
97 'context' => $contextMock,
98 'attrGroupFactory' => $attributeGroupFactoryMock,
99 'eavConfig' => $this->eavConfigMock
103 $objectManager->setBackwardCompatibleProperty($this->model,
'serializer', $this->serializerMock);
105 $this->typeMock = $this->createMock(\
Magento\Eav\Model\Entity\Type::class);
106 $this->objectMock = $this->createPartialMock(\
Magento\Framework\Model\AbstractModel::class, [
125 $this->resourceMock->expects($this->any())
126 ->method(
'getConnection')
127 ->willReturn($this->createMock(\
Magento\Framework\DB\Adapter\AdapterInterface::class));
129 $this->transactionManagerMock->expects($this->once())
131 ->with($this->createMock(\
Magento\Framework\DB\Adapter\AdapterInterface::class))
132 ->willReturn($this->createMock(\
Magento\Framework\DB\Adapter\AdapterInterface::class));
134 $this->objectMock->expects($this->once())->method(
'getEntityTypeId')->willReturn(665);
135 $this->eavConfigMock->expects($this->once())->method(
'getEntityType')->with(665)->willReturn($this->typeMock);
136 $this->typeMock->expects($this->once())->method(
'getDefaultAttributeSetId')->willReturn(4);
137 $this->objectMock->expects($this->once())->method(
'getAttributeSetId')->willReturn(4);
139 $this->model->delete($this->objectMock);
149 $this->resourceMock->expects($this->any())
150 ->method(
'getConnection')
151 ->willReturn($this->createMock(\
Magento\Framework\DB\Adapter\AdapterInterface::class));
153 $this->transactionManagerMock->expects($this->once())
155 ->with($this->createMock(\
Magento\Framework\DB\Adapter\AdapterInterface::class))
156 ->willReturn($this->createMock(\
Magento\Framework\DB\Adapter\AdapterInterface::class));
158 $this->objectMock->expects($this->once())->method(
'getEntityTypeId')->willReturn(665);
159 $this->eavConfigMock->expects($this->once())->method(
'getEntityType')->with(665)->willReturn($this->typeMock);
160 $this->typeMock->expects($this->once())->method(
'getDefaultAttributeSetId')->willReturn(4);
161 $this->objectMock->expects($this->once())->method(
'getAttributeSetId')->willReturn(5);
162 $this->relationProcessor->expects($this->once())
164 ->willThrowException(
new \
Exception(
'test exception'));
166 $this->model->delete($this->objectMock);
174 $serializedData =
'serialized data';
190 $cacheMock = $this->getMockBuilder(\
Magento\Framework\
App\CacheInterface::class)
191 ->disableOriginalConstructor()
192 ->setMethods([
'load',
'save',
'getFrontend',
'remove',
'clean'])
196 ->expects($this->once())
200 $this->serializerMock->expects($this->once())
201 ->method(
'serialize')
203 ->willReturn($serializedData);
205 ->expects($this->once())
213 $this->eavConfigMock->expects($this->any())->method(
'isCacheEnabled')->willReturn(
true);
214 $this->eavConfigMock->expects($this->any())->method(
'getCache')->willReturn($cacheMock);
219 'attribute_group_id' => 10,
220 'group_sort_order' => 100,
221 'sort_order' => 1000,
222 'attribute_set_id' => 10000
226 $selectMock = $this->getMockBuilder(\
Magento\Framework\DB\Select::class)
227 ->disableOriginalConstructor()
228 ->setMethods([
'from',
'joinLeft',
'where'])
230 $selectMock->expects($this->once())->method(
'from')->will($this->returnSelf());
231 $selectMock->expects($this->once())->method(
'joinLeft')->will($this->returnSelf());
232 $selectMock->expects($this->atLeastOnce())->method(
'where')->will($this->returnSelf());
234 $connectionMock = $this->getMockBuilder(\
Magento\Framework\DB\Adapter\Pdo\Mysql::class)
235 ->disableOriginalConstructor()
236 ->setMethods([
'select',
'fetchAll'])
238 $connectionMock->expects($this->atLeastOnce())->method(
'select')->willReturn($selectMock);
239 $connectionMock->expects($this->atLeastOnce())->method(
'fetchAll')->willReturn($fetchResult);
241 $this->resourceMock->expects($this->any())->method(
'getConnection')->willReturn($connectionMock);
242 $this->resourceMock->expects($this->any())->method(
'getTableName')->willReturn(
'_TABLE_');
245 $this->model->getSetInfo([1, 2, 3], 1)
269 $serializedData =
'serialized data';
270 $this->resourceMock->expects($this->never())->method(
'getConnection');
271 $this->eavConfigMock->expects($this->any())->method(
'isCacheEnabled')->willReturn(
true);
272 $cacheMock = $this->getMockBuilder(\
Magento\Framework\
App\CacheInterface::class)
273 ->disableOriginalConstructor()
274 ->setMethods([
'load',
'save',
'getFrontend',
'remove',
'clean'])
276 $cacheMock->expects($this->once())
279 ->willReturn($serializedData);
280 $this->serializerMock->expects($this->once())
281 ->method(
'unserialize')
282 ->with($serializedData)
283 ->willReturn($cached);
285 $this->eavConfigMock->expects($this->any())->method(
'getCache')->willReturn($cacheMock);
289 $this->model->getSetInfo([1, 2, 3], 1)
testBeforeDeleteStateException()
testGetSetInfoCacheMiss()
const ATTRIBUTES_CACHE_ID