File: YamlDictionaryParserTest.php

package info (click to toggle)
php-pda-pheanstalk 8.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 836 kB
  • sloc: php: 4,713; xml: 19; makefile: 14
file content (48 lines) | stat: -rw-r--r-- 1,670 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

declare(strict_types=1);

namespace Pheanstalk\Tests\Unit\Parser;

use Pheanstalk\Parser\YamlDictionaryParser;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

#[CoversClass(YamlDictionaryParser::class)]
final class YamlDictionaryParserTest extends TestCase
{
    /**
     * @phpstan-return iterable<array{0: string, 1: array<string, string|int|float|bool>}>
     */
    public static function yamlDictionaryProvider(): iterable
    {
        yield ["---\n  a: def\n  b: 15", ['a' => 'def', 'b' => 15]];
        yield ["---\n  a: def\n  b: 15", ['a' => 'def', 'b' => 15]];
        yield ["---\n  a:     def\n  b: 15", ['a' => 'def', 'b' => 15]];
        yield ["---\n  a: \"    def\"\n  b: 15", ['a' => '    def', 'b' => 15]];

        // Special cases, some keys are not quoted, but will be in the future
        //  https://github.com/beanstalkd/beanstalkd/issues/610
        yield ["---\n  os: test123\n  b: 15", ['os' => 'test123', 'b' => 15]];
        yield ["---\n  os: \"test123\"\n  b: 15", ['os' => 'test123', 'b' => 15]];


        // Floats
        yield ["---\n  a: \"    def\"\n  b: 1.5", ['a' => '    def', 'b' => 1.5]];

        // Booleans
        yield ["---\n  a: true\n  b: false", ['a' => true, 'b' => false]];
    }

    /**
     * @param array<string, int|string|bool|float> $expected
     */
    #[DataProvider('yamlDictionaryProvider')]
    public function testParse(string $rawData, array $expected): void
    {
        $parser = new YamlDictionaryParser();
        Assert::assertSame($expected, $parser->parse($rawData));
    }
}