|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of Respect/Stringifier. |
| 5 | + * Copyright (c) Henrique Moody <henriquemoody@gmail.com> |
| 6 | + * SPDX-License-Identifier: MIT |
| 7 | + */ |
| 8 | + |
| 9 | +declare(strict_types=1); |
| 10 | + |
| 11 | +namespace Respect\Stringifier\Test\Unit\Stringifiers; |
| 12 | + |
| 13 | +use BackedEnumeration; |
| 14 | +use BasicEnumeration; |
| 15 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 16 | +use PHPUnit\Framework\Attributes\Test; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | +use Respect\Stringifier\Stringifiers\EnumerationStringifier; |
| 19 | +use Respect\Stringifier\Test\Double\FakeQuoter; |
| 20 | + |
| 21 | +#[CoversClass(EnumerationStringifier::class)] |
| 22 | +final class EnumerationStringifierTest extends TestCase |
| 23 | +{ |
| 24 | + private const DEPTH = 0; |
| 25 | + |
| 26 | + #[Test] |
| 27 | + public function itShouldNotStringifyWhenRawValueIsNotAnEnumeration(): void |
| 28 | + { |
| 29 | + $sut = new EnumerationStringifier(new FakeQuoter()); |
| 30 | + |
| 31 | + self::assertNull($sut->stringify(1, self::DEPTH)); |
| 32 | + } |
| 33 | + |
| 34 | + #[Test] |
| 35 | + public function itShouldStringifyRawValueWhenItIsBasicEnumeration(): void |
| 36 | + { |
| 37 | + $quoter = new FakeQuoter(); |
| 38 | + |
| 39 | + $sut = new EnumerationStringifier($quoter); |
| 40 | + |
| 41 | + $actual = $sut->stringify(BasicEnumeration::BAR, self::DEPTH); |
| 42 | + $expected = $quoter->quote('BasicEnumeration::BAR', self::DEPTH); |
| 43 | + |
| 44 | + self::assertSame($expected, $actual); |
| 45 | + } |
| 46 | + |
| 47 | + #[Test] |
| 48 | + public function itShouldStringifyRawValueWhenItIsBackedEnumeration(): void |
| 49 | + { |
| 50 | + $quoter = new FakeQuoter(); |
| 51 | + |
| 52 | + $sut = new EnumerationStringifier($quoter); |
| 53 | + |
| 54 | + $actual = $sut->stringify(BackedEnumeration::BAZ, self::DEPTH); |
| 55 | + $expected = $quoter->quote('BackedEnumeration::BAZ', self::DEPTH); |
| 56 | + |
| 57 | + self::assertSame($expected, $actual); |
| 58 | + } |
| 59 | +} |
0 commit comments