Skip to content

Commit e110bb5

Browse files
author
lestare
committed
Merge branch 'MAGETWO-55612' into 2.1-develop-pr1
2 parents 9bc5cae + 6fb56bb commit e110bb5

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

app/code/Magento/Payment/Model/Checks/CanUseForCountry/CountryProvider.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ public function __construct(DirectoryHelper $directoryHelper)
3333
*/
3434
public function getCountry(Quote $quote)
3535
{
36-
/** @var Address $address */
37-
$address = $quote->getBillingAddress() ?: $quote->getShippingAddress();
36+
/** @var string $country */
37+
$country = $quote->getBillingAddress()->getCountry() ? :
38+
$quote->getShippingAddress()->getCountry();
3839

39-
return $address->getCountry() ? : $this->directoryHelper->getDefaultCountry();
40+
if (!$country) {
41+
$country = $this->directoryHelper->getDefaultCountry();
42+
}
43+
44+
return $country;
4045
}
4146
}

app/code/Magento/Payment/Test/Unit/Model/Checks/CanUseForCountry/CountryProviderTest.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,31 @@ public function testGetCountry()
7777
*/
7878
public function testGetCountryForBillingAddressWithoutCountry()
7979
{
80-
$address = $this->getMockBuilder(Address::class)
80+
$billingAddress = $this->getMockBuilder(Address::class)
81+
->disableOriginalConstructor()
82+
->setMethods(['getCountry'])
83+
->getMock();
84+
85+
$shippingAddress = $this->getMockBuilder(Address::class)
8186
->disableOriginalConstructor()
8287
->setMethods(['getCountry'])
8388
->getMock();
8489

85-
$this->quote->expects(static::never())
86-
->method('getShippingAddress');
90+
$this->quote->expects(static::once())
91+
->method('getShippingAddress')
92+
->willReturn($shippingAddress);
8793
$this->quote->expects(static::once())
8894
->method('getBillingAddress')
89-
->willReturn($address);
95+
->willReturn($billingAddress);
9096

91-
$address->expects(static::once())
97+
$billingAddress->expects(static::once())
98+
->method('getCountry')
99+
->willReturn(null);
100+
101+
$shippingAddress->expects(static::once())
92102
->method('getCountry')
93103
->willReturn(null);
104+
94105
$this->directory->expects(static::once())
95106
->method('getDefaultCountry')
96107
->willReturn('US');
@@ -102,23 +113,32 @@ public function testGetCountryForBillingAddressWithoutCountry()
102113
*/
103114
public function testGetCountryShippingAddress()
104115
{
105-
$address = $this->getMockBuilder(Address::class)
116+
$shippingAddress = $this->getMockBuilder(Address::class)
117+
->disableOriginalConstructor()
118+
->setMethods(['getCountry'])
119+
->getMock();
120+
121+
$billingAddress = $this->getMockBuilder(Address::class)
106122
->disableOriginalConstructor()
107123
->setMethods(['getCountry'])
108124
->getMock();
109125

110126
$this->quote->expects(static::once())
111127
->method('getBillingAddress')
112-
->willReturn(null);
128+
->willReturn($billingAddress);
113129

114130
$this->quote->expects(static::once())
115131
->method('getShippingAddress')
116-
->willReturn($address);
132+
->willReturn($shippingAddress);
117133

118-
$address->expects(static::once())
134+
$shippingAddress->expects(static::once())
119135
->method('getCountry')
120136
->willReturn('CA');
121137

138+
$shippingAddress->expects(static::once())
139+
->method('getCountry')
140+
->willReturn(null);
141+
122142
$this->directory->expects(static::never())
123143
->method('getDefaultCountry');
124144

0 commit comments

Comments
 (0)