/** * @test */ public function instanceCreationThrowsBindingExceptionWhenNoPropertiesBound() { $injector = Binder::createInjector(); expect(function () use($injector) { $injector->getInstance(PropertyReceiver::class); })->throws(BindingException::class)->message(startsWith('Can not inject into ' . PropertyReceiver::class . '::__construct($foo).' . ' No binding for type __PROPERTY__ (named "example.foo") specified.')); }
/** * @test */ public function retrieveNonExistingConstantThrowsBindingException() { expect(function () { Binder::createInjector()->getConstant('answer'); })->throws(BindingException::class); }
/** * @test * @group bug226 */ public function annotatedProviderClassIsUsedWhenNoExplicitBindingSpecified() { assert(Binder::createInjector()->getInstance(Person2::class), isInstanceOf(Schst::class)); }
/** * @test */ public function injectorRetrievesNonAddedMapThrowsBindingException() { $injector = Binder::createInjector(); expect(function () use($injector) { $injector->getInstance(MapBinding::TYPE, 'mapConfig'); })->throws(BindingException::class); }
/** * @test * @since 6.0.0 */ public function throwsBindingExceptionWhenNoFallbackSpecifiedAndNoModeSet() { $injector = Binder::createInjector(); expect(function () use($injector) { $injector->getInstance(Person4::class); })->throws(BindingException::class); }
/** * @test * @since 5.1.0 */ public function constructorInjectionWithOptionalSecondParam() { $injector = Binder::createInjector(function (Binder $binder) { $binder->bind(Tire::class)->to(Goodyear::class); }); $bike = $injector->getInstance(BikeWithOptionalOtherParam::class); assert($bike->other, equals('foo')); }