respect-validation/tests/unit/Message/Stringifier/QuotedStringifierTest.php
Henrique Moody 4379f66bec
Create a stringifier for "quoted" values
The `StandardQuoter` adds backticks around strings, which indicates that
it's not a simple string but a code. With this stringifier, we can add
quotes to placeholders directly into templates.
2024-12-27 00:49:12 +01:00

45 lines
1.3 KiB
PHP

<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Message\Stringifier;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Respect\Stringifier\Quoters\StandardQuoter;
use Respect\Validation\Message\Placeholder\Quoted;
use Respect\Validation\Test\TestCase;
#[CoversClass(QuotedStringifier::class)]
final class QuotedStringifierTest extends TestCase
{
#[Test]
#[DataProvider('providerForAnyValues')]
public function itShouldNotStringifyWhenValueIsNotAnInstanceOfQuoted(mixed $value): void
{
$quoter = new StandardQuoter(1);
$stringifier = new QuotedStringifier($quoter);
self::assertNull($stringifier->stringify($value, 0));
}
#[Test]
#[DataProvider('providerForStringTypes')]
public function itShouldStringifyWhenValueIsAnInstanceOfQuoted(string $value): void
{
$quoted = new Quoted($value);
$quoter = new StandardQuoter(1);
$stringifier = new QuotedStringifier($quoter);
$expected = $quoter->quote($quoted->getValue(), 0);
$actual = $stringifier->stringify($quoted, 0);
self::assertSame($expected, $actual);
}
}