mirror of
https://github.com/Respect/Validation.git
synced 2024-06-13 11:12:18 +02:00
Fix bugs on "SubdivisionCode" rule
The last commit was a cherry-pick from a long time ago, so the test was into a different repository which could not be seen by PHPUnit. I moved the tests and them I could see that the rule had some bugs and wrong exception messages.
This commit is contained in:
parent
6c9a0e7228
commit
9ab672d489
|
@ -26,9 +26,9 @@ class SubdivisionCode extends AbstractWrapper
|
|||
public function __construct($countryCode)
|
||||
{
|
||||
$shortName = ucfirst(strtolower($countryCode)).'SubdivisionCode';
|
||||
$className = __NAMESPACE__.'\\Locale\\'.$shortName;
|
||||
$className = __NAMESPACE__.'\\SubdivisionCode\\'.$shortName;
|
||||
if (!class_exists($className)) {
|
||||
throw new ComponentException(sprintf('"%s" is not a valid countryCode for ISO 3166-2', $countryCode));
|
||||
throw new ComponentException(sprintf('"%s" is not a valid country code in ISO 3166-2', $countryCode));
|
||||
}
|
||||
|
||||
$this->countryCode = $countryCode;
|
||||
|
|
|
@ -20,8 +20,8 @@ use PHPUnit_Framework_TestCase;
|
|||
class SubdivisionCodeTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ComponentException
|
||||
* @expectedExceptionMessage "whatever" is not a valid entry for ISO 3166-2
|
||||
* @expectedException Respect\Validation\Exceptions\ComponentException
|
||||
* @expectedExceptionMessage "whatever" is not a valid country code in ISO 3166-2
|
||||
*/
|
||||
public function testShouldThrowsExceptionWhenInvalidFormat()
|
||||
{
|
||||
|
@ -29,8 +29,8 @@ class SubdivisionCodeTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\ComponentException
|
||||
* @expectedExceptionMessage "JK" is not a valid entry for ISO 3166-2
|
||||
* @expectedException Respect\Validation\Exceptions\ComponentException
|
||||
* @expectedExceptionMessage "JK" is not a valid country code in ISO 3166-2
|
||||
*/
|
||||
public function testShouldNotAcceptWrongNamesOnConstructor()
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ class SubdivisionCodeTest extends PHPUnit_Framework_TestCase
|
|||
{
|
||||
$countrySubdivision = new SubdivisionCode('US');
|
||||
|
||||
$this->assertEquals('US', $countrySubdivision->entry);
|
||||
$this->assertEquals('US', $countrySubdivision->countryCode);
|
||||
}
|
||||
|
||||
public function providerForValidSubdivisionCodeInformation()
|
||||
|
@ -58,9 +58,9 @@ class SubdivisionCodeTest extends PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* @dataProvider providerForValidSubdivisionCodeInformation
|
||||
*/
|
||||
public function testShouldValidateValidSubdivisionCodeInformation($entry, $input)
|
||||
public function testShouldValidateValidSubdivisionCodeInformation($countryCode, $input)
|
||||
{
|
||||
$countrySubdivision = new SubdivisionCode($entry);
|
||||
$countrySubdivision = new SubdivisionCode($countryCode);
|
||||
|
||||
$this->assertTrue($countrySubdivision->validate($input));
|
||||
}
|
||||
|
@ -77,16 +77,16 @@ class SubdivisionCodeTest extends PHPUnit_Framework_TestCase
|
|||
/**
|
||||
* @dataProvider providerForInvalidSubdivisionCodeInformation
|
||||
*/
|
||||
public function testShouldNotValidateInvalidSubdivisionCodeInformation($entry, $input)
|
||||
public function testShouldNotValidateInvalidSubdivisionCodeInformation($countryCode, $input)
|
||||
{
|
||||
$countrySubdivision = new SubdivisionCode($entry);
|
||||
$countrySubdivision = new SubdivisionCode($countryCode);
|
||||
|
||||
$this->assertFalse($countrySubdivision->validate($input));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Respect\Validation\Exceptions\SubdivisionCode\BrSubdivisionCodeException
|
||||
* @expectedExceptionMessage "CA" must be a country subdivision of Brazil
|
||||
* @expectedException Respect\Validation\Exceptions\SubdivisionCode\BrSubdivisionCodeException
|
||||
* @expectedExceptionMessage "CA" must be a subdivision code of Brazil
|
||||
*/
|
||||
public function testShouldThrowsSubdivisionCodeException()
|
||||
{
|
Loading…
Reference in a new issue