Skip to content

Commit 40f547b

Browse files
committed
Test coverage optimisation
1 parent 5d8807a commit 40f547b

File tree

1 file changed

+33
-55
lines changed

1 file changed

+33
-55
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/OfflineShipping/SetOfflineShippingMethodsOnCartTest.php

Lines changed: 33 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Magento\GraphQl\OfflineShipping;
99

1010
use Magento\Integration\Api\CustomerTokenServiceInterface;
11-
use Magento\Quote\Model\Quote;
11+
use Magento\Quote\Model\QuoteFactory;
1212
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
1313
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;
1414
use Magento\TestFramework\Helper\Bootstrap;
@@ -19,6 +19,11 @@
1919
*/
2020
class SetOfflineShippingOnCartTest extends GraphQlAbstract
2121
{
22+
/**
23+
* @var QuoteFactory
24+
*/
25+
private $quoteFactory;
26+
2227
/**
2328
* @var CustomerTokenServiceInterface
2429
*/
@@ -29,11 +34,6 @@ class SetOfflineShippingOnCartTest extends GraphQlAbstract
2934
*/
3035
private $quoteResource;
3136

32-
/**
33-
* @var Quote
34-
*/
35-
private $quote;
36-
3737
/**
3838
* @var QuoteIdToMaskedQuoteIdInterface
3939
*/
@@ -45,67 +45,44 @@ class SetOfflineShippingOnCartTest extends GraphQlAbstract
4545
protected function setUp()
4646
{
4747
$objectManager = Bootstrap::getObjectManager();
48-
$this->quoteResource = $objectManager->create(QuoteResource::class);
49-
$this->quote = $objectManager->create(Quote::class);
50-
$this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
48+
$this->quoteResource = $objectManager->get(QuoteResource::class);
49+
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
50+
$this->quoteIdToMaskedId = $objectManager->get(QuoteIdToMaskedQuoteIdInterface::class);
5151
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
5252
}
5353

54-
/**
55-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
56-
* @magentoApiDataFixture Magento/Checkout/_files/enable_all_shipping_methods.php
57-
*/
58-
public function testSetFlatrateOnCart()
59-
{
60-
$this->setShippingMethodAndCheckResponse(
61-
'flatrate',
62-
'flatrate',
63-
'10',
64-
'Flat Rate - Fixed'
65-
);
66-
}
67-
6854
/**
6955
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
7056
* @magentoApiDataFixture Magento/OfflineShipping/_files/tablerates_weight.php
7157
* @magentoApiDataFixture Magento/Checkout/_files/enable_all_shipping_methods.php
58+
* @dataProvider offlineShippingMethodDataProvider()
59+
* @param string $carrier
60+
* @param string $method
61+
* @param float $amount
62+
* @param string $label
7263
*/
73-
public function testSetTableRatesOnCart()
64+
public function testSetOfflineShippingMethod(string $carrier, string $method, float $amount, string $label)
7465
{
7566
$this->setShippingMethodAndCheckResponse(
76-
'tablerate',
77-
'bestway',
78-
'10',
79-
'Best Way - Table Rate'
67+
$carrier,
68+
$method,
69+
$amount,
70+
$label
8071
);
8172
}
8273

8374
/**
84-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
85-
* @magentoApiDataFixture Magento/Checkout/_files/enable_all_shipping_methods.php
86-
*/
87-
public function testSetFreeShippingOnCart()
88-
{
89-
$this->setShippingMethodAndCheckResponse(
90-
'freeshipping',
91-
'freeshipping',
92-
'0',
93-
'Free Shipping - Free'
94-
);
95-
}
96-
97-
/**
98-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_address_saved.php
99-
* @magentoApiDataFixture Magento/Checkout/_files/enable_all_shipping_methods.php
75+
* Data provider for base offline shipping methods
76+
*
77+
* @return array
10078
*/
101-
public function testSetUpsOnCart()
79+
public function offlineShippingMethodDataProvider()
10280
{
103-
$this->setShippingMethodAndCheckResponse(
104-
'ups',
105-
'GND',
106-
'15.61',
107-
'United Parcel Service - Ground'
108-
);
81+
return [
82+
['flatrate', 'flatrate', 10, 'Flat Rate - Fixed'],
83+
['tablerate', 'bestway', 10, 'Best Way - Table Rate'],
84+
['freeshipping', 'freeshipping', 0, 'Free Shipping - Free']
85+
];
10986
}
11087

11188
/**
@@ -121,17 +98,18 @@ public function testSetUpsOnCart()
12198
private function setShippingMethodAndCheckResponse(
12299
string $shippingCarrierCode,
123100
string $shippingMethodCode,
124-
string $shippingAmount,
101+
float $shippingAmount,
125102
string $shippingLabel
126103
) {
104+
$quote = $this->quoteFactory->create();
127105
$this->quoteResource->load(
128-
$this->quote,
106+
$quote,
129107
'test_order_1',
130108
'reserved_order_id'
131109
);
132-
$shippingAddress = $this->quote->getShippingAddress();
110+
$shippingAddress = $quote->getShippingAddress();
133111
$shippingAddressId = $shippingAddress->getId();
134-
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$this->quote->getId());
112+
$maskedQuoteId = $this->quoteIdToMaskedId->execute((int)$quote->getId());
135113

136114
$query = $this->getQuery(
137115
$maskedQuoteId,

0 commit comments

Comments
 (0)