mirror of
https://github.com/danog/Valinor.git
synced 2025-01-09 22:28:31 +01:00
62 lines
2.7 KiB
PHP
62 lines
2.7 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace CuyZ\Valinor\Tests\Unit\Utility;
|
||
|
|
||
|
use CuyZ\Valinor\Tests\Fixture\Enum\BackedIntegerEnum;
|
||
|
use CuyZ\Valinor\Tests\Fixture\Enum\BackedStringEnum;
|
||
|
use CuyZ\Valinor\Tests\Fixture\Enum\PureEnum;
|
||
|
use CuyZ\Valinor\Utility\ValueDumper;
|
||
|
use DateTimeImmutable;
|
||
|
use PHPUnit\Framework\TestCase;
|
||
|
use stdClass;
|
||
|
|
||
|
final class ValueDumperTest extends TestCase
|
||
|
{
|
||
|
/**
|
||
|
* @dataProvider dump_value_returns_correct_signature_data_provider
|
||
|
*
|
||
|
* @param mixed $value
|
||
|
*/
|
||
|
public function test_dump_value_returns_correct_signature($value, string $expected): void
|
||
|
{
|
||
|
self::assertSame($expected, ValueDumper::dump($value));
|
||
|
}
|
||
|
|
||
|
public function dump_value_returns_correct_signature_data_provider(): array
|
||
|
{
|
||
|
return [
|
||
|
'null' => [null, 'null'],
|
||
|
'boolean true' => [true, 'true'],
|
||
|
'boolean false' => [false, 'false'],
|
||
|
'integer' => [42, '42'],
|
||
|
'float' => [1337.404, '1337.404'],
|
||
|
'string with single quote' => ['foo', "'foo'"],
|
||
|
'string with double quote' => ["foo'bar", '"foo\'bar"'],
|
||
|
'string with both quotes' => ['"foo\'bar"', '\'"foo\\\'bar"\''],
|
||
|
'string with exact max length' => ['Lorem ipsum dolor sit amet, consectetur adipiscing', "'Lorem ipsum dolor sit amet, consectetur adipiscing'"],
|
||
|
'string cropped' => ['Lorem ipsum dolor sit amet, consectetur adipiscing elit.', "'Lorem ipsum dolor sit amet, consectetur adipiscing…'"],
|
||
|
'string cropped only after threshold' => ['Lorem12345 ipsumdolorsitamet,consecteturadipiscingelit.Curabitur', "'Lorem12345 ipsumdolorsitamet,consecteturadipiscinge…'"],
|
||
|
'string without space cropped' => ['Loremipsumdolorsitamet,consecteturadipiscingelit.Curabitur',"'Loremipsumdolorsitamet,consecteturadipiscingelit.Cu…'"],
|
||
|
'date' => [new DateTimeImmutable('@1648733888'), '2022/03/31 13:38:08'],
|
||
|
'object' => [new stdClass(), 'object(stdClass)'],
|
||
|
'array' => [['foo' => 'bar', 'baz'], "array{foo: 'bar', 0: 'baz'}"],
|
||
|
'array with in-depth entries' => [['foo' => ['bar' => 'baz']], "array{foo: array{…}}"],
|
||
|
'array with too much entries' => [[0, 1, 2, 3, 4, 5, 6, 7], "array{0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, …}"],
|
||
|
];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @PHP8.1 move to data provider
|
||
|
*
|
||
|
* @requires PHP >= 8.1
|
||
|
*/
|
||
|
public function test_dump_enum_value_returns_correct_signature(): void
|
||
|
{
|
||
|
self::assertSame('FOO', ValueDumper::dump(PureEnum::FOO));
|
||
|
self::assertSame('foo', ValueDumper::dump(BackedStringEnum::FOO));
|
||
|
self::assertSame('42', ValueDumper::dump(BackedIntegerEnum::FOO));
|
||
|
}
|
||
|
}
|