Skip to content

Commit 4d614d6

Browse files
ENGCOM-6448: [InstantPurchase] Cover Ui/CustomerAddressesFormatter and Ui/ShippingMethodFormatter by Unit Test #25993
2 parents 2ab1d26 + e848267 commit 4d614d6

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InstantPurchase\Test\Unit\Model\Ui;
9+
10+
use Magento\InstantPurchase\Model\Ui\CustomerAddressesFormatter;
11+
use Magento\Customer\Model\Address;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
13+
use Magento\Directory\Model\Country;
14+
use PHPUnit\Framework\TestCase;
15+
16+
class CustomerAddressesFormatterTest extends TestCase
17+
{
18+
/**
19+
* @var CustomerAddressesFormatter|\PHPUnit_Framework_MockObject_MockObject
20+
*/
21+
private $customerAddressesFormatter;
22+
23+
/**
24+
* Setup environment for testing
25+
*/
26+
protected function setUp()
27+
{
28+
$objectManager = new ObjectManagerHelper($this);
29+
$this->customerAddressesFormatter = $objectManager->getObject(CustomerAddressesFormatter::class);
30+
}
31+
32+
/**
33+
* Test format()
34+
*/
35+
public function testFormat()
36+
{
37+
$addressMock = $this->createPartialMock(
38+
Address::class,
39+
['getName', 'getStreetFull', 'getCity', 'getRegion', 'getPostcode', 'getCountryModel']
40+
);
41+
$countryMock = $this->createMock(Country::class);
42+
43+
$countryMock->expects($this->any())->method('getName')->willReturn('USA');
44+
$addressMock->expects($this->any())->method('getName')->willReturn('Address Name');
45+
$addressMock->expects($this->any())->method('getStreetFull')->willReturn('Address Street Full');
46+
$addressMock->expects($this->any())->method('getCity')->willReturn('Address City');
47+
$addressMock->expects($this->any())->method('getRegion')->willReturn('California');
48+
$addressMock->expects($this->any())->method('getPostcode')->willReturn('12345');
49+
$addressMock->expects($this->any())->method('getCountryModel')->willReturn($countryMock);
50+
51+
$this->assertEquals(
52+
'Address Name, Address Street Full, Address City, California 12345, USA',
53+
$this->customerAddressesFormatter->format($addressMock)
54+
);
55+
}
56+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InstantPurchase\Test\Unit\Model\Ui;
9+
10+
use Magento\InstantPurchase\Model\Ui\ShippingMethodFormatter;
11+
use Magento\Quote\Api\Data\ShippingMethodInterface;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class ShippingMethodFormatterTest extends TestCase
16+
{
17+
/**
18+
* @var ShippingMethodFormatter|\PHPUnit_Framework_MockObject_MockObject
19+
*/
20+
private $shippingMethodFormatter;
21+
22+
/**
23+
* Setup environment for testing
24+
*/
25+
protected function setUp()
26+
{
27+
$objectManager = new ObjectManagerHelper($this);
28+
$this->shippingMethodFormatter = $objectManager->getObject(ShippingMethodFormatter::class);
29+
}
30+
31+
/**
32+
* Test format()
33+
*/
34+
public function testFormat()
35+
{
36+
$shippingMethodMock = $this->createMock(ShippingMethodInterface::class, ['getCarrierTitle', 'getMethodTitle']);
37+
38+
$shippingMethodMock->expects($this->any())->method('getCarrierTitle')->willReturn('flatrate');
39+
$shippingMethodMock->expects($this->any())->method('getMethodTitle')->willReturn('flatrate');
40+
41+
$this->assertEquals(
42+
'flatrate - flatrate',
43+
$this->shippingMethodFormatter->format($shippingMethodMock)
44+
);
45+
}
46+
}

0 commit comments

Comments
 (0)