Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Handlers/CompositeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use DateTimeInterface;
use Respect\Stringifier\Handler;
use Respect\Stringifier\Quoter;
use Respect\Stringifier\Quoters\CodeQuoter;

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

public static function create(): self
public static function create(Quoter $quoter = new CodeQuoter(self::MAXIMUM_LENGTH)): self
{
$quoter = new CodeQuoter(self::MAXIMUM_LENGTH);

$handler = new self(
new InfiniteNumberHandler($quoter),
new NotANumberHandler($quoter),
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/Handlers/CompositeHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPUnit\Framework\TestCase;
use Respect\Stringifier\Handlers\CompositeHandler;
use Respect\Stringifier\Test\Double\FakeHandler;
use Respect\Stringifier\Test\Double\FakeQuoter;
use Respect\Stringifier\Test\Double\LameHandler;
use stdClass;

Expand Down Expand Up @@ -75,4 +76,13 @@ public function itShouldCreateDefaultCompositeHandler(): void
{
self::assertInstanceOf(CompositeHandler::class, CompositeHandler::create());
}

#[Test]
public function itShouldCreateCompositeHandlerWithTheGivenQuoter(): void
{
$quoter = new FakeQuoter();
$sut = CompositeHandler::create($quoter);

self::assertSame($quoter->quote('true', self::DEPTH), $sut->handle(true, self::DEPTH));
}
}
Loading