mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 15:25:45 +01:00
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.
45 lines
1.3 KiB
PHP
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);
|
|
}
|
|
}
|