-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAttributeReaderTest.php
More file actions
86 lines (71 loc) · 2.44 KB
/
Copy pathAttributeReaderTest.php
File metadata and controls
86 lines (71 loc) · 2.44 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
/*
* This file is part of the Silverback API Components Bundle Project
*
* (c) Daniel West <daniel@silverback.is>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silverback\ApiComponentsBundle\Tests\AttributeReader;
use Doctrine\Persistence\ManagerRegistry;
use PHPUnit\Framework\TestCase;
use Silverback\ApiComponentsBundle\Annotation\Publishable;
use Silverback\ApiComponentsBundle\AttributeReader\PublishableAttributeReader;
/**
* Exercises the shared traversal logic in the abstract AttributeReader through the concrete
* PublishableAttributeReader (isConfigured resolves via reflection only).
*/
class AttributeReaderTest extends TestCase
{
private function buildReader(): PublishableAttributeReader
{
return new PublishableAttributeReader($this->createStub(ManagerRegistry::class));
}
public function test_attribute_declared_directly_on_class_is_found(): void
{
self::assertTrue($this->buildReader()->isConfigured(DirectlyPublishableStub::class));
}
public function test_attribute_declared_on_grandparent_is_found(): void
{
// Kills While_ (line 121) and LogicalNot (line 123): the parent-class walk must climb past the
// intermediate class (no attribute) up to the grandparent that carries it. A broken loop or an
// un-negated condition stops after the first parent and reports "not configured".
self::assertTrue($this->buildReader()->isConfigured(GrandchildOfPublishableStub::class));
}
public function test_attribute_declared_on_trait_is_found(): void
{
// Kills Foreach_ (line 139): the trait walk must iterate the class's traits to find the one
// carrying the attribute.
self::assertTrue($this->buildReader()->isConfigured(UsesPublishableTraitStub::class));
}
public function test_class_without_attribute_anywhere_is_not_configured(): void
{
self::assertFalse($this->buildReader()->isConfigured(NoAttributeAnywhereStub::class));
}
}
#[Publishable]
class DirectlyPublishableStub
{
}
#[Publishable]
class PublishableAncestorStub
{
}
class IntermediateNoAttributeStub extends PublishableAncestorStub
{
}
class GrandchildOfPublishableStub extends IntermediateNoAttributeStub
{
}
#[Publishable]
trait PublishableMarkerTrait
{
}
class UsesPublishableTraitStub
{
use PublishableMarkerTrait;
}
class NoAttributeAnywhereStub
{
}