|
7 | 7 | use League\Container\Container; |
8 | 8 | use League\Container\Exception\NotFoundException; |
9 | 9 | use League\Container\ReflectionContainer; |
10 | | -use League\Container\Test\Asset\{Foo, FooCallable, Bar}; |
| 10 | +use League\Container\Test\Asset\{Foo, FooCallable, Bar, ProFoo, ProBar}; |
11 | 11 | use PHPUnit\Framework\TestCase; |
12 | 12 |
|
13 | 13 | class ReflectionContainerTest extends TestCase |
@@ -191,4 +191,33 @@ public function testCallResolvesFunction(): void |
191 | 191 | self::assertInstanceOf(Foo::class, $foo); |
192 | 192 | self::assertInstanceOf(Bar::class, $foo->bar); |
193 | 193 | } |
| 194 | + |
| 195 | + public function testGetInstantiatesClassWithConstructorAndSkipsProtectedConstructor(): void |
| 196 | + { |
| 197 | + $classWithConstructor = ProFoo::class; |
| 198 | + |
| 199 | + $container = new Container(); |
| 200 | + $container->delegate(new ReflectionContainer()); |
| 201 | + |
| 202 | + $item = $container->get($classWithConstructor); |
| 203 | + |
| 204 | + $this->assertInstanceOf($classWithConstructor, $item); |
| 205 | + $this->assertNull($item->bar); |
| 206 | + } |
| 207 | + |
| 208 | + public function testGetInstantiatesClassWithConstructorAndUsesFactory(): void |
| 209 | + { |
| 210 | + $classWithConstructor = ProFoo::class; |
| 211 | + $dependencyClass = ProBar::class; |
| 212 | + |
| 213 | + $container = new Container(); |
| 214 | + $container->delegate(new ReflectionContainer()); |
| 215 | + |
| 216 | + $container->add($dependencyClass, [$dependencyClass, 'factory']); |
| 217 | + |
| 218 | + $item = $container->get($classWithConstructor); |
| 219 | + |
| 220 | + $this->assertInstanceOf($classWithConstructor, $item); |
| 221 | + $this->assertInstanceOf($dependencyClass, $item->bar); |
| 222 | + } |
194 | 223 | } |
0 commit comments