24 private $metadataPoolMock;
29 private $typeResolverMock;
34 private $sequenceManagerMock;
39 private $sequenceRegistryMock;
44 private $hydratorPoolMock;
54 private $hydratorMock;
59 private $metadataMock;
64 private $sequenceMock;
69 private $sequenceApplier;
73 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
75 $this->metadataPoolMock = $this->getMockBuilder(MetadataPool::class)
76 ->disableOriginalConstructor()
78 $this->typeResolverMock = $this->getMockBuilder(TypeResolver::class)
79 ->disableOriginalConstructor()
81 $this->sequenceManagerMock = $this->getMockBuilder(SequenceManager::class)
82 ->disableOriginalConstructor()
84 $this->sequenceRegistryMock = $this->getMockBuilder(SequenceRegistry::class)
85 ->disableOriginalConstructor()
87 $this->hydratorPoolMock = $this->getMockBuilder(HydratorPool::class)
88 ->disableOriginalConstructor()
90 $this->entityMock = $this->getMockBuilder(DataObject::class)
91 ->disableOriginalConstructor()
93 $this->hydratorMock = $this->getMockBuilder(HydratorInterface::class)
94 ->disableOriginalConstructor()
96 $this->metadataMock = $this->getMockBuilder(EntityMetadataInterface::class)
97 ->disableOriginalConstructor()
99 $this->sequenceMock = $this->getMockBuilder(SequenceInterface::class)
100 ->disableOriginalConstructor()
103 $this->sequenceApplier =
$helper->getObject(
104 SequenceApplier::class,
106 'metadataPool' => $this->metadataPoolMock,
107 'typeResolver' => $this->typeResolverMock,
108 'sequenceManager' => $this->sequenceManagerMock,
109 'sequenceRegistry' => $this->sequenceRegistryMock,
110 'hydratorPool' => $this->hydratorPoolMock
118 $this->typeResolverMock->expects($this->once())
120 ->with($this->entityMock)
122 $this->sequenceRegistryMock->expects($this->once())->method(
'retrieve')->with(
$entityType)->willReturn(
null);
123 $this->assertEquals($this->entityMock, $this->sequenceApplier->apply($this->entityMock));
129 $identifierField =
'identifier_field';
130 $entityData = [$identifierField =>
'data'];
131 $sequenceInfo = [
'sequence' => $this->sequenceMock];
132 $this->typeResolverMock->expects($this->once())
134 ->with($this->entityMock)
136 $this->sequenceRegistryMock->expects($this->once())
139 ->willReturn($sequenceInfo);
140 $this->metadataPoolMock->expects($this->any())
141 ->method(
'getMetadata')
143 ->willReturn($this->metadataMock);
144 $this->hydratorPoolMock->expects($this->once())
145 ->method(
'getHydrator')
147 ->willReturn($this->hydratorMock);
148 $this->hydratorMock->expects($this->once())
150 ->with($this->entityMock)
151 ->willReturn($entityData);
152 $this->metadataMock->expects($this->any())->method(
'getIdentifierField')->willReturn($identifierField);
153 $this->sequenceManagerMock->expects($this->once())
157 $entityData[$identifierField]
160 $this->assertEquals($this->entityMock, $this->sequenceApplier->apply($this->entityMock));
166 $identifierField =
'identifier_field';
167 $identifierFieldEmptyValue =
'';
168 $entityData = [$identifierField => $identifierFieldEmptyValue];
169 $sequenceInfo = [
'sequence' => $this->sequenceMock];
170 $this->typeResolverMock->expects($this->once())
172 ->with($this->entityMock)
174 $this->sequenceRegistryMock->expects($this->once())
177 ->willReturn($sequenceInfo);
178 $this->metadataPoolMock->expects($this->any())
179 ->method(
'getMetadata')
181 ->willReturn($this->metadataMock);
182 $this->hydratorPoolMock->expects($this->once())
183 ->method(
'getHydrator')
185 ->willReturn($this->hydratorMock);
186 $this->hydratorMock->expects($this->once())
188 ->with($this->entityMock)
189 ->willReturn($entityData);
190 $this->metadataMock->expects($this->any())
191 ->method(
'getIdentifierField')
192 ->willReturn($identifierFieldEmptyValue);
193 $nextValue =
'next_value_data';
194 $this->sequenceMock->expects($this->once())->method(
'getNextValue')->willReturn($nextValue);
195 $entityData[
''] = $nextValue;
196 $this->hydratorMock->expects($this->once())
198 ->with($this->entityMock, $entityData)
199 ->willReturn($this->entityMock);
201 $this->assertEquals($this->entityMock, $this->sequenceApplier->apply($this->entityMock));
testApplySequenceIsNull()
testApplyEntityDoesNotHaveIdentifier()
testApplyEntityHasIdentifier()