Example #1
0
 public function testCloseAndException()
 {
     $stream = new Stream('php://memory', 'w+');
     $stream->close();
     $stream->close();
     $this->assertFalse($stream->isWritable());
     $this->assertFalse($stream->isReadable());
     $this->assertFalse($stream->isSeekable());
     $this->assertSame('', $stream->__toString());
     $this->assertNull($stream->getSize());
     $this->assertTrue($stream->eof());
     try {
         $stream->write('...?');
         $this->fail();
     } catch (RuntimeException $e) {
         $this->assertEquals('No resource available.', $e->getMessage());
     }
 }
 /**
  * Set up for testing.
  *
  * @author Benjamin Carl <*****@*****.**>
  */
 protected function setUp()
 {
     // Get a null driver (testing) based instance of cache pool
     $cacheItemPool = new CacheItemPool('Null');
     // Dummy factory One
     $cacheItemFactory = function ($key) {
         return new CacheItem($key);
     };
     // Dummy factory Two
     $cacheItemKeyFactory = function (RequestInterface $request) {
         return sha1(serialize($request));
     };
     // Create instance of CachingMiddleware for testing
     $this->cachingMiddleware = new CachingMiddleware($cacheItemPool, $cacheItemFactory, $cacheItemKeyFactory);
     // Create a default body for testing
     $this->body = new Stream('php://memory', 'w');
     $this->body->write('<html><head><title>Test</title></head><body><h1>Hello World!</h1></body></html>');
     // Create fake next callable
     $this->next = function (Request $request, Response $response) {
         return $response;
     };
     // Map globals for inject in later use
     $this->server = $_SERVER;
     $this->cookie = $_COOKIE;
     $this->request = $_REQUEST;
     $this->files = $_FILES;
 }
 /**
  * Builds response instance with HTML body from HTML passed in.
  *
  * @param string                              $html     HTML used for response body
  * @param \Psr\Http\Message\ResponseInterface $response Response used as base for response
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 protected function buildResponse($html, ResponseInterface $response)
 {
     // @codeCoverageIgnoreStart
     $body = new Stream('php://memory', 'w');
     $body->write($html);
     $response = $response->withBody($body);
     return $response;
     // @codeCoverageIgnoreEnd
 }