Skip to content

Commit e971004

Browse files
fixed unit test
1 parent c0d1177 commit e971004

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

app/code/Magento/Customer/Block/Address/Renderer/DefaultRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function renderArray($addressAttributes, $format = null)
174174
if ($attributeCode == 'country_id' && isset($addressAttributes['country_id'])) {
175175
$data['country'] = $this->_countryFactory->create()
176176
->loadByCode($addressAttributes['country_id'])
177-
->getName(isset($addressAttributes['locale']) ? $addressAttributes['locale'] : null);
177+
->getName($addressAttributes['locale'] ?? null);
178178
} elseif ($attributeCode == 'region' && isset($addressAttributes['region'])) {
179179
$data['region'] = (string)__($addressAttributes['region']);
180180
} elseif (isset($addressAttributes[$attributeCode])) {

app/code/Magento/Sales/Test/Unit/Model/Order/Address/RendererTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Customer\Block\Address\Renderer\RendererInterface as CustomerAddressBlockRenderer;
1111
use Magento\Customer\Model\Address\Config as CustomerAddressConfig;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
1213
use Magento\Framework\DataObject;
1314
use Magento\Framework\Event\ManagerInterface as EventManager;
1415
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
@@ -18,6 +19,9 @@
1819
use PHPUnit\Framework\MockObject\MockObject;
1920
use PHPUnit\Framework\TestCase;
2021

22+
/**
23+
* Test for \Magento\Sales\Model\Order\Address\Renderer.
24+
*/
2125
class RendererTest extends TestCase
2226
{
2327
/**
@@ -55,6 +59,14 @@ class RendererTest extends TestCase
5559
*/
5660
private $customerAddressBlockRendererMock;
5761

62+
/**
63+
* @var ScopeConfigInterface|MockObject
64+
*/
65+
private $storeConfigMock;
66+
67+
/**
68+
* @ingeritdoc
69+
*/
5870
protected function setUp(): void
5971
{
6072
$this->customerAddressConfigMock = $this->getMockBuilder(CustomerAddressConfig::class)
@@ -75,12 +87,15 @@ protected function setUp(): void
7587
->method('getOrder')
7688
->willReturn($this->orderMock);
7789

90+
$this->storeConfigMock = $this->createMock(ScopeConfigInterface::class);
91+
7892
$this->objectManagerHelper = new ObjectManagerHelper($this);
7993
$this->orderAddressRenderer = $this->objectManagerHelper->getObject(
8094
OrderAddressRenderer::class,
8195
[
8296
'addressConfig' => $this->customerAddressConfigMock,
83-
'eventManager' => $this->eventManagerMock
97+
'eventManager' => $this->eventManagerMock,
98+
'scopeConfig' => $this->storeConfigMock
8499
]
85100
);
86101
}
@@ -89,7 +104,7 @@ public function testFormat()
89104
{
90105
$type = 'html';
91106
$formatType = new DataObject(['renderer' => $this->customerAddressBlockRendererMock]);
92-
$addressData = ['address', 'data'];
107+
$addressData = ['address', 'data', 'locale' => 1];
93108
$result = 'result string';
94109

95110
$this->setStoreExpectations(1);
@@ -103,6 +118,9 @@ public function testFormat()
103118
$this->orderAddressMock->expects(static::atLeastOnce())
104119
->method('getData')
105120
->willReturn($addressData);
121+
$this->storeConfigMock->expects($this->once())
122+
->method('getValue')
123+
->willReturn(1);
106124
$this->customerAddressBlockRendererMock->expects(static::once())
107125
->method('renderArray')
108126
->with($addressData, null)

0 commit comments

Comments
 (0)