Skip to content

Commit

Permalink
proof of concept testing with global formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
rubentebogt committed Oct 9, 2024
1 parent 590857e commit dfa24f4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
21 changes: 20 additions & 1 deletion tests/CountryPostcodeFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Formatter/BEFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function providerFormat() : array
['ABCDE', null],
['ABCDEF', null],

['B8084', '8084'],
['X8084', null],
['B-8084', '8084'],
['X-8084', null],
];
}
}

0 comments on commit dfa24f4

Please sign in to comment.