99use JeroenG \Autowire \Crawler ;
1010use JeroenG \Autowire \Electrician ;
1111use JeroenG \Autowire \Exception \FaultyWiringException ;
12+ use JeroenG \Autowire \Exception \InvalidAttributeException ;
1213use JeroenG \Autowire \Tests \Support \Attributes \CustomAutowire ;
1314use JeroenG \Autowire \Tests \Support \Attributes \CustomConfigure ;
1415use JeroenG \Autowire \Tests \Support \Subject \Contracts \GoodbyeInterface ;
@@ -114,6 +115,31 @@ public function test_it_throws_exception_when_implementation_can_not_be_configur
114115 $ electrician ->configure (GoodbyeInterface::class);
115116 }
116117
118+ /** @dataProvider invalidAutowireAttributeProvider */
119+ public function test_it_throws_an_exception_on_an_invalid_custom_autowire_attribute (string $ invalidAttribute ): void
120+ {
121+ $ crawler = Crawler::in ([SubjectDirectory::ALL ]);
122+
123+ $ this ->expectException (InvalidAttributeException::class);
124+
125+ $ electrician = new Electrician ($ crawler , $ invalidAttribute );
126+ }
127+
128+ public function invalidAutowireAttributeProvider (): \Generator
129+ {
130+ yield 'text ' => [
131+ 'Hello, World! ' ,
132+ ];
133+
134+ yield 'non-attribute class ' => [
135+ HowDoYouDoInterface::class,
136+ ];
137+
138+ yield 'wrong attribute class ' => [
139+ CustomConfigure::class,
140+ ];
141+ }
142+
117143 public function test_it_can_tell_if_class_has_custom_autowire_attribute (): void
118144 {
119145 $ crawler = Crawler::in ([SubjectDirectory::ALL ]);
@@ -133,6 +159,31 @@ public function test_it_can_connect_implementation_with_custom_autowire_attribut
133159 self ::assertEquals (HowDoYouDoInterface::class, $ wire ->interface );
134160 self ::assertEquals (MoonClass::class, $ wire ->implementation );
135161 }
162+
163+ /** @dataProvider invalidConfigureAttributeProvider */
164+ public function test_it_throws_an_exception_on_an_invalid_custom_configure_attribute (string $ invalidAttribute ): void
165+ {
166+ $ crawler = Crawler::in ([SubjectDirectory::ALL ]);
167+
168+ $ this ->expectException (InvalidAttributeException::class);
169+
170+ $ electrician = new Electrician (crawler: $ crawler , configureAttribute: $ invalidAttribute );
171+ }
172+
173+ public function invalidConfigureAttributeProvider (): \Generator
174+ {
175+ yield 'text ' => [
176+ 'Hello, World! ' ,
177+ ];
178+
179+ yield 'non-attribute class ' => [
180+ HowDoYouDoInterface::class,
181+ ];
182+
183+ yield 'wrong attribute class ' => [
184+ CustomAutowire::class,
185+ ];
186+ }
136187
137188 public function test_it_can_tell_if_class_has_custom_configure_attribute (): void
138189 {
0 commit comments