|
5 | 5 | */
|
6 | 6 | namespace Magento\Payment\Test\Unit\Model\Checks\CanUseForCountry;
|
7 | 7 |
|
| 8 | +use Magento\Directory\Helper\Data; |
| 9 | +use Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider; |
| 10 | +use Magento\Quote\Model\Quote; |
| 11 | +use Magento\Quote\Model\Quote\Address; |
| 12 | +use PHPUnit_Framework_MockObject_MockObject as MockObject; |
| 13 | + |
| 14 | +/** |
| 15 | + * CountryProviderTest contains tests for CountryProvider class |
| 16 | + */ |
8 | 17 | class CountryProviderTest extends \PHPUnit_Framework_TestCase
|
9 | 18 | {
|
10 | 19 | /**
|
11 |
| - * @var \Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider |
| 20 | + * @var CountryProvider |
| 21 | + */ |
| 22 | + private $countryProvider; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var Data|MockObject |
12 | 26 | */
|
13 |
| - protected $model; |
| 27 | + private $directory; |
14 | 28 |
|
15 | 29 | /**
|
16 |
| - * @var \PHPUnit_Framework_MockObject_MockObject |
| 30 | + * @var Quote|MockObject |
17 | 31 | */
|
18 |
| - protected $directoryMock; |
| 32 | + private $quote; |
19 | 33 |
|
20 |
| - public function setUp() |
| 34 | + protected function setUp() |
21 | 35 | {
|
22 |
| - $this->directoryMock = $this->getMock('Magento\Directory\Helper\Data', [], [], '', false, false); |
23 |
| - $this->model = new \Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider($this->directoryMock); |
| 36 | + $this->directory = $this->getMockBuilder(Data::class) |
| 37 | + ->disableOriginalConstructor() |
| 38 | + ->setMethods(['getDefaultCountry']) |
| 39 | + ->getMock(); |
| 40 | + |
| 41 | + $this->quote = $this->getMockBuilder(Quote::class) |
| 42 | + ->disableOriginalConstructor() |
| 43 | + ->setMethods(['getBillingAddress', 'getShippingAddress']) |
| 44 | + ->getMock(); |
| 45 | + |
| 46 | + $this->countryProvider = new CountryProvider($this->directory); |
24 | 47 | }
|
25 | 48 |
|
26 |
| - public function testGetCountryForNonVirtualQuote() |
| 49 | + /** |
| 50 | + * @covers \Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider::getCountry |
| 51 | + */ |
| 52 | + public function testGetCountry() |
27 | 53 | {
|
28 |
| - $quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false, false); |
29 |
| - $quoteMock->expects($this->once())->method('isVirtual')->willReturn(false); |
30 |
| - $addressMock = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false, false); |
31 |
| - $addressMock->expects($this->once())->method('getCountry')->will($this->returnValue(1)); |
32 |
| - $quoteMock->expects($this->once())->method('getShippingAddress')->will($this->returnValue($addressMock)); |
33 |
| - $this->assertEquals(1, $this->model->getCountry($quoteMock)); |
| 54 | + $address = $this->getMockBuilder(Address::class) |
| 55 | + ->disableOriginalConstructor() |
| 56 | + ->setMethods(['getCountry']) |
| 57 | + ->getMock(); |
| 58 | + |
| 59 | + $this->quote->expects(static::once()) |
| 60 | + ->method('getBillingAddress') |
| 61 | + ->willReturn($address); |
| 62 | + |
| 63 | + $this->quote->expects(static::never()) |
| 64 | + ->method('getShippingAddress'); |
| 65 | + |
| 66 | + $address->expects(static::once()) |
| 67 | + ->method('getCountry') |
| 68 | + ->willReturn('UK'); |
| 69 | + $this->directory->expects(static::never()) |
| 70 | + ->method('getDefaultCountry'); |
| 71 | + |
| 72 | + static::assertEquals('UK', $this->countryProvider->getCountry($this->quote)); |
34 | 73 | }
|
35 | 74 |
|
36 |
| - public function testGetCountryForVirtualQuoteWhenBillingAddressNotExist() |
| 75 | + /** |
| 76 | + * @covers \Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider::getCountry |
| 77 | + */ |
| 78 | + public function testGetCountryForBillingAddressWithoutCountry() |
37 | 79 | {
|
38 |
| - $quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false, false); |
39 |
| - $quoteMock->expects($this->once())->method('isVirtual')->willReturn(true); |
40 |
| - $addressMock = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false, false); |
41 |
| - $addressMock->expects($this->never())->method('getCountry'); |
42 |
| - $quoteMock->expects($this->never())->method('getShippingAddress'); |
43 |
| - $quoteMock->expects($this->once())->method('getBillingAddress')->willReturn(null); |
44 |
| - $this->directoryMock->expects($this->once())->method('getDefaultCountry')->willReturn(10); |
45 |
| - $this->assertEquals(10, $this->model->getCountry($quoteMock)); |
| 80 | + $billingAddress = $this->getMockBuilder(Address::class) |
| 81 | + ->disableOriginalConstructor() |
| 82 | + ->setMethods(['getCountry']) |
| 83 | + ->getMock(); |
| 84 | + |
| 85 | + $shippingAddress = $this->getMockBuilder(Address::class) |
| 86 | + ->disableOriginalConstructor() |
| 87 | + ->setMethods(['getCountry']) |
| 88 | + ->getMock(); |
| 89 | + |
| 90 | + $this->quote->expects(static::once()) |
| 91 | + ->method('getShippingAddress') |
| 92 | + ->willReturn($shippingAddress); |
| 93 | + $this->quote->expects(static::once()) |
| 94 | + ->method('getBillingAddress') |
| 95 | + ->willReturn($billingAddress); |
| 96 | + |
| 97 | + $billingAddress->expects(static::once()) |
| 98 | + ->method('getCountry') |
| 99 | + ->willReturn(null); |
| 100 | + |
| 101 | + $shippingAddress->expects(static::once()) |
| 102 | + ->method('getCountry') |
| 103 | + ->willReturn(null); |
| 104 | + |
| 105 | + $this->directory->expects(static::once()) |
| 106 | + ->method('getDefaultCountry') |
| 107 | + ->willReturn('US'); |
| 108 | + static::assertEquals('US', $this->countryProvider->getCountry($this->quote)); |
46 | 109 | }
|
47 | 110 |
|
48 |
| - public function testGetCountryForVirtualQuoteWhenBillingAddressExist() |
| 111 | + /** |
| 112 | + * @covers \Magento\Payment\Model\Checks\CanUseForCountry\CountryProvider::getCountry |
| 113 | + */ |
| 114 | + public function testGetCountryShippingAddress() |
49 | 115 | {
|
50 |
| - $quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false, false); |
51 |
| - $quoteMock->expects($this->once())->method('isVirtual')->willReturn(true); |
52 |
| - $addressMock = $this->getMock('Magento\Quote\Model\Quote\Address', [], [], '', false, false); |
53 |
| - $addressMock->expects($this->once())->method('getCountry')->willReturn(10); |
54 |
| - $quoteMock->expects($this->never())->method('getShippingAddress'); |
55 |
| - $quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($addressMock); |
56 |
| - $this->directoryMock->expects($this->never())->method('getDefaultCountry'); |
57 |
| - $this->assertEquals(10, $this->model->getCountry($quoteMock)); |
| 116 | + $shippingAddress = $this->getMockBuilder(Address::class) |
| 117 | + ->disableOriginalConstructor() |
| 118 | + ->setMethods(['getCountry']) |
| 119 | + ->getMock(); |
| 120 | + |
| 121 | + $billingAddress = $this->getMockBuilder(Address::class) |
| 122 | + ->disableOriginalConstructor() |
| 123 | + ->setMethods(['getCountry']) |
| 124 | + ->getMock(); |
| 125 | + |
| 126 | + $this->quote->expects(static::once()) |
| 127 | + ->method('getBillingAddress') |
| 128 | + ->willReturn($billingAddress); |
| 129 | + |
| 130 | + $this->quote->expects(static::once()) |
| 131 | + ->method('getShippingAddress') |
| 132 | + ->willReturn($shippingAddress); |
| 133 | + |
| 134 | + $shippingAddress->expects(static::once()) |
| 135 | + ->method('getCountry') |
| 136 | + ->willReturn('CA'); |
| 137 | + |
| 138 | + $shippingAddress->expects(static::once()) |
| 139 | + ->method('getCountry') |
| 140 | + ->willReturn(null); |
| 141 | + |
| 142 | + $this->directory->expects(static::never()) |
| 143 | + ->method('getDefaultCountry'); |
| 144 | + |
| 145 | + static::assertEquals('CA', $this->countryProvider->getCountry($this->quote)); |
58 | 146 | }
|
59 | 147 | }
|
0 commit comments