|
| 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('Address Region'); |
| 48 | + $addressMock->expects($this->any())->method('getPostcode')->willReturn('Address Postcode'); |
| 49 | + $addressMock->expects($this->any())->method('getCountryModel')->willReturn($countryMock); |
| 50 | + |
| 51 | + $this->assertEquals( |
| 52 | + 'Address Name, Address Street Full, Address City, Address Region Address Postcode, USA', |
| 53 | + $this->customerAddressesFormatter->format($addressMock) |
| 54 | + ); |
| 55 | + } |
| 56 | +} |
0 commit comments