|
| 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 PHPUnit\Framework\Attributes\CoversClass; |
| 15 | +use PHPUnit\Framework\Attributes\Test; |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | +use Respect\Stringifier\Stringifiers\ArrayObjectStringifier; |
| 18 | +use Respect\Stringifier\Test\Double\FakeQuoter; |
| 19 | +use Respect\Stringifier\Test\Double\FakeStringifier; |
| 20 | +use stdClass; |
| 21 | + |
| 22 | +use function sprintf; |
| 23 | + |
| 24 | +#[CoversClass(ArrayObjectStringifier::class)] |
| 25 | +final class ArrayObjectStringifierTest extends TestCase |
| 26 | +{ |
| 27 | + private const DEPTH = 0; |
| 28 | + |
| 29 | + #[Test] |
| 30 | + public function itShouldNotStringifyRawValueWhenItIsNotAnArrayObject(): void |
| 31 | + { |
| 32 | + $sut = new ArrayObjectStringifier(new FakeStringifier(), new FakeQuoter()); |
| 33 | + |
| 34 | + self::assertNull($sut->stringify(new stdClass(), self::DEPTH)); |
| 35 | + } |
| 36 | + |
| 37 | + #[Test] |
| 38 | + public function itShouldStringifyRawValueWhenItIsAnArrayObject(): void |
| 39 | + { |
| 40 | + $raw = new ArrayObject([1, 2, 3]); |
| 41 | + |
| 42 | + $stringifier = new FakeStringifier(); |
| 43 | + $quoter = new FakeQuoter(); |
| 44 | + |
| 45 | + $string = $stringifier->stringify($raw->getArrayCopy(), self::DEPTH + 1); |
| 46 | + |
| 47 | + $sut = new ArrayObjectStringifier($stringifier, $quoter); |
| 48 | + |
| 49 | + $actual = $sut->stringify($raw, self::DEPTH); |
| 50 | + $expected = $quoter->quote( |
| 51 | + sprintf('ArrayObject { getArrayCopy() => %s }', $string), |
| 52 | + self::DEPTH |
| 53 | + ); |
| 54 | + |
| 55 | + self::assertSame($expected, $actual); |
| 56 | + } |
| 57 | +} |
0 commit comments