7
7
8
8
namespace Magento \ConfigurableProductGraphQl \Test \Unit \Model \Cart \BuyRequest ;
9
9
10
+ use Magento \Catalog \Api \Data \ProductInterface ;
10
11
use Magento \Catalog \Api \ProductRepositoryInterface ;
11
12
use Magento \Catalog \Model \Product ;
12
13
use Magento \CatalogInventory \Api \StockStateInterface ;
13
14
use Magento \ConfigurableProductGraphQl \Model \Cart \BuyRequest \SuperAttributeDataProvider ;
14
15
use Magento \ConfigurableProductGraphQl \Model \Options \Collection as OptionCollection ;
16
+ use Magento \Framework \EntityManager \EntityMetadataInterface ;
15
17
use Magento \Framework \EntityManager \MetadataPool ;
16
18
use Magento \Framework \Stdlib \ArrayManager ;
17
19
use Magento \Quote \Model \Quote ;
18
- use Magento \Store \Api \ Data \ StoreInterface ;
20
+ use Magento \Store \Model \ Store ;
19
21
use PHPUnit \Framework \MockObject \MockObject ;
20
22
use PHPUnit \Framework \TestCase ;
21
23
@@ -50,7 +52,7 @@ class SuperAttributeDataProviderTest extends TestCase
50
52
private $ stockState ;
51
53
52
54
/**
53
- * @var SuperAttributeDataProvider|MockObject
55
+ * @var SuperAttributeDataProvider
54
56
*/
55
57
private $ superAttributeDataProvider ;
56
58
@@ -59,22 +61,11 @@ class SuperAttributeDataProviderTest extends TestCase
59
61
*/
60
62
protected function setUp (): void
61
63
{
62
- $ this ->arrayManager = $ this ->getMockBuilder (ArrayManager::class)
63
- ->disableOriginalConstructor ()
64
- ->getMock ();
65
- $ this ->productRepository = $ this ->getMockBuilder (ProductRepositoryInterface::class)
66
- ->disableOriginalConstructor ()
67
- ->getMockForAbstractClass ();
64
+ $ this ->arrayManager = $ this ->createMock (ArrayManager::class);
65
+ $ this ->productRepository = $ this ->createMock (ProductRepositoryInterface::class);
68
66
$ this ->optionCollection = $ this ->createMock (OptionCollection::class);
69
- $ this ->metadataPool = $ this ->getMockBuilder (MetadataPool::class)
70
- ->disableOriginalConstructor ()
71
- ->onlyMethods (['getMetadata ' ])
72
- ->addMethods (['getLinkField ' ])
73
- ->getMock ();
74
- $ this ->stockState = $ this ->getMockBuilder (StockStateInterface::class)
75
- ->disableOriginalConstructor ()
76
- ->addMethods (['getHasError ' ])
77
- ->getMockForAbstractClass ();
67
+ $ this ->metadataPool = $ this ->createMock (MetadataPool::class);
68
+ $ this ->stockState = $ this ->createMock (StockStateInterface::class);
78
69
79
70
$ this ->superAttributeDataProvider = new SuperAttributeDataProvider (
80
71
$ this ->arrayManager ,
@@ -90,9 +81,7 @@ protected function setUp(): void
90
81
*/
91
82
public function testExecute (): void
92
83
{
93
- $ quoteMock = $ this ->getMockBuilder (Quote::class)
94
- ->disableOriginalConstructor ()
95
- ->getMock ();
84
+ $ quoteMock = $ this ->createMock (Quote::class);
96
85
$ cartItemData = [
97
86
'data ' => [
98
87
'quantity ' => 2.0 ,
@@ -116,19 +105,19 @@ public function testExecute(): void
116
105
$ quoteMock ,
117
106
);
118
107
119
- $ storeMock = $ this -> getMockBuilder (StoreInterface::class)
120
- -> disableOriginalConstructor ()
121
- -> addMethods ([ ' getWebsite ' ] )
122
- ->getMockForAbstractClass ();
123
- $ storeMock -> expects ( $ this -> once ())-> method ( ' getWebsiteId ' )-> willReturn (1 );
108
+ $ websiteId = 1 ;
109
+ $ storeMock = $ this -> createMock (Store::class);
110
+ $ storeMock -> expects ( $ this -> atLeastOnce () )
111
+ ->method ( ' getWebsiteId ' )
112
+ -> willReturn ($ websiteId );
124
113
$ storeMock ->expects ($ this ->never ())->method ('getWebsite ' );
125
114
$ quoteMock ->expects ($ this ->atLeastOnce ())
126
115
->method ('getStore ' )
127
116
->willReturn ($ storeMock );
128
117
129
118
$ productMock = $ this ->getMockBuilder (Product::class)
130
119
->disableOriginalConstructor ()
131
- ->onlyMethods (['getId ' , 'getExtensionAttributes ' , 'getData ' ])
120
+ ->onlyMethods (['getId ' , 'getExtensionAttributes ' , 'getData ' , ' getWebsiteIds ' ])
132
121
->addMethods (['getConfigurableProductLinks ' ])
133
122
->getMock ();
134
123
$ productMock ->method ('getId ' )
@@ -139,16 +128,20 @@ public function testExecute(): void
139
128
->willReturn ([1 ]);
140
129
$ productMock ->method ('getData ' )
141
130
->willReturn (1 );
131
+ $ productMock ->method ('getWebsiteIds ' )
132
+ ->willReturn ([$ websiteId ]);
142
133
$ this ->productRepository ->method ('get ' )
143
134
->willReturn ($ productMock );
135
+ $ checkResult = new \Magento \Framework \DataObject ();
136
+ $ checkResult ->setHasError (false );
144
137
$ this ->stockState ->method ('checkQuoteItemQty ' )
145
- ->willReturnSelf ();
146
- $ this ->stockState ->method ('getHasError ' )
147
- ->willReturn (false );
138
+ ->willReturn ($ checkResult );
139
+ $ productMetadata = $ this ->createMock (EntityMetadataInterface::class);
140
+ $ productMetadata ->method ('getLinkField ' )
141
+ ->willReturn ('entity_id ' );
148
142
$ this ->metadataPool ->method ('getMetadata ' )
149
- ->willReturnSelf ();
150
- $ this ->metadataPool ->method ('getLinkField ' )
151
- ->willReturnSelf ();
143
+ ->with (ProductInterface::class)
144
+ ->willReturn ($ productMetadata );
152
145
$ this ->optionCollection ->method ('getAttributesByProductId ' )
153
146
->willReturn ([
154
147
[
0 commit comments