diff options
| author | Murilo Ijanc <[email protected]> | 2026-07-26 14:58:55 -0300 |
|---|---|---|
| committer | Murilo Ijanc <[email protected]> | 2026-07-26 14:58:55 -0300 |
| commit | 64764fb9fac0227f8e0443e7c7519d73aec275b9 (patch) | |
| tree | cb4fc56eeb6ecce53854f9c530609cf01ab3349f /tests/NormalizationTest.php | |
| download | php-0.1.0.tar.gz | |
Initial importv0.1.0
Diffstat (limited to 'tests/NormalizationTest.php')
| -rw-r--r-- | tests/NormalizationTest.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/NormalizationTest.php b/tests/NormalizationTest.php new file mode 100644 index 0000000..36de024 --- /dev/null +++ b/tests/NormalizationTest.php @@ -0,0 +1,44 @@ +<?php + +declare(strict_types=1); + +namespace Cepis\Tests; + +use Cepis\CepisException; +use Cepis\Client; +use Cepis\InvalidCepException; +use PHPUnit\Framework\TestCase; + +final class NormalizationTest extends TestCase +{ + public function testAcceptsMaskedAndUnmasked(): void + { + foreach (['01001000', '01001-000', ' 01001-000 ', '01001.000'] as $value) { + self::assertSame('01001000', Client::normalizeCep($value)); + } + } + + public function testRejectsBadFormat(): void + { + foreach (['', '123', '0100100a', '010010000', 'abcdefgh', '01001-0000'] as $value) { + try { + Client::normalizeCep($value); + self::fail(sprintf('expected "%s" to be rejected', $value)); + } catch (InvalidCepException $exception) { + self::assertStringContainsString('8 digits', $exception->getMessage()); + } + } + } + + public function testOneCatchHandlesEverything(): void + { + $this->expectException(CepisException::class); + Client::normalizeCep('123'); + } + + public function testInvalidCepIsAlsoAnInvalidArgumentException(): void + { + $this->expectException(\InvalidArgumentException::class); + Client::normalizeCep('123'); + } +} |