66use Error ;
77use InvalidArgumentException ;
88use Laragear \Meta \Attr ;
9+ use ReflectionClass ;
910
1011class AttrTest extends TestCase
1112{
13+ public function test_resolves_from_reflection (): void
14+ {
15+ $ attr = Attr::of (new ReflectionClass (StubClass::class));
16+
17+ static ::assertNotEmpty ($ attr );
18+ }
19+
1220 public function test_resolves_from_class_string (): void
1321 {
1422 $ attr = Attr::of (StubClass::class);
@@ -102,6 +110,52 @@ public function test_throws_error_if_attribute_class_does_not_exist(): void
102110 $ attr ->first ('NonExistentAttribute ' );
103111 }
104112
113+ public function test_retrieves_arguments (): void
114+ {
115+ $ attr = Attr::of (StubClass::class);
116+
117+ static ::assertSame (['class ' ], $ attr ->arguments (TestAttribute::class));
118+ }
119+
120+ public function test_retrieves_all_arguments (): void
121+ {
122+ $ attr = Attr::of (StubClass::class);
123+
124+ static ::assertSame ([['class ' ]], $ attr ->allArguments (TestAttribute::class));
125+ }
126+
127+ public function test_emptiness (): void
128+ {
129+ $ attr = Attr::of (StubClass::class);
130+
131+ static ::assertFalse ($ attr ->isEmpty ());
132+ static ::assertTrue ($ attr ->isNotEmpty ());
133+ }
134+
135+ public function test_test_not_emptiness (): void
136+ {
137+ $ attr = Attr::of (StubClassWithoutAttributes::class);
138+
139+ static ::assertTrue ($ attr ->isEmpty ());
140+ static ::assertFalse ($ attr ->isNotEmpty ());
141+ }
142+
143+ public function test_has_given_attribute (): void
144+ {
145+ $ attr = Attr::of (StubClass::class);
146+
147+ static ::assertTrue ($ attr ->has (TestAttribute::class));
148+ static ::assertFalse ($ attr ->has (StubClass::class));
149+ }
150+
151+ public function test_missing_given_attribute (): void
152+ {
153+ $ attr = Attr::of (StubClass::class);
154+
155+ static ::assertFalse ($ attr ->missing (TestAttribute::class));
156+ static ::assertTrue ($ attr ->missing (StubClass::class));
157+ }
158+
105159 public function test_get_retrieves_property_from_attribute (): void
106160 {
107161 $ attr = Attr::of (StubClass::class);
@@ -147,6 +201,19 @@ public function getValue(): string
147201 }
148202}
149203
204+ #[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE )]
205+ class TestRepeatableAttribute
206+ {
207+ public function __construct (public string $ value = 'default ' , public ?string $ second = null )
208+ {
209+ }
210+
211+ public function getValue (): string
212+ {
213+ return $ this ->value ;
214+ }
215+ }
216+
150217#[TestAttribute('class ' )]
151218class StubClass
152219{
@@ -157,6 +224,25 @@ class StubClass
157224 public function stubMethod ()
158225 {
159226 }
227+
228+ public function stubMethodWithoutAttributes ()
229+ {
230+ }
231+
232+ #[TestRepeatableAttribute('first ' )]
233+ #[TestRepeatableAttribute(value: 'second ' )]
234+ #[TestRepeatableAttribute(second: 'test-argument ' , value: 'third ' )]
235+ public function stubMethodWithMultipleAttributes ()
236+ {
237+ }
238+ }
239+
240+ class StubClassWithoutAttributes
241+ {
242+ #[TestAttribute('method ' )]
243+ public function stubMethod ()
244+ {
245+ }
160246}
161247
162248#[TestAttribute('function ' )]
0 commit comments