summaryrefslogtreecommitdiffstats
path: root/tests/NormalizationTest.php
blob: 36de024c81db7cbdc0cfecf51d52531cfe2552f9 (plain)
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
<?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');
    }
}