diff --git a/tests/CountryPostcodeFormatterTest.php b/tests/CountryPostcodeFormatterTest.php index ccf684e..04bfbb3 100644 --- a/tests/CountryPostcodeFormatterTest.php +++ b/tests/CountryPostcodeFormatterTest.php @@ -5,6 +5,9 @@ namespace Brick\Postcode\Tests; use Brick\Postcode\CountryPostcodeFormatter; +use Brick\Postcode\InvalidPostcodeException; +use Brick\Postcode\PostcodeFormatter; +use Brick\Postcode\UnknownCountryException; use PHPUnit\Framework\TestCase; /** @@ -22,7 +25,23 @@ abstract class CountryPostcodeFormatterTest extends TestCase */ public function testFormat(string $input, ?string $expectedOutput) : void { - $this->assertSame($expectedOutput, $this->getFormatter()->format($input)); + $formatter = new PostcodeFormatter(); + try { + $result = $formatter->format($this->getCountry(), $input); + } catch (InvalidPostcodeException $e) { + $result = null; + } + $this->assertSame($expectedOutput, $result); + } + + /** + * Returns the test associated Country ISO2 code + * + * @return string + */ + public function getCountry() : string + { + return substr((new \ReflectionClass($this))->getShortName(), 0, 2); } /** diff --git a/tests/Formatter/BEFormatterTest.php b/tests/Formatter/BEFormatterTest.php index 7741d9a..c071a2a 100644 --- a/tests/Formatter/BEFormatterTest.php +++ b/tests/Formatter/BEFormatterTest.php @@ -37,8 +37,8 @@ public function providerFormat() : array ['ABCDE', null], ['ABCDEF', null], - ['B8084', '8084'], - ['X8084', null], + ['B-8084', '8084'], + ['X-8084', null], ]; } }