36 private $collectionProcessorMock;
40 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
42 $this->searchResultFactoryMock = $this->createPartialMock(
43 \
Magento\Sales\Api\
Data\CreditmemoSearchResultInterfaceFactory::class,
46 $this->collectionProcessorMock = $this->getMockBuilder(CollectionProcessorInterface::class)
51 'metadata' => $this->metadataMock,
52 'searchResultFactory' => $this->searchResultFactoryMock,
53 'collectionProcessor' => $this->collectionProcessorMock,
56 $this->type = $this->createPartialMock(\
Magento\Eav\Model\Entity\Type::class, [
'fetchNewIncrementId']);
63 ->disableOriginalConstructor()
70 ->method(
'getEntityId')
73 $this->metadataMock->expects($this->once())
74 ->method(
'getNewInstance')
77 $this->assertEquals(
$entity, $this->creditmemo->get(
$id));
79 $this->assertEquals(
$entity, $this->creditmemo->get(
$id));
88 $this->creditmemo->get(
null);
99 ->disableOriginalConstructor()
101 $entity->expects($this->once())
105 $entity->expects($this->once())
106 ->method(
'getEntityId')
109 $this->metadataMock->expects($this->once())
110 ->method(
'getNewInstance')
113 $this->assertNull(
$entity, $this->creditmemo->get(
$id));
119 ->disableOriginalConstructor()
121 $this->metadataMock->expects($this->once())
122 ->method(
'getNewInstance')
124 $this->assertEquals(
$entity, $this->creditmemo->create());
130 ->disableOriginalConstructor()
133 ->disableOriginalConstructor()
135 $this->collectionProcessorMock->expects($this->once())
138 $this->searchResultFactoryMock->expects($this->once())
148 ->disableOriginalConstructor()
150 $entity->expects($this->once())
151 ->method(
'getEntityId')
155 ->disableOriginalConstructor()
157 $mapper->expects($this->once())
161 $this->metadataMock->expects($this->any())
162 ->method(
'getMapper')
163 ->willReturn($mapper);
165 $this->assertTrue($this->creditmemo->delete(
$entity));
175 ->disableOriginalConstructor()
177 $entity->expects($this->never())
178 ->method(
'getEntityId');
181 ->disableOriginalConstructor()
183 $mapper->expects($this->once())
185 ->willThrowException(
new \Exception(
'error'));
187 $this->metadataMock->expects($this->any())
188 ->method(
'getMapper')
189 ->willReturn($mapper);
191 $this->creditmemo->delete(
$entity);
197 ->disableOriginalConstructor()
200 ->method(
'getEntityId')
204 ->disableOriginalConstructor()
206 $mapper->expects($this->once())
210 $this->metadataMock->expects($this->any())
211 ->method(
'getMapper')
212 ->willReturn($mapper);
224 ->disableOriginalConstructor()
226 $entity->expects($this->never())
227 ->method(
'getEntityId');
230 ->disableOriginalConstructor()
232 $mapper->expects($this->once())
234 ->willThrowException(
new \Exception(
'error'));
236 $this->metadataMock->expects($this->any())
237 ->method(
'getMapper')
238 ->willReturn($mapper);
testDeleteWithException()