/**
  * @test
  */
 public function returnsInstanceFromSessionIfPresent()
 {
     $instance = new \stdClass();
     $this->prepareSession(['hasValue' => true, 'value' => $instance]);
     assert($this->sessionScope->getInstance(reflect(\stdClass::class), $this->provider), isSameAs($instance));
     verify($this->provider, 'get')->wasNeverCalled();
 }
 /**
  * @test
  * @dataProvider  throwables
  */
 public function writesMessageAndTraceForInternalException($throwable)
 {
     $displayExceptionHandler = $this->createExceptionHandler('cgi');
     $displayExceptionHandler->handleException($throwable);
     verify($displayExceptionHandler, 'header')->received('Status: 500 Internal Server Error');
     verify($displayExceptionHandler, 'writeBody')->received("failure message\nTrace:\n" . $throwable->getTraceAsString());
 }
 /**
  * @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
  * @dataProvider  throwables
  */
 public function loggingDisabledFillsResponseOnly($throwable)
 {
     $this->exceptionHandler->disableLogging()->handleException($throwable);
     verify($this->exceptionHandler, 'header')->wasCalledOnce();
     verify($this->exceptionHandler, 'createResponseBody')->wasCalledOnce();
     verify($this->exceptionHandler, 'writeBody')->wasCalledOnce();
 }
 /**
  * @test
  * @dataProvider  throwables
  */
 public function returnsContentOfError500FileIfPresent($throwable)
 {
     vfsStream::newFile('docroot/500.html')->withContent('An error occurred')->at($this->root);
     $prodModeExceptionHandler = $this->createExceptionHandler('apache');
     $prodModeExceptionHandler->handleException($throwable);
     verify($prodModeExceptionHandler, 'header')->received('HTTP/1.1 500 Internal Server Error');
     verify($prodModeExceptionHandler, 'writeBody')->received('An error occurred');
 }
 /**
  * @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');
 }
Пример #7
0
 /**
  * @test
  */
 public function handleSignalsResultOfResponsibleErrorHandlerIfErrorReportingDisabled()
 {
     $oldLevel = error_reporting(0);
     try {
         $this->errorHandler1->mapCalls(['isResponsible' => false]);
         $this->errorHandler2->mapCalls(['isResponsible' => true, 'isSupressable' => false, 'handle' => ErrorHandler::STOP_ERROR_HANDLING]);
         assert($this->errorHandlers->handle(1, 'foo'), equals(ErrorHandler::STOP_ERROR_HANDLING));
         verify($this->errorHandler3, 'isResponsible')->wasNeverCalled();
     } finally {
         error_reporting($oldLevel);
     }
 }
 /**
  * @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();
 }
Пример #10
0
 /**
  * @test
  * @group  bug258
  */
 public function hasDnsRecordForIpv6Localhost()
 {
     $checkdnsrr = NewCallable::of('checkdnsrr');
     assertTrue(Uri::fromString('http://[::1]')->hasDnsRecord($checkdnsrr));
     verify($checkdnsrr)->wasNeverCalled();
 }
Пример #11
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
  */
 public function closeClosesDecoratedStream()
 {
     $inputStream = NewInstance::of(InputStream::class);
     $decodingInputStream = new DecodingInputStream($inputStream, 'iso-8859-1');
     $decodingInputStream->close();
     verify($inputStream, 'close')->wasCalledOnce();
 }