Skip to content

Commit 7dbd40f

Browse files
committed
Rename "not a number" stringifier
It's just a common practice to keep names descriptive. Even though it's arguable to say the "NaN" could be descriptive enough, I would rather be more explicit. I also updated the tests, removing mocks and making the tests a bit neater. Signed-off-by: Henrique Moody <[email protected]>
1 parent 40412cc commit 7dbd40f

File tree

4 files changed

+56
-77
lines changed

4 files changed

+56
-77
lines changed

src/Stringifiers/ClusterStringifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static function createDefault(): self
4949
new ObjectStringifier($stringifier, $quoter),
5050
new ArrayStringifier($stringifier, $quoter, self::MAXIMUM_DEPTH, self::MAXIMUM_NUMBER_OF_ITEMS),
5151
new InfiniteStringifier($quoter),
52-
new NanStringifier($quoter),
52+
new NotANumberStringifier($quoter),
5353
new ResourceStringifier($quoter),
5454
new BoolStringifier($quoter),
5555
new NullStringifier($quoter),

src/Stringifiers/NanStringifier.php renamed to src/Stringifiers/NotANumberStringifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use function is_float;
1717
use function is_nan;
1818

19-
final class NanStringifier implements Stringifier
19+
final class NotANumberStringifier implements Stringifier
2020
{
2121
public function __construct(
2222
private readonly Quoter $quoter

tests/unit/Stringifiers/NanStringifierTest.php

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Respect/Stringifier.
5+
* Copyright (c) Henrique Moody <[email protected]>
6+
* SPDX-License-Identifier: MIT
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace Respect\Stringifier\Test\Unit\Stringifiers;
12+
13+
use PHPUnit\Framework\Attributes\CoversClass;
14+
use PHPUnit\Framework\Attributes\Test;
15+
use PHPUnit\Framework\TestCase;
16+
use Respect\Stringifier\Stringifiers\NotANumberStringifier;
17+
use Respect\Stringifier\Test\Double\FakeQuoter;
18+
19+
use function acos;
20+
21+
#[CoversClass(NotANumberStringifier::class)]
22+
final class NotANumberStringifierTest extends TestCase
23+
{
24+
private const DEPTH = 0;
25+
26+
#[Test]
27+
public function itShouldNotStringifyRawValueWhenItIsNotFloat(): void
28+
{
29+
$sut = new NotANumberStringifier(new FakeQuoter());
30+
31+
self::assertNull($sut->stringify('string', self::DEPTH));
32+
}
33+
34+
#[Test]
35+
public function itShouldNotStringifyRawValueWhenItIsNumber(): void
36+
{
37+
$sut = new NotANumberStringifier(new FakeQuoter());
38+
39+
self::assertNull($sut->stringify(1.00000000002, self::DEPTH));
40+
}
41+
42+
#[Test]
43+
public function itShouldStringifyRawValueWhenItIsNotNumber(): void
44+
{
45+
$quoter = new FakeQuoter();
46+
47+
$sut = new NotANumberStringifier($quoter);
48+
49+
$actual = $sut->stringify(acos(8), self::DEPTH);
50+
$expected = $quoter->quote('NaN', self::DEPTH);
51+
52+
self::assertSame($expected, $actual);
53+
}
54+
}

0 commit comments

Comments
 (0)