public function testGetSetAttributes() { $request = new Request(new Url('http://127.0.0.1'), 'POST'); $request->setAttribute('foo', 'bar'); $this->assertEquals('bar', $request->getAttribute('foo')); $this->assertEquals(null, $request->getAttribute('bar')); $this->assertEquals(array('foo' => 'bar'), $request->getAttributes()); $request->setAttribute('bar', 'foo'); $this->assertEquals('foo', $request->getAttribute('bar')); $this->assertEquals(array('foo' => 'bar', 'bar' => 'foo'), $request->getAttributes()); $request->removeAttribute('bar'); $request->removeAttribute('fooo'); // unknown value $this->assertEquals(null, $request->getAttribute('bar')); }
public static function createRequest(PsrServerRequestInterface $psrRequest) { $request = new Request(new Uri($psrRequest->getUri()), $psrRequest->getMethod(), $psrRequest->getHeaders(), $psrRequest->getBody()); $attributes = $psrRequest->getAttributes(); foreach ($attributes as $name => $value) { $request->setAttribute($name, $value); } return $request; }
public function testDecryptCookieDataChanged() { $request = new Request(new Url('http://localhost'), 'GET', array('Cookie' => 'psx_cookie=eyJmb28iOiJkYXRhIn0=.2IwNbitA6b1VccgR1pGVIRzro4AwYN1IqNXvNHYebog=')); $response = new Response(); $filters = array(); $filters[] = new CookieSigner('secret_key'); $filters[] = function ($request, $response, $filterChain) { $this->assertEquals(array('foo' => 'data'), $request->getAttribute(CookieSigner::COOKIE_NAME)); $request->setAttribute(CookieSigner::COOKIE_NAME, array('foo' => 'foo')); $filterChain->handle($request, $response); }; $filterChain = new FilterChain($filters); $filterChain->handle($request, $response); $this->assertEquals('psx_cookie=eyJmb28iOiJmb28ifQ==.lUT+fW1P+JlRv1+v0MtN7mQ9cx/OK5Jevt3wn/HXsj0=', $response->getHeader('Set-Cookie')); $this->assertEquals(array('foo' => 'foo'), $request->getAttribute(CookieSigner::COOKIE_NAME)); }