From 58c4dd7ecda91f81ce84d5526e6c20642a907d2c Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 23 Nov 2026 09:50:33 +0900 Subject: [PATCH 1/8] Compile multibinding targets that the module does not bind LazyTo and LazyProvider resolve their target through the injector when the Map is read. Ray\Di\Injector binds a concrete class just in time; CompiledInjector has no script for it and threw Unbound at runtime. Compiler now adds an untargeted binding for each LazyTo/LazyProvider target before building the container, so the target is compiled (and woven) like any bound class. A target that is already bound is left as is. The target class is private in Ray.Di, so it is read by reflection. Fixes #148 --- CHANGELOG.md | 5 ++++ src/Compiler.php | 23 ++++++++++++++++++ .../FakeUnboundTargetMultiBindingsModule.php | 24 +++++++++++++++++++ tests/MultiBindingTest.php | 15 ++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a976b0b..f528f275 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed +- A multibinding target added with `to()` or `toProvider()` resolves without binding it in the module, as with `Ray\Di\Injector` [#148] + ## [1.17.0] - 2026-11-06 ### Changed diff --git a/src/Compiler.php b/src/Compiler.php index 8f791979..e358f2bd 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -9,10 +9,15 @@ use Ray\Di\AbstractModule; use Ray\Di\AcceptInterface; use Ray\Di\Annotation\ScriptDir; +use Ray\Di\Bind; +use Ray\Di\Container; use Ray\Di\ContainerFactory; use Ray\Di\Dependency; use Ray\Di\DependencyInterface; use Ray\Di\DependencyProvider; +use Ray\Di\MultiBinding\LazyProvider; +use Ray\Di\MultiBinding\LazyTo; +use ReflectionProperty; use function assert; use function fclose; @@ -51,6 +56,7 @@ final class Compiler public function compile(AbstractModule $module, string $scriptDir): Scripts { $module->override(new CompilerModule($scriptDir)); + $this->bindMultiBindingTargets($module->getContainer()); $fp = fopen($scriptDir . '/compile.lock', 'a+'); if ($fp === false || ! flock($fp, LOCK_EX)) { @@ -111,4 +117,21 @@ private static function isSingletonDependency(DependencyInterface $dependency): { return ($dependency instanceof Dependency || $dependency instanceof DependencyProvider) && $dependency->isSingleton(); } + + /** LazyTo and LazyProvider resolve their target through the injector at runtime, so the target needs a script */ + private function bindMultiBindingTargets(Container $container): void + { + foreach ($container->multiBindings as $lazyBindings) { + foreach ($lazyBindings as $lazy) { + if (! $lazy instanceof LazyTo && ! $lazy instanceof LazyProvider) { + continue; + } + + /** @var class-string $target */ + $target = (new ReflectionProperty($lazy, 'class'))->getValue($lazy); + // An unbound concrete class becomes an untargeted binding when Bind is destructed + new Bind($container, $target, self::class); + } + } + } } diff --git a/tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php b/tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php new file mode 100644 index 00000000..9ec7d92c --- /dev/null +++ b/tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php @@ -0,0 +1,24 @@ +addBinding('one')->to(FakeEngine::class); + MultiBinder::newInstance($this, FakeRobotInterface::class)->addBinding('provider')->toProvider(FakeRobotProvider::class); + $this->bind(FakeMultiBindingConsumer::class); + } +} diff --git a/tests/MultiBindingTest.php b/tests/MultiBindingTest.php index 735971a1..f4eeacde 100644 --- a/tests/MultiBindingTest.php +++ b/tests/MultiBindingTest.php @@ -8,6 +8,7 @@ use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; use Ray\Compiler\Fake\MultiBindings\FakeMultiBindingsModule; +use Ray\Compiler\Fake\MultiBindings\FakeUnboundTargetMultiBindingsModule; use Ray\Compiler\MultiBindings\FakeEngine; use Ray\Compiler\MultiBindings\FakeEngine2; use Ray\Compiler\MultiBindings\FakeEngineInterface; @@ -142,4 +143,18 @@ public function testSetNotFoundInProvider(): void $this->expectException(SetNotFound::class); $this->injector->getInstance(FakeSetNotFoundWithProvider::class); } + + public function testUnboundTargetIsCompiled(): void + { + $scriptDir = __DIR__ . '/tmp/multi-bindings-unbound-target'; + deleteFiles($scriptDir); + @mkdir($scriptDir); + (new Compiler())->compile(new FakeUnboundTargetMultiBindingsModule(), $scriptDir); + + $consumer = (new CompiledInjector($scriptDir))->getInstance(FakeMultiBindingConsumer::class); + + $this->assertInstanceOf(FakeMultiBindingConsumer::class, $consumer); + $this->assertInstanceOf(FakeEngine::class, $consumer->engines['one']); + $this->assertInstanceOf(FakeRobot::class, $consumer->robots['provider']); + } } From fd2a80fd5af7eec79ddffbd7998aedf273a9b4f0 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 23 Nov 2026 09:52:21 +0900 Subject: [PATCH 2/8] Pin a target with a named dependency and its compile-time failure when unbound --- tests/Fake/MultiBindings/FakeNamedEngine.php | 21 ++++++++++++++++ .../FakeUnboundTargetMultiBindingsModule.php | 14 ++++++++++- tests/MultiBindingTest.php | 24 ++++++++++++++++--- 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 tests/Fake/MultiBindings/FakeNamedEngine.php diff --git a/tests/Fake/MultiBindings/FakeNamedEngine.php b/tests/Fake/MultiBindings/FakeNamedEngine.php new file mode 100644 index 00000000..de9a2d03 --- /dev/null +++ b/tests/Fake/MultiBindings/FakeNamedEngine.php @@ -0,0 +1,21 @@ +addBinding('one')->to(FakeEngine::class); + $engines = MultiBinder::newInstance($this, FakeEngineInterface::class); + $engines->addBinding('one')->to(FakeEngine::class); + $engines->addBinding('named')->to(FakeNamedEngine::class); MultiBinder::newInstance($this, FakeRobotInterface::class)->addBinding('provider')->toProvider(FakeRobotProvider::class); $this->bind(FakeMultiBindingConsumer::class); + if ($this->bindTargetDependency) { + $this->bind()->annotatedWith(FakeNamedEngine::NAME)->toInstance('qiq'); + } } } diff --git a/tests/MultiBindingTest.php b/tests/MultiBindingTest.php index f4eeacde..f96f055d 100644 --- a/tests/MultiBindingTest.php +++ b/tests/MultiBindingTest.php @@ -7,6 +7,7 @@ use LogicException; use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; +use Ray\Compiler\Exception\Unbound; use Ray\Compiler\Fake\MultiBindings\FakeMultiBindingsModule; use Ray\Compiler\Fake\MultiBindings\FakeUnboundTargetMultiBindingsModule; use Ray\Compiler\MultiBindings\FakeEngine; @@ -14,6 +15,7 @@ use Ray\Compiler\MultiBindings\FakeEngineInterface; use Ray\Compiler\MultiBindings\FakeMultiBindingAnnotation; use Ray\Compiler\MultiBindings\FakeMultiBindingConsumer; +use Ray\Compiler\MultiBindings\FakeNamedEngine; use Ray\Compiler\MultiBindings\FakeRobot; use Ray\Compiler\MultiBindings\FakeRobotInterface; use Ray\Compiler\MultiBindings\FakeSetNotFoundWithMap; @@ -146,15 +148,31 @@ public function testSetNotFoundInProvider(): void public function testUnboundTargetIsCompiled(): void { - $scriptDir = __DIR__ . '/tmp/multi-bindings-unbound-target'; - deleteFiles($scriptDir); - @mkdir($scriptDir); + $scriptDir = $this->scriptDir('multi-bindings-unbound-target'); (new Compiler())->compile(new FakeUnboundTargetMultiBindingsModule(), $scriptDir); $consumer = (new CompiledInjector($scriptDir))->getInstance(FakeMultiBindingConsumer::class); $this->assertInstanceOf(FakeMultiBindingConsumer::class, $consumer); $this->assertInstanceOf(FakeEngine::class, $consumer->engines['one']); + $named = $consumer->engines['named']; + $this->assertInstanceOf(FakeNamedEngine::class, $named); + $this->assertSame('qiq', $named->name); $this->assertInstanceOf(FakeRobot::class, $consumer->robots['provider']); } + + public function testUnboundTargetDependencyFailsAtCompileTime(): void + { + $this->expectException(Unbound::class); + (new Compiler())->compile(new FakeUnboundTargetMultiBindingsModule(false), $this->scriptDir('multi-bindings-unbound-dependency')); + } + + private function scriptDir(string $name): string + { + $scriptDir = __DIR__ . '/tmp/' . $name; + deleteFiles($scriptDir); + @mkdir($scriptDir); + + return $scriptDir; + } } From e6f3d62d5ff405dbc3424595b3ec12dc5acd2fff Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 23 Nov 2026 09:52:44 +0900 Subject: [PATCH 3/8] Type the test script dir as non-empty-string --- tests/MultiBindingTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/MultiBindingTest.php b/tests/MultiBindingTest.php index f96f055d..a1554314 100644 --- a/tests/MultiBindingTest.php +++ b/tests/MultiBindingTest.php @@ -167,6 +167,7 @@ public function testUnboundTargetDependencyFailsAtCompileTime(): void (new Compiler())->compile(new FakeUnboundTargetMultiBindingsModule(false), $this->scriptDir('multi-bindings-unbound-dependency')); } + /** @return non-empty-string */ private function scriptDir(string $name): string { $scriptDir = __DIR__ . '/tmp/' . $name; From 18ad9ad8e8d40a96dcfef549915448abe25fe3e0 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 23 Nov 2026 09:53:08 +0900 Subject: [PATCH 4/8] CHANGELOG: an unbound dependency of a multibinding target fails the compile --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f528f275..eb80ba9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed -- A multibinding target added with `to()` or `toProvider()` resolves without binding it in the module, as with `Ray\Di\Injector` [#148] +- A multibinding target added with `to()` or `toProvider()` resolves without binding it in the module, as with `Ray\Di\Injector`; such a target is compiled, so an unbound dependency of it fails the compile [#148] ## [1.17.0] - 2026-11-06 From c6531eeaca2b326f58daa6c4eaeea28bc7b56244 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 23 Nov 2026 09:59:22 +0900 Subject: [PATCH 5/8] Pin that an unbound multibinding target is woven --- .../Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php | 2 ++ tests/MultiBindingTest.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php b/tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php index b4ba247f..02583292 100644 --- a/tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php +++ b/tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php @@ -4,6 +4,7 @@ namespace Ray\Compiler\Fake\MultiBindings; +use Ray\Compiler\FakeDoubleInterceptor; use Ray\Compiler\MultiBindings\FakeEngine; use Ray\Compiler\MultiBindings\FakeEngineInterface; use Ray\Compiler\MultiBindings\FakeMultiBindingConsumer; @@ -29,6 +30,7 @@ protected function configure(): void $engines->addBinding('named')->to(FakeNamedEngine::class); MultiBinder::newInstance($this, FakeRobotInterface::class)->addBinding('provider')->toProvider(FakeRobotProvider::class); $this->bind(FakeMultiBindingConsumer::class); + $this->bindInterceptor($this->matcher->subclassesOf(FakeNamedEngine::class), $this->matcher->any(), [FakeDoubleInterceptor::class]); if ($this->bindTargetDependency) { $this->bind()->annotatedWith(FakeNamedEngine::NAME)->toInstance('qiq'); } diff --git a/tests/MultiBindingTest.php b/tests/MultiBindingTest.php index a1554314..30452193 100644 --- a/tests/MultiBindingTest.php +++ b/tests/MultiBindingTest.php @@ -7,6 +7,7 @@ use LogicException; use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; +use Ray\Aop\WeavedInterface; use Ray\Compiler\Exception\Unbound; use Ray\Compiler\Fake\MultiBindings\FakeMultiBindingsModule; use Ray\Compiler\Fake\MultiBindings\FakeUnboundTargetMultiBindingsModule; @@ -158,6 +159,7 @@ public function testUnboundTargetIsCompiled(): void $named = $consumer->engines['named']; $this->assertInstanceOf(FakeNamedEngine::class, $named); $this->assertSame('qiq', $named->name); + $this->assertInstanceOf(WeavedInterface::class, $named); $this->assertInstanceOf(FakeRobot::class, $consumer->robots['provider']); } From e1199d4e15cd7282e8296e31f217828b51c0f624 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 23 Nov 2026 21:16:00 +0900 Subject: [PATCH 6/8] Reject an unbound multibinding target at compile time instead of binding it Ray.Di 2.24 deprecates just-in-time binding of an unbound concrete class and asks for an explicit binding (ray-di/Ray.Di#337), and promises that a passing compile leaves no JIT dependency. Compiling an unbound LazyTo/LazyProvider target would accept the deprecated form only under CompiledInjector. Compiler now throws Unbound for such a target before compiling, so the failure surfaces at build time. --- CHANGELOG.md | 4 +-- src/Compiler.php | 14 ++++---- tests/Fake/MultiBindings/FakeNamedEngine.php | 21 ------------ .../FakeUnboundTargetMultiBindingsModule.php | 21 +++++------- tests/MultiBindingTest.php | 32 ++++++++----------- 5 files changed, 32 insertions(+), 60 deletions(-) delete mode 100644 tests/Fake/MultiBindings/FakeNamedEngine.php diff --git a/CHANGELOG.md b/CHANGELOG.md index eb80ba9d..1e7150bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -### Fixed -- A multibinding target added with `to()` or `toProvider()` resolves without binding it in the module, as with `Ray\Di\Injector`; such a target is compiled, so an unbound dependency of it fails the compile [#148] +### Changed +- `compile()` throws `Unbound` for a multibinding target added with `to()` or `toProvider()` that the module does not bind. Bind the target explicitly (`$this->bind(Target::class)`), as Ray.Di 2.24 asks for [#148] ## [1.17.0] - 2026-11-06 diff --git a/src/Compiler.php b/src/Compiler.php index e358f2bd..867a1e1c 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -6,10 +6,10 @@ use Ray\Compiler\Exception\CompileLockFailed; use Ray\Compiler\Exception\SingletonRequiresInjectionPoint; +use Ray\Compiler\Exception\Unbound; use Ray\Di\AbstractModule; use Ray\Di\AcceptInterface; use Ray\Di\Annotation\ScriptDir; -use Ray\Di\Bind; use Ray\Di\Container; use Ray\Di\ContainerFactory; use Ray\Di\Dependency; @@ -56,7 +56,7 @@ final class Compiler public function compile(AbstractModule $module, string $scriptDir): Scripts { $module->override(new CompilerModule($scriptDir)); - $this->bindMultiBindingTargets($module->getContainer()); + $this->assertMultiBindingTargetsBound($module->getContainer()); $fp = fopen($scriptDir . '/compile.lock', 'a+'); if ($fp === false || ! flock($fp, LOCK_EX)) { @@ -118,9 +118,10 @@ private static function isSingletonDependency(DependencyInterface $dependency): return ($dependency instanceof Dependency || $dependency instanceof DependencyProvider) && $dependency->isSingleton(); } - /** LazyTo and LazyProvider resolve their target through the injector at runtime, so the target needs a script */ - private function bindMultiBindingTargets(Container $container): void + /** LazyTo and LazyProvider resolve their target through the injector at runtime, which has no just-in-time binding */ + private function assertMultiBindingTargetsBound(Container $container): void { + $bindings = $container->getContainer(); foreach ($container->multiBindings as $lazyBindings) { foreach ($lazyBindings as $lazy) { if (! $lazy instanceof LazyTo && ! $lazy instanceof LazyProvider) { @@ -129,8 +130,9 @@ private function bindMultiBindingTargets(Container $container): void /** @var class-string $target */ $target = (new ReflectionProperty($lazy, 'class'))->getValue($lazy); - // An unbound concrete class becomes an untargeted binding when Bind is destructed - new Bind($container, $target, self::class); + if (! isset($bindings[$target . '-'])) { + throw new Unbound($target . '-'); + } } } } diff --git a/tests/Fake/MultiBindings/FakeNamedEngine.php b/tests/Fake/MultiBindings/FakeNamedEngine.php deleted file mode 100644 index de9a2d03..00000000 --- a/tests/Fake/MultiBindings/FakeNamedEngine.php +++ /dev/null @@ -1,21 +0,0 @@ -addBinding('one')->to(FakeEngine::class); - $engines->addBinding('named')->to(FakeNamedEngine::class); - MultiBinder::newInstance($this, FakeRobotInterface::class)->addBinding('provider')->toProvider(FakeRobotProvider::class); - $this->bind(FakeMultiBindingConsumer::class); - $this->bindInterceptor($this->matcher->subclassesOf(FakeNamedEngine::class), $this->matcher->any(), [FakeDoubleInterceptor::class]); - if ($this->bindTargetDependency) { - $this->bind()->annotatedWith(FakeNamedEngine::NAME)->toInstance('qiq'); + if ($this->provider) { + MultiBinder::newInstance($this, FakeRobotInterface::class)->addBinding('provider')->toProvider(FakeRobotProvider::class); + + return; } + + MultiBinder::newInstance($this, FakeEngineInterface::class)->addBinding('one')->to(FakeEngine::class); } } diff --git a/tests/MultiBindingTest.php b/tests/MultiBindingTest.php index 30452193..147387bc 100644 --- a/tests/MultiBindingTest.php +++ b/tests/MultiBindingTest.php @@ -5,9 +5,9 @@ namespace Ray\Compiler; use LogicException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\TestCase; -use Ray\Aop\WeavedInterface; use Ray\Compiler\Exception\Unbound; use Ray\Compiler\Fake\MultiBindings\FakeMultiBindingsModule; use Ray\Compiler\Fake\MultiBindings\FakeUnboundTargetMultiBindingsModule; @@ -16,9 +16,9 @@ use Ray\Compiler\MultiBindings\FakeEngineInterface; use Ray\Compiler\MultiBindings\FakeMultiBindingAnnotation; use Ray\Compiler\MultiBindings\FakeMultiBindingConsumer; -use Ray\Compiler\MultiBindings\FakeNamedEngine; use Ray\Compiler\MultiBindings\FakeRobot; use Ray\Compiler\MultiBindings\FakeRobotInterface; +use Ray\Compiler\MultiBindings\FakeRobotProvider; use Ray\Compiler\MultiBindings\FakeSetNotFoundWithMap; use Ray\Compiler\MultiBindings\FakeSetNotFoundWithProvider; use Ray\Di\AbstractModule; @@ -147,26 +147,22 @@ public function testSetNotFoundInProvider(): void $this->injector->getInstance(FakeSetNotFoundWithProvider::class); } - public function testUnboundTargetIsCompiled(): void + /** CompiledInjector has no just-in-time binding, so an unbound target would fail only when the Map is read */ + #[DataProvider('unboundTarget')] + public function testUnboundTargetIsRejectedAtCompileTime(bool $provider, string $index): void { - $scriptDir = $this->scriptDir('multi-bindings-unbound-target'); - (new Compiler())->compile(new FakeUnboundTargetMultiBindingsModule(), $scriptDir); - - $consumer = (new CompiledInjector($scriptDir))->getInstance(FakeMultiBindingConsumer::class); - - $this->assertInstanceOf(FakeMultiBindingConsumer::class, $consumer); - $this->assertInstanceOf(FakeEngine::class, $consumer->engines['one']); - $named = $consumer->engines['named']; - $this->assertInstanceOf(FakeNamedEngine::class, $named); - $this->assertSame('qiq', $named->name); - $this->assertInstanceOf(WeavedInterface::class, $named); - $this->assertInstanceOf(FakeRobot::class, $consumer->robots['provider']); + $this->expectException(Unbound::class); + $this->expectExceptionMessage($index); + (new Compiler())->compile(new FakeUnboundTargetMultiBindingsModule($provider), $this->scriptDir('multi-bindings-unbound-target')); } - public function testUnboundTargetDependencyFailsAtCompileTime(): void + /** @return array */ + public static function unboundTarget(): array { - $this->expectException(Unbound::class); - (new Compiler())->compile(new FakeUnboundTargetMultiBindingsModule(false), $this->scriptDir('multi-bindings-unbound-dependency')); + return [ + 'to' => [false, FakeEngine::class . '-'], + 'toProvider' => [true, FakeRobotProvider::class . '-'], + ]; } /** @return non-empty-string */ From 286c158a78ff49f4b68209a5d133174893fa253a Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 23 Nov 2026 21:35:11 +0900 Subject: [PATCH 7/8] Document the unbound multibinding target; pin a qualifier-only binding as unbound --- CHANGELOG.md | 2 +- docs/error/Unbound.md | 16 ++++++++++++++++ .../FakeUnboundTargetMultiBindingsModule.php | 6 +++++- tests/MultiBindingTest.php | 11 ++++++----- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e7150bc..a26bafa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Changed -- `compile()` throws `Unbound` for a multibinding target added with `to()` or `toProvider()` that the module does not bind. Bind the target explicitly (`$this->bind(Target::class)`), as Ray.Di 2.24 asks for [#148] +- `compile()` throws `Unbound` for a class added with `MultiBinder` `to()` or `toProvider()` that has no unnamed binding. Bind it explicitly, e.g. `$this->bind(FooStep::class)`, or the provider class for `toProvider()` [#148] ## [1.17.0] - 2026-11-06 diff --git a/docs/error/Unbound.md b/docs/error/Unbound.md index 006ffb1f..e8ee2b51 100644 --- a/docs/error/Unbound.md +++ b/docs/error/Unbound.md @@ -88,6 +88,22 @@ $this->bind(BarInterface::class)->to(Bar::class); class BarInterface_Bar implements BarInterface ``` +### 4. Unbound Multibinding Target + +`compile()` throws `Unbound` when a class added with `MultiBinder::addBinding()->to()` or `->toProvider()` has no unnamed binding: + +```php +MultiBinder::newInstance($this, StepInterface::class)->addBinding('foo')->to(FooStep::class); +``` + +#### Solution: + +Bind the class itself (the provider class for `toProvider()`): + +```php +$this->bind(FooStep::class); +``` + ## Quick Checklist 1. ✓ Required bindings are defined in your module diff --git a/tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php b/tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php index 189b6e16..6c7ad118 100644 --- a/tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php +++ b/tests/Fake/MultiBindings/FakeUnboundTargetMultiBindingsModule.php @@ -15,7 +15,8 @@ final class FakeUnboundTargetMultiBindingsModule extends AbstractModule { public function __construct( - private bool $provider + private bool $provider, + private bool $qualifiedOnly = false ) { parent::__construct(); } @@ -29,5 +30,8 @@ protected function configure(): void } MultiBinder::newInstance($this, FakeEngineInterface::class)->addBinding('one')->to(FakeEngine::class); + if ($this->qualifiedOnly) { + $this->bind(FakeEngine::class)->annotatedWith('one')->to(FakeEngine::class); + } } } diff --git a/tests/MultiBindingTest.php b/tests/MultiBindingTest.php index 147387bc..b21c1c24 100644 --- a/tests/MultiBindingTest.php +++ b/tests/MultiBindingTest.php @@ -149,19 +149,20 @@ public function testSetNotFoundInProvider(): void /** CompiledInjector has no just-in-time binding, so an unbound target would fail only when the Map is read */ #[DataProvider('unboundTarget')] - public function testUnboundTargetIsRejectedAtCompileTime(bool $provider, string $index): void + public function testUnboundTargetIsRejectedAtCompileTime(bool $provider, bool $qualifiedOnly, string $index): void { $this->expectException(Unbound::class); $this->expectExceptionMessage($index); - (new Compiler())->compile(new FakeUnboundTargetMultiBindingsModule($provider), $this->scriptDir('multi-bindings-unbound-target')); + (new Compiler())->compile(new FakeUnboundTargetMultiBindingsModule($provider, $qualifiedOnly), $this->scriptDir('multi-bindings-unbound-target')); } - /** @return array */ + /** @return array */ public static function unboundTarget(): array { return [ - 'to' => [false, FakeEngine::class . '-'], - 'toProvider' => [true, FakeRobotProvider::class . '-'], + 'to' => [false, false, FakeEngine::class . '-'], + 'toProvider' => [true, false, FakeRobotProvider::class . '-'], + 'bound only with a qualifier' => [false, true, FakeEngine::class . '-'], ]; } From cb9215c76ba3e53ad7699321c4f572dc3ac4658c Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Mon, 23 Nov 2026 22:10:20 +0900 Subject: [PATCH 8/8] Conflict with madapaja/twig-module 2.8.0 too; say to update the module with ray/compiler --- CHANGELOG.md | 2 +- composer.json | 3 ++- docs/error/Unbound.md | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e07af325..d4b2499c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - `compile()` throws `Unbound` for a class added with `MultiBinder` `to()` or `toProvider()` that has no unnamed binding. Bind it explicitly, e.g. `$this->bind(FooStep::class)`, or the provider class for `toProvider()` [#148] -- Conflict with bear/qiq-module 2.1.0–2.1.2, whose `QiqProdModule` does not bind its compile step; update it to 2.1.3 [#148] +- Conflict with bear/qiq-module 2.1.0–2.1.2 and madapaja/twig-module 2.8.0, which do not bind their compile step; update them together with ray/compiler (`composer update ray/compiler bear/qiq-module`) [#148] ## [1.17.1] - 2026-11-23 diff --git a/composer.json b/composer.json index 1969f7d9..9970300e 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "phpunit/phpunit": "^11.5" }, "conflict": { - "bear/qiq-module": ">=2.1.0 <2.1.3" + "bear/qiq-module": ">=2.1.0 <2.1.3", + "madapaja/twig-module": ">=2.8.0 <2.8.1" }, "config": { "sort-packages": true, diff --git a/docs/error/Unbound.md b/docs/error/Unbound.md index e8ee2b51..66511f12 100644 --- a/docs/error/Unbound.md +++ b/docs/error/Unbound.md @@ -110,6 +110,7 @@ $this->bind(FooStep::class); 2. ✓ Compilation was successful 3. ✓ Compiled files exist in the correct location 4. ✓ Paths are consistent between environments +5. ✓ Every `MultiBinder` `to()` / `toProvider()` class is bound ## Related Errors