File: ArrayShapeTest.php

package info (click to toggle)
php-phpdocumentor-type-resolver 1.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 2,432 kB
  • sloc: php: 26,448; xml: 102; makefile: 50
file content (66 lines) | stat: -rw-r--r-- 1,870 bytes parent folder | download | duplicates (2)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

declare(strict_types=1);

namespace phpDocumentor\Reflection\PseudoTypes;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
 * @coversDefaultClass \phpDocumentor\Reflection\PseudoTypes\ArrayShape
 */
class ArrayShapeTest extends TestCase
{
    /**
     * @covers ::getItems
     */
    public function testExposeItems(): void
    {
        $item1 = new ArrayShapeItem('foo', new True_(), false);
        $item2 = new ArrayShapeItem('bar', new False_(), true);

        $arrayShape = new ArrayShape($item1, $item2);

        $this->assertSame([$item1, $item2], $arrayShape->getItems());
    }

    /**
     * @covers ::__toString
     */
    #[DataProvider('provideToStringData')]
    public function testToString(string $expectedResult, ArrayShape $arrayShape): void
    {
        $this->assertSame($expectedResult, (string) $arrayShape);
    }

    /**
     * @return array<string, array{string, ArrayShape}>
     */
    public static function provideToStringData(): array
    {
        return [
            'with keys' => [
                'array{foo: true, bar?: false}',
                new ArrayShape(
                    new ArrayShapeItem('foo', new True_(), false),
                    new ArrayShapeItem('bar', new False_(), true)
                ),
            ],
            'with empty keys' => [
                'array{true, false}',
                new ArrayShape(
                    new ArrayShapeItem('', new True_(), false),
                    new ArrayShapeItem('', new False_(), false)
                ),
            ],
            'without keys' => [
                'array{true, false}',
                new ArrayShape(
                    new ArrayShapeItem(null, new True_(), false),
                    new ArrayShapeItem(null, new False_(), false)
                ),
            ],
        ];
    }
}