Failed Conditions
Push — travis-php7.4 ( 6887c5 )
by Michael
13:05
created

DCOM58Test::testIssue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Doctrine\Tests\Annotations\Ticket;
3
4
use Doctrine\Annotations\AnnotationReader;
5
use Doctrine\Annotations\DocParser;
6
use PHPUnit\Framework\TestCase;
7
8
//Some class named Entity in the global namespace
9
include __DIR__ .'/DCOM58Entity.php';
10
11
/**
12
 * @group DCOM58
13
 */
14
class DCOM58Test extends TestCase
15
{
16
    public function testIssue()
17
    {
18
        $reader     = new AnnotationReader();
19
        $result     = $reader->getClassAnnotations(new \ReflectionClass(__NAMESPACE__ . '\MappedClass'));
20
21
        $classAnnotations = array_combine(
22
            array_map('get_class', $result),
23
            $result
24
        );
25
26
        self::assertArrayNotHasKey('', $classAnnotations, 'Class "xxx" is not a valid entity or mapped super class.');
27
    }
28
29
    public function testIssueGlobalNamespace()
30
    {
31
        $docblock   = '@Entity';
32
        $parser     = new DocParser();
33
        $parser->setImports([
34
            '__NAMESPACE__' => 'Doctrine\Tests\Annotations\Ticket\Doctrine\ORM\Mapping'
35
        ]);
36
37
        $annots     = $parser->parse($docblock);
38
39
        self::assertCount(1, $annots);
40
        self::assertInstanceOf(Doctrine\ORM\Mapping\Entity::class, $annots[0]);
41
    }
42
43
    public function testIssueNamespaces()
44
    {
45
        $docblock   = '@Entity';
46
        $parser     = new DocParser();
47
        $parser->addNamespace('Doctrine\Tests\Annotations\Ticket\Doctrine\ORM');
48
49
        $annots     = $parser->parse($docblock);
50
51
        self::assertCount(1, $annots);
52
        self::assertInstanceOf(Doctrine\ORM\Entity::class, $annots[0]);
53
    }
54
55
    public function testIssueMultipleNamespaces()
56
    {
57
        $docblock   = '@Entity';
58
        $parser     = new DocParser();
59
        $parser->addNamespace('Doctrine\Tests\Annotations\Ticket\Doctrine\ORM\Mapping');
60
        $parser->addNamespace('Doctrine\Tests\Annotations\Ticket\Doctrine\ORM');
61
62
        $annots     = $parser->parse($docblock);
63
64
        self::assertCount(1, $annots);
65
        self::assertInstanceOf(Doctrine\ORM\Mapping\Entity::class, $annots[0]);
66
    }
67
68
    public function testIssueWithNamespacesOrImports()
69
    {
70
        $docblock   = '@Entity';
71
        $parser     = new DocParser();
72
        $annots     = $parser->parse($docblock);
73
74
        self::assertCount(1, $annots);
75
        self::assertInstanceOf(\Entity::class, $annots[0]);
76
    }
77
}
78
79
/**
80
 * @Entity
81
 */
82
class MappedClass
83
{
84
85
}
86
87
88
namespace Doctrine\Tests\Annotations\Ticket\Doctrine\ORM\Mapping;
89
/**
90
* @Annotation
91
*/
92
class Entity
93
{
94
95
}
96
97
namespace Doctrine\Tests\Annotations\Ticket\Doctrine\ORM;
98
/**
99
* @Annotation
100
*/
101
class Entity
102
{
103
104
}
105