Skip to content

Commit 5b82bfc

Browse files
author
Hayder Sharhan
committed
Merge remote-tracking branch 'remotes/api/MAGETWO-51296-Github-Multiple-calls-to-getCountryInfo-result-in-a-fatal-error-3858' into for-pr
2 parents b94d6fb + 8ee5c38 commit 5b82bfc

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

app/code/Magento/Directory/Model/CountryInformationAcquirer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,16 @@ public function getCountryInfo($countryId)
9797
);
9898

9999
$countriesCollection = $this->directoryHelper->getCountryCollection($store)->load();
100+
$regions = $this->directoryHelper->getRegionData();
101+
$country = $countriesCollection->getItemById($countryId);
100102

101-
if ($countriesCollection->count() == 0) {
103+
if (!$country) {
102104
throw new NoSuchEntityException(
103105
__(
104106
'Requested country is not available.'
105107
)
106108
);
107109
}
108-
$regions = $this->directoryHelper->getRegionData();
109-
$country = $countriesCollection->getItemById($countryId);
110110
$countryInfo = $this->setCountryInfo($country, $regions, $storeLocale);
111111

112112
return $countryInfo;

app/code/Magento/Directory/Model/ResourceModel/Country/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function loadByStore($store = null)
143143
* Loads Item By Id
144144
*
145145
* @param string $countryId
146-
* @return \Magento\Directory\Model\ResourceModel\Country
146+
* @return \Magento\Directory\Model\ResourceModel\Country|null
147147
*/
148148
public function getItemById($countryId)
149149
{
@@ -152,7 +152,7 @@ public function getItemById($countryId)
152152
return $country;
153153
}
154154
}
155-
return $this->_countryFactory->create();
155+
return null;
156156
}
157157

158158
/**

app/code/Magento/Directory/Test/Unit/Model/CountryInformationAcquirerTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ public function testGetCountryInfo()
129129
'',
130130
false
131131
);
132-
$countryCollection->expects($this->once())->method('addCountryIdFilter')->willReturnSelf();
133132
$countryCollection->expects($this->once())->method('load')->willReturnSelf();
134-
$countryCollection->expects($this->once())->method('count')->willReturn(1);
135133
$countryCollection->expects($this->once())->method('getItemById')->with('AE')->willReturn($testCountryInfo);
136134

137135
$this->directoryHelper->expects($this->once())->method('getCountryCollection')->willReturn($countryCollection);
@@ -174,11 +172,10 @@ public function testGetCountryInfoNotFound()
174172
'',
175173
false
176174
);
177-
$countryCollection->expects($this->once())->method('addCountryIdFilter')->willReturnSelf();
178175
$countryCollection->expects($this->once())->method('load')->willReturnSelf();
179-
$countryCollection->expects($this->once())->method('count')->willReturn(0);
180176

181177
$this->directoryHelper->expects($this->once())->method('getCountryCollection')->willReturn($countryCollection);
178+
$countryCollection->expects($this->once())->method('getItemById')->willReturn(null);
182179
$this->model->getCountryInfo('AE');
183180
}
184181
}

0 commit comments

Comments
 (0)