Skip to content

Commit e33bb7c

Browse files
committed
Change how to stringify resources
Considering that we use "[]" for arrays, removing it from the resources makes sense. It also makes sense to use something else other than "()" and "<>" makes the most sense also because it's familiar, as in docblocks, we use "<>" to specify types. Signed-off-by: Henrique Moody <[email protected]>
1 parent 526354e commit e33bb7c

File tree

4 files changed

+15
-34
lines changed

4 files changed

+15
-34
lines changed

src/Stringifiers/ResourceStringifier.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ public function stringify(mixed $raw, int $depth): ?string
3030
return null;
3131
}
3232

33-
return $this->quoter->quote(
34-
sprintf(
35-
'[resource] (%s)',
36-
get_resource_type($raw)
37-
),
38-
$depth
39-
);
33+
return $this->quoter->quote(sprintf('resource <%s>', get_resource_type($raw)), $depth);
4034
}
4135
}

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-resource.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(tmpfile());
99
?>
1010
--EXPECT--
11-
`[resource] (stream)`
11+
`resource <stream>`

tests/unit/Stringifiers/ResourceStringifierTest.php

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,34 @@
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\ResourceStringifier;
17+
use Respect\Stringifier\Test\Double\FakeQuoter;
1818

1919
use function tmpfile;
2020

2121
#[CoversClass(ResourceStringifier::class)]
2222
final class ResourceStringifierTest extends TestCase
2323
{
24+
private const DEPTH = 0;
25+
2426
#[Test]
25-
public function shouldNotConvertToStringWhenRawValueIsNotResource(): void
27+
public function itShouldNotStringifyRawValueWhenItIsNotOfTypeResource(): void
2628
{
27-
$raw = true;
28-
$depth = 0;
29-
30-
$quoterMock = $this->createMock(Quoter::class);
31-
$quoterMock
32-
->expects($this->never())
33-
->method('quote');
29+
$sut = new ResourceStringifier(new FakeQuoter());
3430

35-
$resourceStringifier = new ResourceStringifier($quoterMock);
36-
37-
self::assertNull($resourceStringifier->stringify($raw, $depth));
31+
self::assertNull($sut->stringify(true, self::DEPTH));
3832
}
3933

4034
#[Test]
41-
public function shouldConvertToStringWhenRawValueIsNotResource(): void
35+
public function itShouldStringifyRawValueWhenItIsOfTypeResource(): void
4236
{
43-
$raw = tmpfile();
44-
$depth = 0;
45-
46-
$expected = '[resource] (stream)';
37+
$quoter = new FakeQuoter();
4738

48-
$quoterMock = $this->createMock(Quoter::class);
49-
$quoterMock
50-
->expects($this->once())
51-
->method('quote')
52-
->with($expected, $depth)
53-
->willReturn($expected);
39+
$sut = new ResourceStringifier($quoter);
5440

55-
$resourceStringifier = new ResourceStringifier($quoterMock);
41+
$actual = $sut->stringify(tmpfile(), self::DEPTH);
42+
$expected = $quoter->quote('resource <stream>', self::DEPTH);
5643

57-
self::assertSame($expected, $resourceStringifier->stringify($raw, $depth));
44+
self::assertSame($expected, $actual);
5845
}
5946
}

0 commit comments

Comments
 (0)