Skip to content

Commit 40412cc

Browse files
committed
Change how to stringify null values
Using "null" in lowercase is more familiar because that's how we represent that in PHP itself. Signed-off-by: Henrique Moody <[email protected]>
1 parent 2fdd6e5 commit 40412cc

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

src/Stringifiers/NullStringifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ public function stringify(mixed $raw, int $depth): ?string
2626
return null;
2727
}
2828

29-
return $this->quoter->quote('NULL', $depth);
29+
return $this->quoter->quote('null', $depth);
3030
}
3131
}

tests/integration/stringify-array.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ output([
2525
]);
2626
?>
2727
--EXPECT--
28-
`[1, NULL, [1.0, [resource <stream>, ..., []]], false, [object] (stdClass: []), ...]`
28+
`[1, null, [1.0, [resource <stream>, ..., []]], false, [object] (stdClass: []), ...]`

tests/integration/stringify-null.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ require 'vendor/autoload.php';
88
output(null);
99
?>
1010
--EXPECT--
11-
`NULL`
11+
`null`

tests/unit/Stringifiers/NullStringifierTest.php

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,32 @@
1313
use PHPUnit\Framework\Attributes\CoversClass;
1414
use PHPUnit\Framework\Attributes\Test;
1515
use PHPUnit\Framework\TestCase;
16-
use Respect\Stringifier\Quoter;
1716
use Respect\Stringifier\Stringifiers\NullStringifier;
17+
use Respect\Stringifier\Test\Double\FakeQuoter;
1818

1919
#[CoversClass(NullStringifier::class)]
2020
final class NullStringifierTest extends TestCase
2121
{
22+
private const DEPTH = 0;
23+
2224
#[Test]
23-
public function shouldNotConvertToStringWhenRawValueIsNotNull(): void
25+
public function itShouldNotStringifyRawValueWhenItIsNotNull(): void
2426
{
25-
$raw = 1;
26-
$depth = 0;
27-
28-
$quoterMock = $this->createMock(Quoter::class);
29-
$quoterMock
30-
->expects($this->never())
31-
->method('quote');
27+
$sut = new NullStringifier(new FakeQuoter());
3228

33-
$nullStringifier = new NullStringifier($quoterMock);
34-
35-
self::assertNull($nullStringifier->stringify($raw, $depth));
29+
self::assertNull($sut->stringify(1, self::DEPTH));
3630
}
3731

3832
#[Test]
39-
public function shouldConvertToStringWhenRawValueIsNull(): void
33+
public function itShouldStringifyRawValueWhenItIsNull(): void
4034
{
41-
$raw = null;
42-
$depth = 0;
43-
44-
$expected = 'NULL';
35+
$quoter = new FakeQuoter();
4536

46-
$quoterMock = $this->createMock(Quoter::class);
47-
$quoterMock
48-
->expects($this->once())
49-
->method('quote')
50-
->with($expected, $depth)
51-
->willReturn($expected);
37+
$sut = new NullStringifier($quoter);
5238

53-
$nullStringifier = new NullStringifier($quoterMock);
39+
$actual = $sut->stringify(null, self::DEPTH);
40+
$expected = $quoter->quote('null', self::DEPTH);
5441

55-
self::assertSame($expected, $nullStringifier->stringify($raw, $depth));
42+
self::assertSame($expected, $actual);
5643
}
5744
}

0 commit comments

Comments
 (0)