|
| 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 ArrayObject; |
| 14 | +use BasicEnumeration; |
| 15 | +use Countable; |
| 16 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 17 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 18 | +use PHPUnit\Framework\Attributes\Test; |
| 19 | +use PHPUnit\Framework\TestCase; |
| 20 | +use Respect\Stringifier\Helpers\ObjectHelper; |
| 21 | +use Respect\Stringifier\Stringifiers\DeclaredStringifier; |
| 22 | +use Respect\Stringifier\Test\Double\FakeQuoter; |
| 23 | + |
| 24 | +#[CoversClass(DeclaredStringifier::class)] |
| 25 | +final class DeclaredStringifierTest extends TestCase |
| 26 | +{ |
| 27 | + private const DEPTH = 0; |
| 28 | + |
| 29 | + #[Test] |
| 30 | + public function itShouldNotStringifyWhenRawValueIsNotExists(): void |
| 31 | + { |
| 32 | + $sut = new DeclaredStringifier(new FakeQuoter()); |
| 33 | + |
| 34 | + self::assertNull($sut->stringify('NotAClassInterfaceTraitOrEnum', self::DEPTH)); |
| 35 | + } |
| 36 | + |
| 37 | + #[Test] |
| 38 | + #[DataProvider('existsRawValuesProvider')] |
| 39 | + public function itShouldStringifyWhenRawValueIsExists(string $raw): void |
| 40 | + { |
| 41 | + $quoter = new FakeQuoter(); |
| 42 | + |
| 43 | + $sut = new DeclaredStringifier($quoter); |
| 44 | + |
| 45 | + $actual = $sut->stringify($raw, self::DEPTH); |
| 46 | + $expected = $quoter->quote($raw, self::DEPTH); |
| 47 | + |
| 48 | + self::assertEquals($expected, $actual); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @return array<int, array<int, string>> |
| 53 | + */ |
| 54 | + public static function existsRawValuesProvider(): array |
| 55 | + { |
| 56 | + return [ |
| 57 | + [ArrayObject::class], |
| 58 | + [Countable::class], |
| 59 | + [BasicEnumeration::class], |
| 60 | + [ObjectHelper::class], |
| 61 | + ]; |
| 62 | + } |
| 63 | +} |
0 commit comments