File: TypeMatcherTest.php

package info (click to toggle)
php-deepcopy 1.13.4-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 612 kB
  • sloc: php: 1,793; makefile: 26
file content (56 lines) | stat: -rw-r--r-- 1,249 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
<?php declare(strict_types=1);

namespace DeepCopyTest\TypeMatcher;

use DeepCopy\TypeMatcher\TypeMatcher;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use stdClass;

/**
 * @covers \DeepCopy\TypeMatcher\TypeMatcher
 */
class TypeMatcherTest extends TestCase
{
    /**
     * @dataProvider provideElements
     */
    #[DataProvider('provideElements')]
    public function test_it_retrieves_the_object_properties($type, $element, $expected)
    {
        $matcher = new TypeMatcher($type);

        $actual = $matcher->matches($element);

        $this->assertSame($expected, $actual);
    }

    public static function provideElements()
    {
        return [
            '[class] same class as type' => ['stdClass', new stdClass(), true],
            '[class] different class as type' => ['stdClass', new Foo(), false],
            '[class] child class as type' => [Foo::class, new Bar(), true],
            '[class] interface implementation as type' => [IA::class, new A(), true],

            '[scalar] array match' => ['array', [], true],
            '[scalar] array no match' => ['array', true, false],
        ];
    }
}

class Foo
{
}

class Bar extends Foo
{
}

interface IA
{
}

class A implements IA
{
}