/**
  * @test
  */
 public function closeCallsDecoratedStream()
 {
     $inputStream = NewInstance::of(InputStream::class);
     $decoratedInputStream = $this->createDecoratedInputStream($inputStream);
     $decoratedInputStream->close();
     verify($inputStream, 'close')->wasCalledOnce();
 }
 /**
  * @test
  */
 public function closeClosesDecoratedOutputStream()
 {
     $outputStream = NewInstance::of(OutputStream::class);
     $encodingOutputStream = new EncodingOutputStream($outputStream, 'iso-8859-1');
     $encodingOutputStream->close();
     verify($outputStream, 'close')->wasCalledOnce();
 }
 /**
  * @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 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));
 }
Exemplo n.º 5
0
 /**
  * set up test environment
  */
 public function setUp()
 {
     $this->memory = '';
     $socket = NewInstance::stub(Stream::class)->mapCalls(['write' => function (string $line) {
         $this->memory .= $line;
         return strlen($line);
     }]);
     $httpUri = NewInstance::stub(HttpUri::class)->mapCalls(['openSocket' => $socket, 'path' => '/foo/resource', 'hostname' => 'example.com', 'hasQueryString' => true, 'queryString' => 'foo=bar']);
     $this->httpConnection = new HttpConnection($httpUri);
 }
Exemplo n.º 6
0
 /**
  * set up test environment
  */
 public function setUp()
 {
     $this->errorHandlers = new ErrorHandlers();
     $this->errorHandler1 = NewInstance::of(ErrorHandler::class);
     $this->errorHandlers->addErrorHandler($this->errorHandler1);
     $this->errorHandler2 = NewInstance::of(ErrorHandler::class);
     $this->errorHandlers->addErrorHandler($this->errorHandler2);
     $this->errorHandler3 = NewInstance::of(ErrorHandler::class);
     $this->errorHandlers->addErrorHandler($this->errorHandler3);
 }
 /**
  * @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 canNotRewindNonSeekableInputStream()
 {
     $inputStream = NewInstance::of(InputStream::class)->mapCalls(['readLine' => onConsecutiveCalls('foo', 'bar', 'baz', ''), 'eof' => onConsecutiveCalls(false, false, true, true)]);
     $lines = linesOf($inputStream);
     foreach ($lines as $lineNumber => $line) {
         // do nothing
     }
     $content = [];
     foreach (linesOf($inputStream) as $lineNumber => $line) {
         $content[$lineNumber] = $line;
     }
     assertEmptyArray($content);
 }
Exemplo n.º 9
0
 /**
  * creates instance to test
  *
  * @param   string  $queryString
  * @return  HttpRequest
  */
 private function createHttpRequest(string $queryString = null) : HttpRequest
 {
     $socket = NewInstance::stub(Stream::class)->mapCalls(['write' => function (string $line) {
         $this->memory .= $line;
         return strlen($line);
     }]);
     $uriCalls = ['openSocket' => $socket, 'path' => '/foo/resource', 'hostname' => 'example.com'];
     if (null !== $queryString) {
         $uriCalls['hasQueryString'] = true;
         $uriCalls['queryString'] = $queryString;
     } else {
         $uriCalls['hasQueryString'] = false;
     }
     return HttpRequest::create(NewInstance::stub(HttpUri::class)->mapCalls($uriCalls), new HeaderList(['X-Binford' => 6100]));
 }
Exemplo n.º 10
0
 /**
  * creates instance to test
  *
  * @return  \stubbles\environments\exceptionhandler\DisplayExceptionHandler
  */
 public function createExceptionHandler($sapi)
 {
     $displayExceptionHandler = NewInstance::of(DisplayException::class, ['/tmp', $sapi])->mapCalls(['header' => false, 'writeBody' => false]);
     return $displayExceptionHandler->disableLogging();
 }
 /**
  * set up test environment
  */
 public function setUp()
 {
     $this->root = vfsStream::setup();
     $this->exceptionHandler = NewInstance::of(AbstractExceptionHandler::class, [vfsStream::url('root')])->mapCalls(['header' => null, 'createResponseBody' => '', 'writeBody' => null]);
 }
Exemplo n.º 12
0
 /**
  * set up test environment
  */
 public function setUp()
 {
     $this->injector = NewInstance::of(Injector::class);
 }
Exemplo n.º 13
0
 /**
  * creates mocked provider
  *
  * @param   mixed  $value
  * @return  \stubbles\ioc\InjectionProvider
  */
 private function createProviderForValue($value) : InjectionProvider
 {
     return NewInstance::of(InjectionProvider::class)->mapCalls(['get' => $value]);
 }
Exemplo n.º 14
0
 /**
  * @test
  * @since  3.4.0
  */
 public function bindsPropertiesWhenConfigFilePresent()
 {
     vfsStream::newFile('config/config.ini')->withContent("[config]\nstubbles.locale=\"de_DE\"\nstubbles.number.decimals=4\nstubbles.webapp.xml.serializeMode=true")->at($this->root);
     $binder = NewInstance::of(Binder::class);
     $runtime = new Runtime($this->environment);
     $runtime->configure($binder, $this->root->url());
     verify($binder, 'bindProperties')->wasCalledOnce();
 }
 /**
  * @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));
 }
 /**
  * @test
  * @since  8.0.0
  */
 public function castFromInputStreamReturnsInputStream()
 {
     $inputStream = NewInstance::of(InputStream::class);
     assert(FileInputStream::castFrom($inputStream), isSameAs($inputStream));
 }
Exemplo n.º 17
0
 /**
  * @test
  * @since  7.0.0
  */
 public function openLocalResourceWithOtherUsesOther()
 {
     $myClass = NewInstance::classname(FileInputStream::class);
     assert($this->resourceLoader->open('lang/stubbles.ini', $myClass), isInstanceOf($myClass));
 }
Exemplo n.º 18
0
 /**
  * @test
  */
 public function usesPassedSessionScope()
 {
     $sessionScope = NewInstance::of(BindingScope::class);
     $bindingScopes = new BindingScopes(null, $sessionScope);
     assert($bindingScopes->session(), isSameAs($sessionScope));
 }
 /**
  * @test
  */
 public function closeClosesDecoratedStream()
 {
     $inputStream = NewInstance::of(InputStream::class);
     $decodingInputStream = new DecodingInputStream($inputStream, 'iso-8859-1');
     $decodingInputStream->close();
     verify($inputStream, 'close')->wasCalledOnce();
 }
Exemplo n.º 20
0
 /**
  * @test
  */
 public function registerErrorHandlerWithInstanceReturnsGivenInstance()
 {
     $errorHandler = NewInstance::of(ErrorHandler::class);
     assert($this->environment->useErrorHandler($errorHandler)->registerErrorHandler('/tmp'), isSameAs($errorHandler));
 }
Exemplo n.º 21
0
 /**
  * @test
  */
 public function addInvalidProviderClassThrowsBindingException()
 {
     $providerClass = get_class(NewInstance::of(InjectionProvider::class));
     $this->injector->mapCalls(['getInstance' => \stdClass::class]);
     $listBinding = $this->listBinding->withValueFromProvider($providerClass);
     expect(function () use($listBinding) {
         $listBinding->getInstance($this->injector, new \ReflectionClass(InjectionProvider::class));
     })->throws(BindingException::class);
 }
 /**
  * creates instance to test
  *
  * @return  stubbles\environments\exceptionhandler\ProdModExceptionHandler
  */
 public function createExceptionHandler($sapi)
 {
     $prodModeExceptionHandler = NewInstance::of(ProdModeExceptionHandler::class, [vfsStream::url('root'), $sapi])->mapCalls(['header' => false, 'writeBody' => false]);
     return $prodModeExceptionHandler->disableLogging();
 }
 /**
  * set up test enviroment
  */
 public function setUp()
 {
     $this->session = NewInstance::of(Session::class);
     $this->sessionScope = new SessionBindingScope();
     $this->provider = NewInstance::of(InjectionProvider::class);
 }
Exemplo n.º 24
0
 /**
  * @test
  * @group  ioc_constantprovider
  * @since  1.6.0
  */
 public function constantViaInjectionProviderInstance()
 {
     $binder = new Binder();
     $binder->bindConstant('answer')->toProvider(NewInstance::of(InjectionProvider::class)->mapCalls(['get' => 42]));
     $injector = $binder->getInjector();
     assertTrue($injector->hasConstant('answer'));
     assert($injector->getConstant('answer'), equals(42));
     $this->assertConstantInjection($binder->getInjector());
 }
Exemplo n.º 25
0
 /**
  * @test
  * @since  8.0.0
  */
 public function appendCreatesNewCombinedSequenceFromInitialIteratorAggregate()
 {
     $iteratorAggregate = NewInstance::of(\IteratorAggregate::class)->mapCalls(['getIterator' => new \ArrayIterator([1, 2])]);
     assert(Sequence::of($iteratorAggregate)->append([3, 4]), Provides::values([1, 2, 3, 4]));
 }