-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCountryPostcodeFormatterTest.php
More file actions
56 lines (49 loc) · 1.35 KB
/
CountryPostcodeFormatterTest.php
File metadata and controls
56 lines (49 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
declare(strict_types=1);
namespace Brick\Postcode\Tests;
use Brick\Postcode\CountryPostcodeFormatter;
use Brick\Postcode\InvalidPostcodeException;
use Brick\Postcode\PostcodeFormatter;
use Brick\Postcode\UnknownCountryException;
use PHPUnit\Framework\TestCase;
/**
* Base class for individual country postcode formatter tests.
*/
abstract class CountryPostcodeFormatterTest extends TestCase
{
/**
* @dataProvider providerFormat
*
* @param string $input
* @param string|null $expectedOutput
*
* @return void
*/
public function testFormat(string $input, ?string $expectedOutput) : void
{
$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);
}
/**
* @return CountryPostcodeFormatter
*/
abstract protected function getFormatter() : CountryPostcodeFormatter;
/**
* @return array
*/
abstract public function providerFormat() : array;
}