|
31 | 31 | */ |
32 | 32 | final class ReflectorTest extends TestCase |
33 | 33 | { |
| 34 | + public function testCacheSizeReturnsNumberOfCachedReflectionClasses(): void |
| 35 | + { |
| 36 | + Reflector::clearCache(); |
| 37 | + |
| 38 | + Reflector::shortName(ReflectionFixture::class); |
| 39 | + |
| 40 | + self::assertSame( |
| 41 | + 1, |
| 42 | + Reflector::cacheSize(), |
| 43 | + 'Should return one cached class after first reflection lookup.', |
| 44 | + ); |
| 45 | + |
| 46 | + Reflector::shortName(stdClass::class); |
| 47 | + |
| 48 | + self::assertSame( |
| 49 | + 2, |
| 50 | + Reflector::cacheSize(), |
| 51 | + 'Should increase cache size when reflecting a different class.', |
| 52 | + ); |
| 53 | + } |
| 54 | + |
34 | 55 | public function testClassAttributesReturnsAllClassAttributes(): void |
35 | 56 | { |
36 | 57 | $attributes = Reflector::classAttributes(ReflectionFixture::class); |
@@ -70,6 +91,26 @@ public function testClassAttributesWithFilterReturnsMatchingAttributesOnly(): vo |
70 | 91 | ); |
71 | 92 | } |
72 | 93 |
|
| 94 | + public function testClearCacheEmptiesReflectionClassCache(): void |
| 95 | + { |
| 96 | + Reflector::clearCache(); |
| 97 | + Reflector::shortName(ReflectionFixture::class); |
| 98 | + |
| 99 | + self::assertGreaterThan( |
| 100 | + 0, |
| 101 | + Reflector::cacheSize(), |
| 102 | + 'Should populate cache after reflection usage.', |
| 103 | + ); |
| 104 | + |
| 105 | + Reflector::clearCache(); |
| 106 | + |
| 107 | + self::assertSame( |
| 108 | + 0, |
| 109 | + Reflector::cacheSize(), |
| 110 | + 'Should clear all cached reflection classes.', |
| 111 | + ); |
| 112 | + } |
| 113 | + |
73 | 114 | public function testFirstPropertyAttributeReturnsFirstMatchingAttributeInstance(): void |
74 | 115 | { |
75 | 116 | $attribute = Reflector::firstPropertyAttribute(ReflectionFixture::class, 'name', Label::class); |
@@ -105,6 +146,27 @@ public function testHasPropertyReturnsExpectedResult(): void |
105 | 146 | ); |
106 | 147 | } |
107 | 148 |
|
| 149 | + public function testPropertiesReturnsAllPropertiesWhenFilterIsNull(): void |
| 150 | + { |
| 151 | + $allProperties = Reflector::properties(ReflectionFixture::class); |
| 152 | + $allPropertyNames = []; |
| 153 | + |
| 154 | + foreach ($allProperties as $property) { |
| 155 | + $allPropertyNames[] = $property->getName(); |
| 156 | + } |
| 157 | + |
| 158 | + self::assertContains( |
| 159 | + 'name', |
| 160 | + $allPropertyNames, |
| 161 | + 'Should include public properties when no filter is provided.', |
| 162 | + ); |
| 163 | + self::assertContains( |
| 164 | + 'hidden', |
| 165 | + $allPropertyNames, |
| 166 | + 'Should include private properties when no filter is provided.', |
| 167 | + ); |
| 168 | + } |
| 169 | + |
108 | 170 | public function testPropertiesReturnsFilteredListWhenVisibilityFilterIsProvided(): void |
109 | 171 | { |
110 | 172 | $publicProperties = Reflector::properties(ReflectionFixture::class, ReflectionProperty::IS_PUBLIC); |
|
0 commit comments