Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CountryProviderTest.php
Go to the documentation of this file.
1 <?php
7 
12 use PHPUnit_Framework_MockObject_MockObject as MockObject;
13 
17 class CountryProviderTest extends \PHPUnit\Framework\TestCase
18 {
22  private $countryProvider;
23 
27  private $directory;
28 
32  private $quote;
33 
34  protected function setUp()
35  {
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);
47  }
48 
52  public function testGetCountry()
53  {
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::exactly(2))
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));
73  }
74 
79  {
80  $address = $this->getMockBuilder(Address::class)
81  ->disableOriginalConstructor()
82  ->setMethods(['getCountry'])
83  ->getMock();
84 
85  $this->quote->expects(static::never())
86  ->method('getShippingAddress');
87  $this->quote->expects(static::once())
88  ->method('getBillingAddress')
89  ->willReturn($address);
90 
91  $address->expects(static::once())
92  ->method('getCountry')
93  ->willReturn(null);
94  $this->directory->expects(static::once())
95  ->method('getDefaultCountry')
96  ->willReturn('US');
97  static::assertEquals('US', $this->countryProvider->getCountry($this->quote));
98  }
99 
104  {
105  $address = $this->getMockBuilder(Address::class)
106  ->disableOriginalConstructor()
107  ->setMethods(['getCountry'])
108  ->getMock();
109 
110  $this->quote->expects(static::once())
111  ->method('getBillingAddress')
112  ->willReturn(null);
113 
114  $this->quote->expects(static::once())
115  ->method('getShippingAddress')
116  ->willReturn($address);
117 
118  $address->expects(static::exactly(2))
119  ->method('getCountry')
120  ->willReturn('CA');
121 
122  $this->directory->expects(static::never())
123  ->method('getDefaultCountry');
124 
125  static::assertEquals('CA', $this->countryProvider->getCountry($this->quote));
126  }
127 }
$address
Definition: customer.php:38