Skip to content

Commit

Permalink
428 - Test coverage: GetAvailableShippingMethodsTest
Browse files Browse the repository at this point in the history
Fix for PHP Fatal error:  Uncaught Exception: Exception occurred when running the "\/home\/travis\/build\/magento\/graphql-ce\/dev\/tests\/integration\/testsuite\/Magento\/Sales\/_files\/guest_quote_with_addresses.php" fixture:
URL key for specified store already exists. in /home/travis/build/magento/graphql-ce/dev/tests/api-functional/framework/Magento/TestFramework/Annotation/ApiDataFixture.php:114
  • Loading branch information
atwixfirster committed Mar 13, 2019
1 parent 36a5981 commit 10a2202
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
declare(strict_types = 1);

namespace Magento\GraphQl\Quote\Customer;

Expand Down Expand Up @@ -44,11 +44,11 @@ class GetAvailableShippingMethodsTest extends GraphQlAbstract
*/
protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
$this->quoteResource = $objectManager->create(QuoteResource::class);
$objectManager = Bootstrap::getObjectManager();
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
$this->quoteResource = $objectManager->create(QuoteResource::class);
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
$this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
$this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
}

/**
Expand All @@ -59,7 +59,7 @@ protected function setUp()
public function testGetAvailableShippingMethods()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1');
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap());
$response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId), [], '', $this->getHeaderMap());

self::assertArrayHasKey('cart', $response);
self::assertArrayHasKey('shipping_addresses', $response['cart']);
Expand All @@ -68,13 +68,13 @@ public function testGetAvailableShippingMethods()
self::assertCount(1, $response['cart']['shipping_addresses'][0]['available_shipping_methods']);

$expectedAddressData = [
'amount' => 10,
'base_amount' => 10,
'carrier_code' => 'flatrate',
'carrier_title' => 'Flat Rate',
'error_message' => '',
'method_code' => 'flatrate',
'method_title' => 'Fixed',
'amount' => 10,
'base_amount' => 10,
'carrier_code' => 'flatrate',
'carrier_title' => 'Flat Rate',
'error_message' => '',
'method_code' => 'flatrate',
'method_title' => 'Fixed',
'price_incl_tax' => 10,
'price_excl_tax' => 10,
];
Expand All @@ -98,7 +98,7 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart()
"The current user cannot perform operations on cart \"$maskedQuoteId\""
);

$this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap('customer2@search.example.com'));
$this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId), [], '', $this->getHeaderMap('customer2@search.example.com'));
}

/**
Expand All @@ -110,7 +110,7 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart()
public function testGetAvailableShippingMethodsIfShippingsAreNotSet()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('test_order_1');
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId), [], '', $this->getHeaderMap());
$response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId), [], '', $this->getHeaderMap());

self::assertEquals(0, count($response['cart']['shipping_addresses'][0]['available_shipping_methods']));
}
Expand All @@ -125,7 +125,7 @@ public function testGetAvailableShippingMethodsIfShippingsAreNotSet()
public function testGetAvailableShippingMethodsOfNonExistentCart()
{
$maskedQuoteId = 'non_existent_masked_id';
$query = $this->getQuery($maskedQuoteId);
$query = $this->getAvailableShippingMethodsQuery($maskedQuoteId);

$this->graphQlQuery($query, [], '', $this->getHeaderMap());
}
Expand All @@ -134,9 +134,10 @@ public function testGetAvailableShippingMethodsOfNonExistentCart()
* @param string $maskedQuoteId
* @return string
*/
private function getQuery(
private function getAvailableShippingMethodsQuery(
string $maskedQuoteId
): string {
): string
{
return <<<QUERY
query {
cart (cart_id: "{$maskedQuoteId}") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
declare(strict_types = 1);

namespace Magento\GraphQl\Quote\Guest;

Expand Down Expand Up @@ -38,10 +38,10 @@ class GetAvailableShippingMethodsTest extends GraphQlAbstract
*/
protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
$this->quoteResource = $objectManager->create(QuoteResource::class);
$this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
$objectManager = Bootstrap::getObjectManager();
$this->quoteFactory = $objectManager->get(QuoteFactory::class);
$this->quoteResource = $objectManager->create(QuoteResource::class);
$this->quoteIdToMaskedId = $objectManager->create(QuoteIdToMaskedQuoteIdInterface::class);
}

/**
Expand All @@ -52,7 +52,7 @@ protected function setUp()
public function testGetAvailableShippingMethodsFromGuestCart()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('guest_quote');
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId));
$response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId));

self::assertArrayHasKey('cart', $response);
self::assertArrayHasKey('shipping_addresses', $response['cart']);
Expand All @@ -61,13 +61,13 @@ public function testGetAvailableShippingMethodsFromGuestCart()
self::assertCount(1, $response['cart']['shipping_addresses'][0]['available_shipping_methods']);

$expectedAddressData = [
'amount' => 5,
'base_amount' => 5,
'carrier_code' => 'flatrate',
'carrier_title' => 'Flat Rate',
'error_message' => '',
'method_code' => 'flatrate',
'method_title' => 'Fixed',
'amount' => 5,
'base_amount' => 5,
'carrier_code' => 'flatrate',
'carrier_title' => 'Flat Rate',
'error_message' => '',
'method_code' => 'flatrate',
'method_title' => 'Fixed',
'price_incl_tax' => 5,
'price_excl_tax' => 5,
];
Expand All @@ -90,7 +90,7 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart()
"The current user cannot perform operations on cart \"$maskedQuoteId\""
);

$this->graphQlQuery($this->getQuery($maskedQuoteId));
$this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId));
}

/**
Expand All @@ -102,7 +102,7 @@ public function testGetAvailableShippingMethodsFromAnotherCustomerCart()
public function testGetAvailableShippingMethodsIfShippingsAreNotSet()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId('guest_quote');
$response = $this->graphQlQuery($this->getQuery($maskedQuoteId));
$response = $this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId));

self::assertEquals(0, count($response['cart']['shipping_addresses'][0]['available_shipping_methods']));
}
Expand All @@ -117,16 +117,17 @@ public function testGetAvailableShippingMethodsOfNonExistentCart()
{
$maskedQuoteId = 'non_existent_masked_id';

$this->graphQlQuery($this->getQuery($maskedQuoteId));
$this->graphQlQuery($this->getAvailableShippingMethodsQuery($maskedQuoteId));
}

/**
* @param string $maskedQuoteId
* @return string
*/
private function getQuery(
private function getAvailableShippingMethodsQuery(
string $maskedQuoteId
): string {
): string
{
return <<<QUERY
query {
cart (cart_id: "{$maskedQuoteId}") {
Expand Down

0 comments on commit 10a2202

Please sign in to comment.