Skip to content

Commit 596034c

Browse files
committed
Allow custom Quoter to be injected into CompositeHandler::create()
Assisted-by: Claude Code (claude-sonnet-4-6)
1 parent 9fea72b commit 596034c

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/Handlers/CompositeHandler.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use DateTimeInterface;
1414
use Respect\Stringifier\Handler;
15+
use Respect\Stringifier\Quoter;
1516
use Respect\Stringifier\Quoters\CodeQuoter;
1617

1718
use function array_unshift;
@@ -31,10 +32,8 @@ public function __construct(Handler ...$handlers)
3132
$this->handlers = $handlers;
3233
}
3334

34-
public static function create(): self
35+
public static function create(Quoter $quoter = new CodeQuoter(self::MAXIMUM_LENGTH)): self
3536
{
36-
$quoter = new CodeQuoter(self::MAXIMUM_LENGTH);
37-
3837
$handler = new self(
3938
new InfiniteNumberHandler($quoter),
4039
new NotANumberHandler($quoter),

tests/unit/Handlers/CompositeHandlerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Respect\Stringifier\Handlers\CompositeHandler;
1717
use Respect\Stringifier\Test\Double\FakeHandler;
18+
use Respect\Stringifier\Test\Double\FakeQuoter;
1819
use Respect\Stringifier\Test\Double\LameHandler;
1920
use stdClass;
2021

@@ -75,4 +76,13 @@ public function itShouldCreateDefaultCompositeHandler(): void
7576
{
7677
self::assertInstanceOf(CompositeHandler::class, CompositeHandler::create());
7778
}
79+
80+
#[Test]
81+
public function itShouldCreateCompositeHandlerWithTheGivenQuoter(): void
82+
{
83+
$quoter = new FakeQuoter();
84+
$sut = CompositeHandler::create($quoter);
85+
86+
self::assertSame($quoter->quote('true', self::DEPTH), $sut->handle(true, self::DEPTH));
87+
}
7888
}

0 commit comments

Comments
 (0)