Passed
Pull Request — master (#100)
by
unknown
23:41 queued 21:10
created

CountryTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 24
dl 0
loc 45
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of the Numverify API Client for PHP.
7
 *
8
 * (c) 2024 Eric Sizemore <[email protected]>
9
 * (c) 2018-2021 Mark Rogoyski <[email protected]>
10
 *
11
 * This source file is subject to the MIT license. For the full copyright,
12
 * license information, and credits/acknowledgements, please view the LICENSE
13
 * and README files that were distributed with this source code.
14
 */
15
16
namespace Numverify\Tests\Country;
17
18
use Numverify\Country\Country;
19
use PHPUnit\Framework\Attributes\CoversClass;
20
use PHPUnit\Framework\Attributes\TestDox;
21
use PHPUnit\Framework\TestCase;
22
use stdClass;
23
24
/**
25
 * @internal
26
 */
27
#[CoversClass(Country::class)]
28
class CountryTest extends TestCase
29
{
30
    private const COUNTRY_CODE = 'US';
31
32
    private const COUNTRY_NAME = 'United States';
33
34
    private const DIALLING_CODE = '+1';
35
36
    #[TestDox('Country \'getters\' returns expected results.')]
37
    public function testGetters(): void
38
    {
39
        $country = new Country(self::COUNTRY_CODE, self::COUNTRY_NAME, self::DIALLING_CODE);
40
41
        $countryCode  = $country->getCountryCode();
42
        $countryName  = $country->getCountryName();
43
        $diallingCode = $country->getDialingCode();
44
45
        self::assertSame(self::COUNTRY_CODE, $countryCode);
46
        self::assertSame(self::COUNTRY_NAME, $countryName);
47
        self::assertSame(self::DIALLING_CODE, $diallingCode);
48
    }
49
50
    #[TestDox('Country implements JsonSerialize and returns array of country information.')]
51
    public function testJsonSerializeInterface(): void
52
    {
53
        $country = new Country(self::COUNTRY_CODE, self::COUNTRY_NAME, self::DIALLING_CODE);
54
55
        /** @var non-empty-string $json */
56
        $json = json_encode($country);
57
58
        /** @var stdClass $object */
59
        $object = json_decode($json);
60
        self::assertSame(self::COUNTRY_CODE, $object->countryCode);
61
        self::assertSame(self::COUNTRY_NAME, $object->countryName);
62
        self::assertSame(self::DIALLING_CODE, $object->diallingCode);
63
    }
64
65
    #[TestDox('Country implements Stringable and returns correct string representation.')]
66
    public function testStringRepresentation(): void
67
    {
68
        $country = new Country(self::COUNTRY_CODE, self::COUNTRY_NAME, self::DIALLING_CODE);
69
70
        $stringRepresentation = (string) $country;
71
        self::assertSame('US: United States (+1)', $stringRepresentation);
72
    }
73
}
74