@@ -69,4 +69,64 @@ public function testGetDataWithMinMaxAndIncrements(): void
6969 $ result = $ this ->quantityValidator ->getData (self ::PRODUCT_ID , self ::WEBSITE_ID );
7070 $ this ->assertEquals ($ expected , $ result );
7171 }
72+
73+ public function testReturnsEmptyArrayForNonExistentProductOrWebsite (): void
74+ {
75+ $ this ->stockRegistry ->expects ($ this ->once ())
76+ ->method ('getStockItem ' )
77+ ->with (self ::PRODUCT_ID , self ::WEBSITE_ID )
78+ ->willReturn (null );
79+
80+ $ result = $ this ->quantityValidator ->getData (self ::PRODUCT_ID , self ::WEBSITE_ID );
81+ $ this ->assertSame ([], $ result , 'Should return empty array when StockItem is not found ' );
82+ }
83+
84+ public function testHandlesNullValuesFromStockItem (): void
85+ {
86+ $ stockItem = $ this ->createMock (StockItemInterface::class);
87+ $ stockItem ->method ('getMinSaleQty ' )
88+ ->willReturn (null );
89+ $ stockItem ->method ('getMaxSaleQty ' )
90+ ->willReturn (null );
91+ $ stockItem ->method ('getQtyIncrements ' )
92+ ->willReturn (null );
93+
94+ $ this ->stockRegistry ->expects ($ this ->once ())
95+ ->method ('getStockItem ' )
96+ ->with (self ::PRODUCT_ID , self ::WEBSITE_ID )
97+ ->willReturn ($ stockItem );
98+
99+ $ expected = [
100+ 'validate-item-quantity ' => [
101+ 'minAllowed ' => null
102+ ],
103+ ];
104+ $ result = $ this ->quantityValidator ->getData (self ::PRODUCT_ID , self ::WEBSITE_ID );
105+ $ this ->assertEquals ($ expected , $ result );
106+ }
107+
108+ public function testHandlesInvalidValuesFromStockItem (): void
109+ {
110+ $ stockItem = $ this ->createMock (StockItemInterface::class);
111+ $ stockItem ->method ('getMinSaleQty ' )
112+ ->willReturn ('not-a-number ' );
113+ $ stockItem ->method ('getMaxSaleQty ' )
114+ ->willReturn (-5 );
115+ $ stockItem ->method ('getQtyIncrements ' )
116+ ->willReturn (false );
117+
118+ $ this ->stockRegistry ->expects ($ this ->once ())
119+ ->method ('getStockItem ' )
120+ ->with (self ::PRODUCT_ID , self ::WEBSITE_ID )
121+ ->willReturn ($ stockItem );
122+
123+ $ expected = [
124+ 'validate-item-quantity ' => [
125+ 'minAllowed ' => 'not-a-number ' ,
126+ 'maxAllowed ' => -5
127+ ],
128+ ];
129+ $ result = $ this ->quantityValidator ->getData (self ::PRODUCT_ID , self ::WEBSITE_ID );
130+ $ this ->assertEquals ($ expected , $ result );
131+ }
72132}
0 commit comments