Skip to content

Commit 304a638

Browse files
committed
ACP2E-894: wip adding parametrized data fixtures
1 parent ad1be29 commit 304a638

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Quote\Test\Fixture;
9+
10+
use Magento\Framework\DataObject;
11+
use Magento\Quote\Api\CartManagementInterface;
12+
use Magento\Quote\Api\CartRepositoryInterface;
13+
use Magento\Quote\Model\QuoteFactory;
14+
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
15+
use Magento\TestFramework\Fixture\Api\ServiceFactory;
16+
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
17+
18+
class CustomerCart implements RevertibleDataFixtureInterface
19+
{
20+
21+
/**
22+
* @var ServiceFactory
23+
*/
24+
private $serviceFactory;
25+
26+
/**
27+
* @var CartRepositoryInterface
28+
*/
29+
private $cartRepository;
30+
31+
/**
32+
* @var CartManagementInterface
33+
*/
34+
private $cartManagement;
35+
36+
/**
37+
* @var QuoteResource
38+
*/
39+
private $quoteResource;
40+
41+
/**
42+
* @var QuoteFactory
43+
*/
44+
private $quoteFactory;
45+
46+
/**
47+
* @param ServiceFactory $serviceFactory
48+
* @param CartRepositoryInterface $cartRepository
49+
* @param CartManagementInterface $cartManagement
50+
* @param QuoteResource $quoteResource
51+
* @param QuoteFactory $quoteFactory
52+
*/
53+
public function __construct(
54+
ServiceFactory $serviceFactory,
55+
CartRepositoryInterface $cartRepository,
56+
CartManagementInterface $cartManagement,
57+
QuoteResource $quoteResource,
58+
QuoteFactory $quoteFactory
59+
) {
60+
$this->serviceFactory = $serviceFactory;
61+
$this->cartRepository = $cartRepository;
62+
$this->cartManagement = $cartManagement;
63+
$this->quoteResource = $quoteResource;
64+
$this->quoteFactory = $quoteFactory;
65+
}
66+
67+
/**
68+
* @inheritdoc
69+
*/
70+
public function apply(array $data = []): ?DataObject
71+
{
72+
$customerId = $data['customer_id'] ?? null;
73+
$cartService = $this->serviceFactory->create(CartManagementInterface::class, 'createEmptyCartForCustomer');
74+
$cartId = $cartService->execute(['customerId' => $customerId]);
75+
$cartRepositoryService = $this->serviceFactory->create(CartRepositoryInterface::class, 'get');
76+
return $cartRepositoryService->execute(['cartId' => $cartId]);
77+
}
78+
79+
/**
80+
* @inheritdoc
81+
*/
82+
public function revert(DataObject $data): void
83+
{
84+
$cartRepositoryService = $this->serviceFactory->create(CartRepositoryInterface::class, 'delete');
85+
$cartRepositoryService->execute(['quote' => $data]);
86+
}
87+
}

0 commit comments

Comments
 (0)