/** * @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 tellAfterCloseThrowsLogicException() { $this->standardInputStream->close(); expect(function () { $this->standardInputStream->tell(); })->throws(\LogicException::class); }
/** * @test */ public function throwInvalidArgumentExceptionWhenTestValueIsNotOfTypeSequence() { $provides = Provides::values([]); expect(function () use($provides) { $provides->test(new \stdClass()); })->throws(\InvalidArgumentException::class)->withMessage('Given value of type "object" is not an instance of ' . Sequence::class); }
/** * @test */ public function constructionWithObjectThrowsIllegalArgumentException() { $value = value('foo'); expect(function () use($value) { $value->equals(new \stdClass()); })->throws(\InvalidArgumentException::class); }
/** * @test */ public function injectWithInvalidProviderClassThrowsException() { $binder = new Binder(); $binder->bind(Answer::class)->toProviderClass(\stdClass::class); $injector = $binder->getInjector(); expect(function () use($injector) { $injector->getInstance(AnotherQuestion::class); })->throws(BindingException::class); }
/** * @test * @since 4.0.0 */ public function createWithNonEnvironmentThrowsIllegalArgumentException() { expect(function () { new Runtime(new \stdClass()); })->throws(\InvalidArgumentException::class); }
/** * @test */ public function createWithInvalidResourceThrowsIllegalArgumentException() { expect(function () { new Stream('foo'); })->throws(\InvalidArgumentException::class); }
/** * @since 2.0.0 * @test * @dataProvider invalidHttpVersions */ public function deleteWithInvalidHttpVersionThrowsIllegalArgumentException($httpVersion) { expect(function () use($httpVersion) { $this->createHttpRequest()->delete(5, $httpVersion); })->throws(\InvalidArgumentException::class); }
/** * @test */ public function typedMapWithInvalidValueThrowsBindingException() { $binder = new Binder(); $binder->bindList('listConfig'); $binder->bindMap('mapConfig'); $binder->bindMap(Plugin::class)->withEntry('tb', 303); expect(function () use($binder) { $this->createPluginHandler($binder); })->throws(BindingException::class); }
/** * @test * @since 5.4.0 */ public function requestSessionScopedWithoutSessionThrowsRuntimeException() { expect(function () { $this->injector->getInstance(Person2::class); })->throws(\RuntimeException::class); }
/** * @test */ public function invalidBindingModuleThrowsIllegalArgumentException() { expect(function () { App::createInstance(AppClassWithInvalidBindingModule::class, 'projectPath'); })->throws(\InvalidArgumentException::class); }
/** * @test */ public function getReasonPhraseForUnknownStatusCodeThrowsIllegalArgumentException() { expect(function () { Http::reasonPhraseFor(1); })->throws(\InvalidArgumentException::class); }
/** * @test * @since 5.3.0 */ public function throwsInvalidArgumentExceptionWhenBothValueMapperAndKeyMapperAreNull() { expect(function () { new MappingIterator(new \ArrayIterator(['foo', 'bar', 'baz'])); })->throws(\InvalidArgumentException::class); }
/** * @test */ public function throwsRuntimeExceptionWhenCreatedWithoutSession() { expect(function () { $this->sessionScope->getInstance(reflect(\stdClass::class), $this->provider); })->throws(\RuntimeException::class); }
/** * @test */ public function missingConstantBindingOnInjectionHandlingThrowsBindingException() { $injector = Binder::createInjector(); expect(function () use($injector) { $injector->getInstance(MissingArrayInjection::class); })->throws(BindingException::class); }
/** * @test */ public function writeLineToExternalClosedStreamThrowsIOException() { fclose($this->handle); expect(function () { $this->resourceOutputStream->writeLine('foobarbaz'); })->throws(StreamException::class); }
/** * @test */ public function addAcceptableWithPriorityGreaterThan1ThrowsIllegalArgumentException() { expect(function () { $this->acceptHeader->addAcceptable('text/html', 1.1); })->throws(\InvalidArgumentException::class); }
/** * @test * @since 6.0.0 */ public function throwsBindingExceptionWhenNoFallbackSpecifiedAndNoModeSet() { $injector = Binder::createInjector(); expect(function () use($injector) { $injector->getInstance(Person4::class); })->throws(BindingException::class); }
/** * @test */ public function tellOnClosedStreamThrowsIllegalStateException() { $fileInputStream = new FileInputStream(vfsStream::url('home/test.txt')); $fileInputStream->close(); expect(function () use($fileInputStream) { $fileInputStream->tell(); })->throws(\LogicException::class); }
/** * @test * @since 5.0.0 */ public function asClassWithNonExistingClassAndDefaultThrowsReflectionException() { $parse = new Parse('does\\not\\Exist.class'); expect(function () use($parse) { $parse->defaultingTo(__CLASS__ . '.class')->asClass(); })->throws(\ReflectionException::class); }
/** * @since 2.1.0 * @test * @group issue_31 */ public function invalidObjectFromClosureAddedToTypedListThrowsBindingException() { $listBinding = $this->listBinding->withValueFromClosure(function () { return new \stdClass(); }); expect(function () use($listBinding) { $listBinding->getInstance($this->injector, new \ReflectionClass(InjectionProvider::class)); })->throws(BindingException::class); }
/** * @test */ public function throwsBindingExceptionWhenPropertyNotSet() { $properyBinding = $this->createPropertyBinding(); expect(function () use($properyBinding) { $properyBinding->getInstance($this->injector, 'does.not.exist'); })->throws(BindingException::class)->withMessage('Missing property does.not.exist for environment PROD'); }
/** * @test */ public function registerErrorHandlerWithInvalidClassThrowsIllegalArgumentException() { expect(function () { $this->environment->useErrorHandler(404); })->throws(\InvalidArgumentException::class); }
/** * @test * @dataProvider emptyVersions */ public function castFromEmptyWithoutDefaultThrowsIllegalArgumentException($empty) { expect(function () use($empty) { HttpVersion::castFrom($empty); })->throws(\InvalidArgumentException::class)->withMessage('Given HTTP version is empty'); }
/** * @test */ public function addIllegalParamThrowsIllegalArgumentException() { expect(function () { $this->emptyQueryString->addParam('some', new \stdClass()); })->throws(\InvalidArgumentException::class); }
/** * @test * @group ioc_constantprovider * @since 1.6.0 */ public function constantViaInvalidInjectionProviderClassThrowsBindingException() { $binder = new Binder(); $binder->bindConstant('answer')->toProviderClass('\\stdClass'); expect(function () use($binder) { $binder->getInjector()->getConstant('answer'); })->throws(BindingException::class); }
/** * @test */ public function putObjectThrowsIllegalArgumentException() { expect(function () { $this->headerList->put('Binford', new \stdClass()); })->throws(\InvalidArgumentException::class); }
/** * @test */ public function invalidRegexThrowsRuntimeExceptionOnEvaluation() { expect(function () { pattern('^([a-z]{3})$')->matches('foo'); })->throws(\RuntimeException::class)->withMessage('Failure while matching "^([a-z]{3})$", reason: invalid regular expression.'); }
/** * @test * @since 8.0.0 */ public function annotationNameWithInvalidCharactersThrowsReflectionException() { expect(function () { $this->parser->parse('/** * a method with an annotation for its parameter * * @1 */', 'Bar::someMethod()'); })->throws(\ReflectionException::class)->withMessage('Annotation name for Bar::someMethod()@ must start with a' . ' letter or underscore and may contain letters, underscores' . ' and numbers, but contains an invalid character: @1'); }