set( 'example', $service ); self::assertSame( $service, $container->get( 'example' ) ); } public function test_it_reuses_factory_result(): void { $container = new Container(); $calls = 0; $container->factory( 'example', static function () use ( &$calls ): \stdClass { ++$calls; return new \stdClass(); } ); $first = $container->get( 'example' ); $second = $container->get( 'example' ); self::assertSame( $first, $second ); self::assertSame( 1, $calls ); } public function test_it_throws_for_unknown_service(): void { $container = new Container(); $this->expectException( \InvalidArgumentException::class ); $this->expectExceptionMessage( 'Service "missing" is not registered.' ); $container->get( 'missing' ); } }