|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\Annotations\Metadata; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Annotations\Metadata\AnnotationTarget; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
final class AnnotationTargetTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function testConstructor() : void |
|
13
|
|
|
{ |
|
14
|
|
|
self::assertSame(AnnotationTarget::TARGET_ALL, (new AnnotationTarget(AnnotationTarget::TARGET_ALL))->unwrap()); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function testAllIncludesEverything() : void |
|
18
|
|
|
{ |
|
19
|
|
|
self::assertTrue((AnnotationTarget::TARGET_ALL & AnnotationTarget::TARGET_CLASS) !== 0, 'class in all'); |
|
20
|
|
|
self::assertTrue((AnnotationTarget::TARGET_ALL & AnnotationTarget::TARGET_METHOD) !== 0, 'method in all'); |
|
21
|
|
|
self::assertTrue((AnnotationTarget::TARGET_ALL & AnnotationTarget::TARGET_PROPERTY) !== 0, 'property in all'); |
|
22
|
|
|
self::assertTrue((AnnotationTarget::TARGET_ALL & AnnotationTarget::TARGET_ANNOTATION) !== 0, 'annotation in all'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testStaticFactories() : void |
|
26
|
|
|
{ |
|
27
|
|
|
self::assertSame(AnnotationTarget::TARGET_CLASS, AnnotationTarget::class()->unwrap()); |
|
28
|
|
|
self::assertSame(AnnotationTarget::TARGET_METHOD, AnnotationTarget::method()->unwrap()); |
|
29
|
|
|
self::assertSame(AnnotationTarget::TARGET_PROPERTY, AnnotationTarget::property()->unwrap()); |
|
30
|
|
|
self::assertSame(AnnotationTarget::TARGET_ANNOTATION, AnnotationTarget::annotation()->unwrap()); |
|
31
|
|
|
self::assertSame(AnnotationTarget::TARGET_ALL, AnnotationTarget::all()->unwrap()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @dataProvider accessorsProvider() |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testAccessors(AnnotationTarget $target, int $raw) : void |
|
38
|
|
|
{ |
|
39
|
|
|
self::assertSame(($raw & AnnotationTarget::TARGET_CLASS) !== 0, $target->targetsClass()); |
|
40
|
|
|
self::assertSame(($raw & AnnotationTarget::TARGET_METHOD) !== 0, $target->targetsMethod()); |
|
41
|
|
|
self::assertSame(($raw & AnnotationTarget::TARGET_PROPERTY) !== 0, $target->targetsProperty()); |
|
42
|
|
|
self::assertSame(($raw & AnnotationTarget::TARGET_ANNOTATION) !== 0, $target->targetsAnnotation()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @dataProvider describeProvider() |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testDescribe(AnnotationTarget $target, string $described) : void |
|
49
|
|
|
{ |
|
50
|
|
|
self::assertSame($described, $target->describe()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return (AnnotationTarget|int)[] |
|
55
|
|
|
*/ |
|
56
|
|
|
public function accessorsProvider() : iterable |
|
57
|
|
|
{ |
|
58
|
|
|
yield [AnnotationTarget::class(), AnnotationTarget::TARGET_CLASS]; |
|
|
|
|
|
|
59
|
|
|
yield [AnnotationTarget::method(), AnnotationTarget::TARGET_METHOD]; |
|
60
|
|
|
yield [AnnotationTarget::property(), AnnotationTarget::TARGET_PROPERTY]; |
|
61
|
|
|
yield [AnnotationTarget::annotation(), AnnotationTarget::TARGET_ANNOTATION]; |
|
62
|
|
|
yield [AnnotationTarget::all(), AnnotationTarget::TARGET_ALL]; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return (AnnotationTarget|int)[] |
|
67
|
|
|
*/ |
|
68
|
|
|
public function describeProvider() : iterable |
|
69
|
|
|
{ |
|
70
|
|
|
yield [AnnotationTarget::class(), 'CLASS']; |
|
|
|
|
|
|
71
|
|
|
yield [AnnotationTarget::method(), 'METHOD']; |
|
72
|
|
|
yield [AnnotationTarget::property(), 'PROPERTY']; |
|
73
|
|
|
yield [AnnotationTarget::annotation(), 'ANNOTATION']; |
|
74
|
|
|
yield [AnnotationTarget::all(), 'ALL']; |
|
75
|
|
|
yield [ |
|
76
|
|
|
new AnnotationTarget(AnnotationTarget::TARGET_CLASS | AnnotationTarget::TARGET_ANNOTATION), |
|
77
|
|
|
'CLASS, ANNOTATION', |
|
78
|
|
|
]; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|