@@ -75,6 +75,63 @@ public function testIsCallable()
75
75
$ this ->assertFalse (Reflector::isCallable (['TotallyMissingClass ' , 'foo ' ]));
76
76
$ this ->assertTrue (Reflector::isCallable (['TotallyMissingClass ' , 'foo ' ], true ));
77
77
}
78
+
79
+ public function testGetClassAttributes ()
80
+ {
81
+ require_once __DIR__ .'/Fixtures/ClassesWithAttributes.php ' ;
82
+
83
+ $ this ->assertSame ([], Reflector::getClassAttributes (Fixtures \ChildClass::class, Fixtures \UnusedAttr::class)->toArray ());
84
+
85
+ $ this ->assertSame (
86
+ [Fixtures \ChildClass::class => [], Fixtures \ParentClass::class => []],
87
+ Reflector::getClassAttributes (Fixtures \ChildClass::class, Fixtures \UnusedAttr::class, true )->toArray ()
88
+ );
89
+
90
+ $ this ->assertSame (
91
+ ['quick ' , 'brown ' , 'fox ' ],
92
+ Reflector::getClassAttributes (Fixtures \ChildClass::class, Fixtures \StrAttr::class)->map ->string ->all ()
93
+ );
94
+
95
+ $ this ->assertSame (
96
+ ['quick ' , 'brown ' , 'fox ' , 'lazy ' , 'dog ' ],
97
+ Reflector::getClassAttributes (Fixtures \ChildClass::class, Fixtures \StrAttr::class, true )->flatten ()->map ->string ->all ()
98
+ );
99
+
100
+ $ this ->assertSame (7 , Reflector::getClassAttributes (Fixtures \ChildClass::class, Fixtures \NumAttr::class)->sum ->number );
101
+ $ this ->assertSame (12 , Reflector::getClassAttributes (Fixtures \ChildClass::class, Fixtures \NumAttr::class, true )->flatten ()->sum ->number );
102
+ $ this ->assertSame (5 , Reflector::getClassAttributes (Fixtures \ParentClass::class, Fixtures \NumAttr::class)->sum ->number );
103
+ $ this ->assertSame (5 , Reflector::getClassAttributes (Fixtures \ParentClass::class, Fixtures \NumAttr::class, true )->flatten ()->sum ->number );
104
+
105
+ $ this ->assertSame (
106
+ [Fixtures \ChildClass::class, Fixtures \ParentClass::class],
107
+ Reflector::getClassAttributes (Fixtures \ChildClass::class, Fixtures \StrAttr::class, true )->keys ()->all ()
108
+ );
109
+
110
+ $ this ->assertContainsOnlyInstancesOf (
111
+ Fixtures \StrAttr::class,
112
+ Reflector::getClassAttributes (Fixtures \ChildClass::class, Fixtures \StrAttr::class)->all ()
113
+ );
114
+
115
+ $ this ->assertContainsOnlyInstancesOf (
116
+ Fixtures \StrAttr::class,
117
+ Reflector::getClassAttributes (Fixtures \ChildClass::class, Fixtures \StrAttr::class, true )->flatten ()->all ()
118
+ );
119
+ }
120
+
121
+ public function testGetClassAttribute ()
122
+ {
123
+ require_once __DIR__ .'/Fixtures/ClassesWithAttributes.php ' ;
124
+
125
+ $ this ->assertNull (Reflector::getClassAttribute (Fixtures \ChildClass::class, Fixtures \UnusedAttr::class));
126
+ $ this ->assertNull (Reflector::getClassAttribute (Fixtures \ChildClass::class, Fixtures \UnusedAttr::class, true ));
127
+ $ this ->assertNull (Reflector::getClassAttribute (Fixtures \ChildClass::class, Fixtures \ParentOnlyAttr::class));
128
+ $ this ->assertInstanceOf (Fixtures \ParentOnlyAttr::class, Reflector::getClassAttribute (Fixtures \ChildClass::class, Fixtures \ParentOnlyAttr::class, true ));
129
+ $ this ->assertInstanceOf (Fixtures \StrAttr::class, Reflector::getClassAttribute (Fixtures \ChildClass::class, Fixtures \StrAttr::class));
130
+ $ this ->assertInstanceOf (Fixtures \StrAttr::class, Reflector::getClassAttribute (Fixtures \ChildClass::class, Fixtures \StrAttr::class, true ));
131
+ $ this ->assertSame ('quick ' , Reflector::getClassAttribute (Fixtures \ChildClass::class, Fixtures \StrAttr::class)->string );
132
+ $ this ->assertSame ('quick ' , Reflector::getClassAttribute (Fixtures \ChildClass::class, Fixtures \StrAttr::class, true )->string );
133
+ $ this ->assertSame ('lazy ' , Reflector::getClassAttribute (Fixtures \ParentClass::class, Fixtures \StrAttr::class)->string );
134
+ }
78
135
}
79
136
80
137
class A
0 commit comments