11<?php namespace lang \reflection \unittest ;
22
3- use lang \IllegalArgumentException ;
43use lang \reflection \Package ;
4+ use lang \reflection \unittest \fixture \{Instruction , CreateInstruction };
5+ use lang \{Reflection , IllegalArgumentException };
56use test \{Assert , Expect , Test , Values };
67
78class PackageTest {
9+ const FIXTURES = 'lang.reflection.unittest.fixture ' ;
10+
11+ /** @return iterable */
12+ private function instructions () {
13+ yield [Instruction::class, 'class literal ' ];
14+ yield ['lang.reflection.unittest.fixture.Instruction ' , 'class name ' ];
15+ yield [Reflection::type (Instruction::class), 'type ' ];
16+ }
817
918 #[Test, Values(['lang.reflection ' , 'lang\reflection ' , 'lang.reflection. ' ])]
1019 public function name ($ arg ) {
@@ -102,4 +111,30 @@ public function type_via_full_name() {
102111 public function type_with_namespace () {
103112 (new Package ('lang ' ))->type ('util.Date ' );
104113 }
114+
115+ #[Test, Values(from: 'instructions ' )]
116+ public function implementation_by_name ($ type ) {
117+ Assert::equals (
118+ Reflection::type (CreateInstruction::class),
119+ (new Package (self ::FIXTURES ))->implementation ($ type , 'CreateInstruction ' )
120+ );
121+ }
122+
123+ #[Test, Values(from: 'instructions ' )]
124+ public function implementation_by_class ($ type ) {
125+ Assert::equals (
126+ Reflection::type (CreateInstruction::class),
127+ (new Package (self ::FIXTURES ))->implementation ($ type , CreateInstruction::class)
128+ );
129+ }
130+
131+ #[Test, Expect(class: IllegalArgumentException::class, message: '/Given type util.Date is not in package .+/ ' )]
132+ public function implementation_not_in_package () {
133+ (new Package (self ::FIXTURES ))->implementation (Instruction::class, 'util.Date ' );
134+ }
135+
136+ #[Test, Expect(class: IllegalArgumentException::class, message: '/Given type .+ is not an implementation of lang.Runnable/ ' )]
137+ public function not_an_implementation () {
138+ (new Package (self ::FIXTURES ))->implementation ('lang.Runnable ' , 'CreateInstruction ' );
139+ }
105140}
0 commit comments