diff --git a/src/Support/Container.php b/src/Support/Container.php index 85a5f9d2..fa45f500 100644 --- a/src/Support/Container.php +++ b/src/Support/Container.php @@ -92,6 +92,8 @@ final class Container return $reflectionClass->newInstanceArgs($params); } + + return $reflectionClass->newInstance(); } throw ShouldNotHappen::fromMessage(sprintf('A dependency with the name `%s` cannot be resolved.', $id)); diff --git a/tests/Unit/Support/Container.php b/tests/Unit/Support/Container.php index 33256885..13a369ff 100644 --- a/tests/Unit/Support/Container.php +++ b/tests/Unit/Support/Container.php @@ -18,6 +18,10 @@ it('gets an instance', function () { assertSame($this->container, $this->container->get(Container::class)); }); +test('autowire', function () { + assertInstanceOf(Container::class, $this->container->get(Container::class)); +}); + it('creates an instance and resolves parameters', function () { $this->container->add(Container::class, $this->container); $instance = $this->container->get(ClassWithDependency::class); @@ -39,15 +43,9 @@ it('can resolve builtin value types', function () { assertInstanceOf(TestSuite::class, $instance); }); -it('cannot resolve a parameter that requires additional dependencies', function () { - $this->expectException(ShouldNotHappen::class); - $this->container->get(ClassWithDependency::class); -}); - it('cannot resolve a parameter without type', function () { - $this->expectException(ShouldNotHappen::class); $this->container->get(ClassWithoutTypeParameter::class); -}); +})->throws(ShouldNotHappen::class); class ClassWithDependency {