Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CountryTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class CountryTest extends \PHPUnit\Framework\TestCase
12 {
13  protected $country;
14 
18  protected $localeListsMock;
19 
20  protected function setUp()
21  {
22  $this->localeListsMock = $this->createMock(\Magento\Framework\Locale\ListsInterface::class);
23 
24  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
25  $this->country = $objectManager->getObject(
26  \Magento\Directory\Model\Country::class,
27  ['localeLists' => $this->localeListsMock]
28  );
29  }
30 
31  public function testGetName()
32  {
33  $this->localeListsMock->expects($this->once())
34  ->method('getCountryTranslation')
35  ->with(1, null)
36  ->willReturn('United States');
37 
38  $this->country->setId(1);
39  $this->assertEquals('United States', $this->country->getName());
40  }
41 
42  public function testGetNameWithLocale()
43  {
44  $this->localeListsMock->expects($this->once())
45  ->method('getCountryTranslation')
46  ->with(1, 'de_DE')
47  ->willReturn('Vereinigte Staaten');
48 
49  $this->country->setId(1);
50  $this->assertEquals('Vereinigte Staaten', $this->country->getName('de_DE'));
51  }
52 }
$objectManager
Definition: bootstrap.php:17