Skip to content

Commit

Permalink
magento#13899 Improve unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
tadeobarranco committed Mar 2, 2018
1 parent c6d128f commit 7c5ddee
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,35 @@ public function testPostCodesThrowsExceptionIfCountryDoesNotExist()
$this->validator->validate('12345', 'INVALID-CODE');
}

public function testInvalidCanadaZipCode() {
$resultOnlyDigits = $this->validator->validate('12345', 'CA');
$resultMoreCharactersThanNeeded = $this->validator->validate('A1B2C3D', 'CA');
$resultLessCharactersThanNeeded = $this->validator->validate('A1B2C', 'CA');
$resultMoreThanOneSpace = $this->validator->validate('A1B 2C3', 'CA');
$this->assertFalse($resultOnlyDigits);
$this->assertFalse($resultMoreCharactersThanNeeded);
$this->assertFalse($resultLessCharactersThanNeeded);
$this->assertFalse($resultMoreThanOneSpace);
/**
* @dataProvider getCanadaInvalidPostCodes
*/
public function testInvalidCanadaZipCode($countryId, $invalidPostCode) {
$this->assertFalse($this->validator->validate($invalidPostCode, $countryId));
}

/**
*
*/
public function testValidCanadaZipCode() {
$resultPattern1 = $this->validator->validate('A1B2C3', 'CA');
$resultPattern2 = $this->validator->validate('A1B 2C3', 'CA');
$this->assertTrue($resultPattern1);
$this->assertTrue($resultPattern2);
}

/**
* @return array
*/
public function getCanadaInvalidPostCodes() {
return [
['countryId' => 'CA', 'postcode' => '12345'],
['countryId' => 'CA', 'postcode' => 'A1B2C3D'],
['countryId' => 'CA', 'postcode' => 'A1B2C'],
['countryId' => 'CA', 'postcode' => 'A1B 2C3'],
];
}

/**
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
Expand Down

0 comments on commit 7c5ddee

Please sign in to comment.