Skip to content

Commit 172b220

Browse files
committed
ACP2E-894: wip adding parametrized data fixtures
1 parent 35bedb5 commit 172b220

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

app/code/Magento/Quote/Test/Fixture/CustomerCart.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
use Magento\Quote\Api\CartRepositoryInterface;
1313
use Magento\Quote\Model\QuoteFactory;
1414
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
15+
use Magento\Store\Model\StoreManagerInterface;
1516
use Magento\TestFramework\Fixture\Api\DataMerger;
1617
use Magento\TestFramework\Fixture\Api\ServiceFactory;
1718
use Magento\TestFramework\Fixture\Data\ProcessorInterface;
1819
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
1920

2021
class CustomerCart implements RevertibleDataFixtureInterface
2122
{
22-
2323
private const DEFAULT_DATA = [
2424
'customer_id' => null
2525
];
@@ -59,8 +59,14 @@ class CustomerCart implements RevertibleDataFixtureInterface
5959
*/
6060
private $dataMerger;
6161

62+
/**
63+
* @var StoreManagerInterface
64+
*/
65+
private $storeManager;
66+
6267
/**
6368
* @param ServiceFactory $serviceFactory
69+
* @param StoreManagerInterface $storeManager
6470
* @param CartRepositoryInterface $cartRepository
6571
* @param CartManagementInterface $cartManagement
6672
* @param QuoteResource $quoteResource
@@ -70,6 +76,7 @@ class CustomerCart implements RevertibleDataFixtureInterface
7076
*/
7177
public function __construct(
7278
ServiceFactory $serviceFactory,
79+
StoreManagerInterface $storeManager,
7380
CartRepositoryInterface $cartRepository,
7481
CartManagementInterface $cartManagement,
7582
QuoteResource $quoteResource,
@@ -78,6 +85,7 @@ public function __construct(
7885
DataMerger $dataMerger,
7986
) {
8087
$this->serviceFactory = $serviceFactory;
88+
$this->storeManager = $storeManager;
8189
$this->cartRepository = $cartRepository;
8290
$this->cartManagement = $cartManagement;
8391
$this->quoteResource = $quoteResource;
@@ -95,17 +103,14 @@ public function apply(array $data = []): ?DataObject
95103
$customerId = $data['customer_id'] ?? null;
96104
$storeId = $data['store_id'] ?? null;
97105
if ($storeId) {
98-
$cartService = $this->serviceFactory->create(CartManagementInterface::class, 'createEmptyCart');
99-
} else {
100-
$cartService = $this->serviceFactory->create(CartManagementInterface::class, 'createEmptyCartForCustomer');
106+
$setCurrentStoreService = $this->serviceFactory->create(StoreManagerInterface::class, 'setCurrentStore');
107+
$setCurrentStoreService->execute(['store' => $storeId]);
101108
}
109+
$cartService = $this->serviceFactory->create(CartManagementInterface::class, 'createEmptyCartForCustomer');
102110
$cartId = $cartService->execute(['customerId' => $customerId]);
103-
if ($storeId) {
104-
$cartService = $this->serviceFactory->create(CartManagementInterface::class, 'assignCustomer');
105-
$cartService->execute(['cartId' => $cartId, 'customerId' => $customerId, 'storeId' => $storeId]);
106-
}
107111
$cartRepositoryService = $this->serviceFactory->create(CartRepositoryInterface::class, 'get');
108-
return $cartRepositoryService->execute(['cartId' => $cartId]);
112+
$cart = $cartRepositoryService->execute(['cartId' => $cartId]);
113+
return $cart;
109114
}
110115

111116
/**

app/code/Magento/Store/Test/Fixture/Store.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Store implements RevertibleDataFixtureInterface
4949
* @param StoreResource $storeResource
5050
* @param StoreManagerInterface $storeManager
5151
* @param ProcessorInterface $dataProcessor
52+
* @param ManagerInterface $eventManager
5253
*/
5354
public function __construct(
5455
StoreInterfaceFactory $storeFactory,
@@ -85,6 +86,10 @@ public function apply(array $data = []): ?DataObject
8586
$this->storeResource->save($store);
8687
$this->storeManager->reinitStores();
8788

89+
$sequence = \Magento\Framework\App\ObjectManager::getInstance()->create(\Magento\TestFramework\Db\Sequence::class);
90+
$n = $store->getId() + 1;
91+
$sequence->generateSequences($n);
92+
8893
return $store;
8994
}
9095

dev/tests/api-functional/testsuite/Magento/GraphQl/Sales/CustomerOrders/GetCustomerOrdersTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,24 @@ public function testGetCustomerOrders()
154154
$query,
155155
[],
156156
'',
157-
$this->getCustomerAuthHeaders($customerToken)
157+
$this->getCustomerHeaders($customerToken, $store2->getCode())
158158
);
159159

160-
$this->assertNull($response['customer']['id']);
160+
$this->assertNotNull($response['customer']['orders']);
161161
$this->assertEquals('John', $response['customer']['firstname']);
162162
$this->assertEquals('Smith', $response['customer']['lastname']);
163163
$this->assertEquals($currentEmail, $response['customer']['email']);
164164
}
165165

166166
/**
167167
* @param string $token
168+
* @param string $storeCode
168169
*
169170
* @return array
170171
*/
171-
private function getCustomerAuthHeaders(string $token): array
172+
private function getCustomerHeaders(string $token, string $storeCode): array
172173
{
173-
return ['Authorization' => 'Bearer ' . $token];
174+
return ['Authorization' => 'Bearer ' . $token, 'Store' => $storeCode];
174175
}
175176

176177
/**

0 commit comments

Comments
 (0)