@@ -58,6 +58,11 @@ class LastOrderedItemsTest extends \PHPUnit\Framework\TestCase
58
58
*/
59
59
private $ section ;
60
60
61
+ /**
62
+ * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
63
+ */
64
+ private $ loggerMock ;
65
+
61
66
protected function setUp ()
62
67
{
63
68
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
@@ -81,13 +86,16 @@ protected function setUp()
81
86
->getMock ();
82
87
$ this ->productRepository = $ this ->getMockBuilder (\Magento \Catalog \Api \ProductRepositoryInterface::class)
83
88
->getMockForAbstractClass ();
89
+ $ this ->loggerMock = $ this ->getMockBuilder (\Psr \Log \LoggerInterface::class)
90
+ ->getMockForAbstractClass ();
84
91
$ this ->section = new \Magento \Sales \CustomerData \LastOrderedItems (
85
92
$ this ->orderCollectionFactoryMock ,
86
93
$ this ->orderConfigMock ,
87
94
$ this ->customerSessionMock ,
88
95
$ this ->stockRegistryMock ,
89
96
$ this ->storeManagerMock ,
90
- $ this ->productRepository
97
+ $ this ->productRepository ,
98
+ $ this ->loggerMock
91
99
);
92
100
}
93
101
@@ -196,4 +204,34 @@ private function getLastOrderMock()
196
204
->willReturnSelf ();
197
205
return $ this ->orderMock ;
198
206
}
207
+
208
+ public function testGetSectionDataWithNotExistingProduct ()
209
+ {
210
+ $ storeId = 1 ;
211
+ $ websiteId = 4 ;
212
+ $ productId = 1 ;
213
+ $ exception = new \Magento \Framework \Exception \NoSuchEntityException (__ ("Product doesn't exist " ));
214
+ $ orderItemMock = $ this ->getMockBuilder (\Magento \Sales \Model \Order \Item::class)
215
+ ->disableOriginalConstructor ()
216
+ ->setMethods (['getProductId ' ])
217
+ ->getMock ();
218
+ $ storeMock = $ this ->getMockBuilder (\Magento \Store \Api \Data \StoreInterface::class)->getMockForAbstractClass ();
219
+
220
+ $ this ->getLastOrderMock ();
221
+ $ this ->storeManagerMock ->expects ($ this ->exactly (2 ))->method ('getStore ' )->willReturn ($ storeMock );
222
+ $ storeMock ->expects ($ this ->once ())->method ('getWebsiteId ' )->willReturn ($ websiteId );
223
+ $ storeMock ->expects ($ this ->once ())->method ('getId ' )->willReturn ($ storeId );
224
+ $ this ->orderMock ->expects ($ this ->once ())
225
+ ->method ('getParentItemsRandomCollection ' )
226
+ ->with (\Magento \Sales \CustomerData \LastOrderedItems::SIDEBAR_ORDER_LIMIT )
227
+ ->willReturn ([$ orderItemMock ]);
228
+ $ orderItemMock ->expects ($ this ->once ())->method ('getProductId ' )->willReturn ($ productId );
229
+ $ this ->productRepository ->expects ($ this ->once ())
230
+ ->method ('getById ' )
231
+ ->with ($ productId , false , $ storeId )
232
+ ->willThrowException ($ exception );
233
+ $ this ->loggerMock ->expects ($ this ->once ())->method ('critical ' )->with ($ exception );
234
+
235
+ $ this ->assertEquals (['items ' => []], $ this ->section ->getSectionData ());
236
+ }
199
237
}
0 commit comments