9
9
10
10
use Magento \Catalog \Api \ProductRepositoryInterface ;
11
11
use Magento \GraphQl \App \State \GraphQlStateDiff ;
12
+ use Magento \Quote \Test \Fixture \GuestCart as GuestCartFixture ;
13
+ use Magento \TestFramework \Fixture \DataFixture ;
14
+ use Magento \TestFramework \Fixture \DataFixtureStorage ;
15
+ use Magento \TestFramework \Fixture \DataFixtureStorageManager ;
12
16
13
17
/**
14
18
* Tests the dispatch method in the GraphQl Controller class using a simple product query
@@ -25,12 +29,18 @@ class GraphQlCheckoutMutationsStateTest extends \PHPUnit\Framework\TestCase
25
29
*/
26
30
private ?GraphQlStateDiff $ graphQlStateDiff = null ;
27
31
32
+ /**
33
+ * @var DataFixtureStorage
34
+ */
35
+ private DataFixtureStorage $ fixtures ;
36
+
28
37
/**
29
38
* @inheritDoc
30
39
*/
31
40
protected function setUp (): void
32
41
{
33
42
$ this ->graphQlStateDiff = new GraphQlStateDiff ();
43
+ $ this ->fixtures = Bootstrap::getObjectManager ()->get (DataFixtureStorageManager::class)->getStorage ();
34
44
parent ::setUp ();
35
45
}
36
46
@@ -61,14 +71,17 @@ public function testCreateEmptyCart() : void
61
71
}
62
72
63
73
/**
64
- * @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_two_empty_carts.php
65
74
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
66
75
* @return void
67
76
*/
68
- public function testAddSimpleProductToCart ()
77
+ #[
78
+ DataFixture(GuestCartFixture::class, as: 'cart1 ' ),
79
+ DataFixture(GuestCartFixture::class, as: 'cart2 ' ),
80
+ ]
81
+ public function testAddSimpleProductToCart (): void
69
82
{
70
- $ cartId1 = $ this ->graphQlStateDiff -> getCartIdHash ( ' test_quote1 ' );
71
- $ cartId2 = $ this ->graphQlStateDiff -> getCartIdHash ( ' test_quote2 ' );
83
+ $ cartId1 = $ this ->fixtures -> get ( ' cart1 ' )-> getId ( );
84
+ $ cartId2 = $ this ->fixtures -> get ( ' cart2 ' )-> getId ( );
72
85
$ query = $ this ->getAddProductToCartQuery ();
73
86
$ this ->graphQlStateDiff ->testState (
74
87
$ query ,
@@ -105,14 +118,17 @@ public function testAddCouponToCart()
105
118
}
106
119
107
120
/**
108
- * @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_two_empty_carts.php
109
121
* @magentoDataFixture Magento/GraphQl/Catalog/_files/virtual_product.php
110
122
* @return void
111
123
*/
124
+ #[
125
+ DataFixture(GuestCartFixture::class, as: 'cart1 ' ),
126
+ DataFixture(GuestCartFixture::class, as: 'cart2 ' ),
127
+ ]
112
128
public function testAddVirtualProductToCart ()
113
129
{
114
- $ cartId1 = $ this ->graphQlStateDiff -> getCartIdHash ( ' test_quote1 ' );
115
- $ cartId2 = $ this ->graphQlStateDiff -> getCartIdHash ( ' test_quote2 ' );
130
+ $ cartId1 = $ this ->fixtures -> get ( ' cart1 ' )-> getId ( );
131
+ $ cartId2 = $ this ->fixtures -> get ( ' cart2 ' )-> getId ( );
116
132
$ query = $ this ->getAddVirtualProductToCartQuery ();
117
133
$ this ->graphQlStateDiff ->testState (
118
134
$ query ,
@@ -126,14 +142,17 @@ public function testAddVirtualProductToCart()
126
142
}
127
143
128
144
/**
129
- * @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_two_empty_carts.php
130
145
* @magentoDataFixture Magento/Bundle/_files/product.php
131
146
* @return void
132
147
*/
148
+ #[
149
+ DataFixture(GuestCartFixture::class, as: 'cart1 ' ),
150
+ DataFixture(GuestCartFixture::class, as: 'cart2 ' ),
151
+ ]
133
152
public function testAddBundleProductToCart ()
134
153
{
135
- $ cartId1 = $ this ->graphQlStateDiff -> getCartIdHash ( ' test_quote1 ' );
136
- $ cartId2 = $ this ->graphQlStateDiff -> getCartIdHash ( ' test_quote2 ' );
154
+ $ cartId1 = $ this ->fixtures -> get ( ' cart1 ' )-> getId ( );
155
+ $ cartId2 = $ this ->fixtures -> get ( ' cart2 ' )-> getId ( );
137
156
$ query = $ this ->getAddBundleProductToCartQuery ('bundle-product ' );
138
157
$ this ->graphQlStateDiff ->testState (
139
158
$ query ,
@@ -147,14 +166,17 @@ public function testAddBundleProductToCart()
147
166
}
148
167
149
168
/**
150
- * @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_two_empty_carts.php
151
169
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
152
170
* @return void
153
171
*/
172
+ #[
173
+ DataFixture(GuestCartFixture::class, as: 'cart1 ' ),
174
+ DataFixture(GuestCartFixture::class, as: 'cart2 ' ),
175
+ ]
154
176
public function testAddConfigurableProductToCart (): void
155
177
{
156
- $ cartId1 = $ this ->graphQlStateDiff -> getCartIdHash ( ' test_quote1 ' );
157
- $ cartId2 = $ this ->graphQlStateDiff -> getCartIdHash ( ' test_quote2 ' );
178
+ $ cartId1 = $ this ->fixtures -> get ( ' cart1 ' )-> getId ( );
179
+ $ cartId2 = $ this ->fixtures -> get ( ' cart2 ' )-> getId ( );
158
180
$ query = $ this ->getAddConfigurableProductToCartQuery ();
159
181
$ this ->graphQlStateDiff ->testState (
160
182
$ query ,
@@ -168,14 +190,17 @@ public function testAddConfigurableProductToCart(): void
168
190
}
169
191
170
192
/**
171
- * @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_two_empty_carts.php
172
193
* @magentoDataFixture Magento/Downloadable/_files/product_downloadable_with_purchased_separately_links.php
173
194
* @return void
174
195
*/
196
+ #[
197
+ DataFixture(GuestCartFixture::class, as: 'cart1 ' ),
198
+ DataFixture(GuestCartFixture::class, as: 'cart2 ' ),
199
+ ]
175
200
public function testAddDownloadableProductToCart (): void
176
201
{
177
- $ cartId1 = $ this ->graphQlStateDiff -> getCartIdHash ( ' test_quote1 ' );
178
- $ cartId2 = $ this ->graphQlStateDiff -> getCartIdHash ( ' test_quote2 ' );
202
+ $ cartId1 = $ this ->fixtures -> get ( ' cart1 ' )-> getId ( );
203
+ $ cartId2 = $ this ->fixtures -> get ( ' cart2 ' )-> getId ( );
179
204
$ sku = 'downloadable-product-with-purchased-separately-links ' ;
180
205
$ links = $ this ->getProductsLinks ($ sku );
181
206
$ linkId = key ($ links );
0 commit comments