public function testCookiesGetEncrytedDecrypted()
 {
     $request = ServerRequestFactory::fromGlobals(null, null, null, ['cookie1' => 'a value NOT to be encrypted', 'cookie2' => base64_encode('a value that IS encrypted')]);
     $response = new Response();
     $middleware = new EncryptCookies(new Base64CookieEncrypter(), ['cookie1', 'cookie3']);
     $response = $middleware($request, $response, function (RequestInterface $request, ResponseInterface $response) {
         //simply add existing cookies to the response, and add a new one so we can check the encoded cookie is decrypted in the callback
         foreach ($request->getCookieParams() as $key => $value) {
             $response = $response->withCookie($key, $value);
             if ($key == 'cookie2') {
                 $response = $response->withCookie('cookie3', $value);
             }
         }
         return $response;
     });
     $cookie1 = $response->getCookie('cookie1');
     $cookie2 = $response->getCookie('cookie2');
     $cookie3 = $response->getCookie('cookie3');
     $this->assertEquals('a value NOT to be encrypted', $cookie1->getValue());
     $this->assertEquals(base64_encode('a value that IS encrypted'), $cookie2->getValue());
     $this->assertEquals('a value that IS encrypted', $cookie3->getValue());
 }
 public function testCanCreateServerRequestViaFromGlobalsMethod()
 {
     $server = ['SERVER_PROTOCOL' => '1.1', 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'application/json', 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/foo/bar', 'QUERY_STRING' => 'bar=baz'];
     $cookies = $query = $body = $files = ['bar' => 'baz'];
     $cookies['cookies'] = true;
     $query['query'] = true;
     $body['body'] = true;
     $files = ['files' => ['tmp_name' => 'php://temp', 'size' => 0, 'error' => 0, 'name' => 'foo.bar', 'type' => 'text/plain']];
     $expectedFiles = ['files' => new UploadedFile('php://temp', 0, 0, 'foo.bar', 'text/plain')];
     $request = ServerRequestFactory::fromGlobals($server, $query, $body, $cookies, $files);
     $this->assertInstanceOf('Conformity\\Http\\Message\\ServerRequest', $request);
     $this->assertEquals($cookies, $request->getCookieParams());
     $this->assertEquals($query, $request->getQueryParams());
     $this->assertEquals($body, $request->getParsedBody());
     $this->assertEquals($expectedFiles, $request->getUploadedFiles());
     $this->assertEmpty($request->getAttributes());
 }