/**
  * @test
  */
 public function outputStreamGetsPrefix()
 {
     $outputStream = NewInstance::of(OutputStream::class);
     $this->streamFactory->mapCalls(['createOutputStream' => $outputStream]);
     assert($this->prefixedStreamFactory->createOutputStream('foo', ['bar' => 'baz']), isSameAs($outputStream));
     verify($this->streamFactory, 'createOutputStream')->received('prefix/foo', ['bar' => 'baz']);
 }
 /**
  * @test
  */
 public function classAnnotatedWithSingletonWillOnlyBeCreatedOnce()
 {
     $binder = new Binder();
     $binder->bind(Number::class)->to(RandomSingleton::class);
     $slot = $binder->getInjector()->getInstance(SlotMachine::class);
     assert($slot->number1, isInstanceOf(RandomSingleton::class)->and(isSameAs($slot->number2)));
 }
 /**
  * @test
  */
 public function otherScopeIsUsedToCreateInstance()
 {
     $binder = new Binder();
     $instance = new \stdClass();
     $binder->bind(\stdClass::class)->to(\stdClass::class)->in(NewInstance::of(BindingScope::class)->mapCalls(['getInstance' => $instance]));
     assert($binder->getInjector()->getInstance(\stdClass::class), isSameAs($instance));
 }
 /**
  * @test
  */
 public function createsInstanceIfNotPresent()
 {
     $instance = new \stdClass();
     $this->prepareSession(['hasValue' => false]);
     $this->provider->mapCalls(['get' => $instance]);
     assert($this->sessionScope->getInstance(reflect(\stdClass::class), $this->provider), isSameAs($instance));
 }
 /**
  * @test
  */
 public function injectWithProviderInstance()
 {
     $binder = new Binder();
     $answer = new Answer();
     $provider = NewInstance::of(InjectionProvider::class)->mapCalls(['get' => $answer]);
     $binder->bind(Answer::class)->toProvider($provider);
     $question = $binder->getInjector()->getInstance(AnotherQuestion::class);
     assert($question->getAnswer(), isSameAs($answer));
     verify($provider, 'get')->received('answer');
 }
 /**
  * @test
  */
 public function injectWithClosure()
 {
     $binder = new Binder();
     $answer = new Answer();
     $binder->bind(Answer::class)->toClosure(function () use($answer) {
         return $answer;
     });
     $question = $binder->getInjector()->getInstance(AnotherQuestion::class);
     assert($question, isInstanceOf(AnotherQuestion::class));
     assert($question->getAnswer(), isSameAs($answer));
 }
Example #7
0
 /**
  * @test
  * @since  5.1.0
  */
 public function propertyInstanceIsBound()
 {
     assert($this->createInjector()->getInstance(Properties::class, 'config.ini'), isSameAs($this->properties));
 }
 /**
  * @test
  */
 public function castFromInstanceReturnsInstance()
 {
     $httpVersion = new HttpVersion(1, 1);
     assert(HttpVersion::castFrom($httpVersion), isSameAs($httpVersion));
 }
 /**
  * @test
  */
 public function registerErrorHandlerWithInstanceReturnsGivenInstance()
 {
     $errorHandler = NewInstance::of(ErrorHandler::class);
     assert($this->environment->useErrorHandler($errorHandler)->registerErrorHandler('/tmp'), isSameAs($errorHandler));
 }
 /**
  * @test
  * @since  8.0.0
  */
 public function castFromInputStreamReturnsInputStream()
 {
     $inputStream = NewInstance::of(InputStream::class);
     assert(FileInputStream::castFrom($inputStream), isSameAs($inputStream));
 }
Example #11
0
 /**
  * @test
  */
 public function mapResultOfNullReturnsResultOfNull()
 {
     assert(Result::of(null)->map(function ($value) {
         return 909;
     }), isSameAs(Result::of(null)));
 }
 /**
  * @test
  */
 public function usesPassedSessionScope()
 {
     $sessionScope = NewInstance::of(BindingScope::class);
     $bindingScopes = new BindingScopes(null, $sessionScope);
     assert($bindingScopes->session(), isSameAs($sessionScope));
 }
 /**
  * @test
  * @since  5.4.0
  */
 public function setSessionAddsBindingForSessionAsSingleton()
 {
     $session = NewInstance::of(Session::class);
     assert($this->injector->setSession($session, Session::class)->getInstance(Session::class), isSameAs($session));
 }
Example #14
0
 public function assertions() : array
 {
     return [[function (Injector $injector) {
         assertTrue($injector->hasBinding('foo'));
     }], [function (Injector $injector) {
         assertTrue($injector->hasBinding('bar'));
     }], [function (Injector $injector) {
         assertTrue($injector->hasBinding(Injector::class));
     }], [function (Injector $injector) {
         assert($injector->getInstance(Injector::class), isSameAs($injector));
     }]];
 }
Example #15
0
 /**
  * @test
  * @since  4.0.0
  */
 public function bindsEnvironmentProvidedViaCallable()
 {
     $runtime = new Runtime(function () {
         return $this->environment;
     });
     $binder = new Binder();
     $runtime->configure($binder, $this->root->url());
     assert($binder->getInjector()->getInstance(Environment::class), isSameAs($this->environment));
     verify($this->environment, 'registerErrorHandler')->received($this->root->url());
     verify($this->environment, 'registerExceptionHandler')->received($this->root->url());
 }
 /**
  * @test
  * @since  4.0.0
  */
 public function ensureCallableAlwaysReturnsSameClosureForSameFunction()
 {
     assert(ensureCallable('strlen'), isSameAs(ensureCallable('strlen')));
 }