Completed
Push — master ( d154ad...604248 )
by Valentin
05:10
created

DeclarationTest::classNamespaceProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Cycle\ORM\Promise\Tests\Declaration;
5
6
use Cycle\ORM\Promise\Declaration\Declaration;
7
use Cycle\ORM\Promise\Tests\Declaration\Fixtures\HasNamespaceExample;
8
use PHPUnit\Framework\TestCase;
9
10
class DeclarationTest extends TestCase
11
{
12
    /**
13
     * @dataProvider nameProvider
14
     *
15
     * @param \ReflectionClass $parent
16
     * @param string           $class
17
     * @param string           $expected
18
     */
19
    public function testShortName(\ReflectionClass $parent, string $class, string $expected): void
20
    {
21
        $declaration = new Declaration($parent, $class);
22
        $this->assertSame($expected, $declaration->class->getShortName());
23
    }
24
25
    public function nameProvider(): array
26
    {
27
        $r = new \ReflectionClass(\Example::class);
28
29
        return [
30
            [$r, 'ExampleProxy\\', 'ExampleProxy'],
31
            [$r, 'ExampleProxy', 'ExampleProxy'],
32
            [$r, '\ExampleProxy', 'ExampleProxy'],
33
            [$r, '\Namespaced\Name\Of\ExampleProxy', 'ExampleProxy'],
34
        ];
35
    }
36
37
    /**
38
     * @dataProvider namespaceProvider
39
     *
40
     * @param \ReflectionClass $parent
41
     * @param string           $class
42
     * @param string|null      $expected
43
     */
44
    public function testNamespace(\ReflectionClass $parent, string $class, ?string $expected): void
45
    {
46
        $declaration = new Declaration($parent, $class);
47
        $this->assertSame($expected, $declaration->class->getNamespaceName());
48
    }
49
50
    public function namespaceProvider(): array
51
    {
52
        $r1 = new \ReflectionClass(\Example::class);
53
        $r2 = new \ReflectionClass(HasNamespaceExample::class);
54
55
        return [
56
            [$r1, 'ExampleProxy\\', null],
57
            [$r1, 'ExampleProxy', null],
58
            [$r1, '\ExampleProxy', null],
59
            [$r2, '\ExampleProxy', null],
60
            [$r2, 'ExampleProxy', $r2->getNamespaceName()],
61
            [$r2, 'ExampleProxy\\', $r2->getNamespaceName()],
62
            [$r2, '\Namespaced\Name\Of\ExampleProxy', 'Namespaced\Name\Of'],
63
            [$r2, 'Namespaced\Name\Of\ExampleProxy', 'Namespaced\Name\Of'],
64
        ];
65
    }
66
67
    /**
68
     * @dataProvider fullNameProvider
69
     *
70
     * @param \ReflectionClass $parent
71
     * @param string           $class
72
     * @param string|null      $expected
73
     */
74
    public function testFullName(\ReflectionClass $parent, string $class, ?string $expected): void
75
    {
76
        $declaration = new Declaration($parent, $class);
77
        $this->assertSame($expected, $declaration->class->getFullName());
78
    }
79
80
    public function fullNameProvider(): array
81
    {
82
        $r1 = new \ReflectionClass(\Example::class);
83
        $r2 = new \ReflectionClass(HasNamespaceExample::class);
84
85
        return [
86
            [$r1, 'ExampleProxy', '\ExampleProxy'],
87
            [$r1, '\ExampleProxy', '\ExampleProxy'],
88
            [$r2, '\ExampleProxy', '\ExampleProxy'],
89
            [$r2, 'ExampleProxy', $r2->getNamespaceName() . '\\' . 'ExampleProxy'],
90
            [$r2, 'ExampleProxy\\', $r2->getNamespaceName() . '\\' . 'ExampleProxy'],
91
            [$r2, '\Namespaced\Name\Of\ExampleProxy', 'Namespaced\Name\Of\ExampleProxy'],
92
            [$r2, 'Namespaced\Name\Of\ExampleProxy', 'Namespaced\Name\Of\ExampleProxy'],
93
        ];
94
    }
95
}