|
13 | 13 | use PHPUnit\Framework\Attributes\CoversClass; |
14 | 14 | use PHPUnit\Framework\Attributes\Test; |
15 | 15 | use PHPUnit\Framework\TestCase; |
16 | | -use Respect\Stringifier\Quoter; |
17 | 16 | use Respect\Stringifier\Stringifiers\BoolStringifier; |
| 17 | +use Respect\Stringifier\Test\Double\FakeQuoter; |
18 | 18 |
|
19 | 19 | #[CoversClass(BoolStringifier::class)] |
20 | 20 | final class BoolStringifierTest extends TestCase |
21 | 21 | { |
| 22 | + private const DEPTH = 0; |
| 23 | + |
22 | 24 | #[Test] |
23 | | - public function shouldNotConvertToStringWhenRawValueIsNotBoolean(): void |
| 25 | + public function itShouldNotStringifyWhenRawValueIsNotBoolean(): void |
24 | 26 | { |
25 | | - $raw = 1; |
26 | | - $depth = 0; |
27 | | - |
28 | | - $quoterMock = $this->createMock(Quoter::class); |
29 | | - $quoterMock |
30 | | - ->expects($this->never()) |
31 | | - ->method('quote'); |
32 | | - |
33 | | - $boolStringifier = new BoolStringifier($quoterMock); |
| 27 | + $sut = new BoolStringifier(new FakeQuoter()); |
34 | 28 |
|
35 | | - self::assertNull($boolStringifier->stringify($raw, $depth)); |
| 29 | + self::assertNull($sut->stringify(1, self::DEPTH)); |
36 | 30 | } |
37 | 31 |
|
38 | 32 | #[Test] |
39 | | - public function shouldConvertToStringWhenRawValueIsTrue(): void |
| 33 | + public function itShouldStringifyRawValueWhenItIsTrue(): void |
40 | 34 | { |
41 | | - $raw = true; |
42 | | - $depth = 0; |
| 35 | + $quoter = new FakeQuoter(); |
43 | 36 |
|
44 | | - $expected = 'TRUE'; |
| 37 | + $sut = new BoolStringifier($quoter); |
45 | 38 |
|
46 | | - $quoterMock = $this->createMock(Quoter::class); |
47 | | - $quoterMock |
48 | | - ->expects($this->once()) |
49 | | - ->method('quote') |
50 | | - ->with($expected, $depth) |
51 | | - ->willReturn($expected); |
| 39 | + $actual = $sut->stringify(true, self::DEPTH); |
| 40 | + $expected = $quoter->quote('true', self::DEPTH); |
52 | 41 |
|
53 | | - $boolStringifier = new BoolStringifier($quoterMock); |
54 | | - |
55 | | - self::assertSame($expected, $boolStringifier->stringify($raw, $depth)); |
| 42 | + self::assertSame($expected, $actual); |
56 | 43 | } |
57 | 44 |
|
58 | 45 | #[Test] |
59 | | - public function shouldConvertToStringWhenRawValueIsFalse(): void |
| 46 | + public function itShouldStringifyRawValueWhenItIsFalse(): void |
60 | 47 | { |
61 | | - $raw = false; |
62 | | - $depth = 0; |
63 | | - |
64 | | - $expected = 'FALSE'; |
| 48 | + $quoter = new FakeQuoter(); |
65 | 49 |
|
66 | | - $quoterMock = $this->createMock(Quoter::class); |
67 | | - $quoterMock |
68 | | - ->expects($this->once()) |
69 | | - ->method('quote') |
70 | | - ->with($expected, $depth) |
71 | | - ->willReturn($expected); |
| 50 | + $sut = new BoolStringifier($quoter); |
72 | 51 |
|
73 | | - $boolStringifier = new BoolStringifier($quoterMock); |
| 52 | + $actual = $sut->stringify(false, self::DEPTH); |
| 53 | + $expected = $quoter->quote('false', self::DEPTH); |
74 | 54 |
|
75 | | - self::assertSame($expected, $boolStringifier->stringify($raw, $depth)); |
| 55 | + self::assertSame($expected, $actual); |
76 | 56 | } |
77 | 57 | } |
0 commit comments