Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PostcodeTest.php
Go to the documentation of this file.
1 <?php
7 
8 class PostcodeTest extends \PHPUnit\Framework\TestCase
9 {
15  public function testIsValid()
16  {
17  $countryUs = 'US';
18  $countryUa = 'UK';
19  $helperMock = $this->getMockBuilder(\Magento\Directory\Helper\Data::class)
20  ->disableOriginalConstructor()
21  ->getMock();
22 
23  $helperMock->expects($this->any())
24  ->method('isZipCodeOptional')
25  ->willReturnMap(
26  [
27  [$countryUs, true],
28  [$countryUa, false],
29  ]
30  );
31 
32  $validator = new \Magento\Customer\Model\Address\Validator\Postcode($helperMock);
33  $this->assertTrue($validator->isValid($countryUs, ''));
34  $this->assertFalse($validator->isValid($countryUa, ''));
35  $this->assertTrue($validator->isValid($countryUa, '123123'));
36  }
37 }