'header', 'titi' => 'headers']; $request = new ServerRequest($method, '/', $headers); $controller = new ProxyController(); $this->assertInstanceOf(Controller::class, $controller->setRequest($request)); $this->assertEquals($headers, $controller->getHeaders()); $this->assertTrue($controller->hasHeader('titi')); $this->assertFalse($controller->hasHeader('notexist')); $this->assertEquals(['headers'], $controller->getHeader('titi')); $this->assertEmpty($controller->getHeader('notexist')); } /** * @dataProvider httpMethodProvider() * @param string $method Http Method to be tested */ public function testHttpPostParameters($method) { $parameters = ['toto' => 'header', 'titi' => 'headers']; $request = new ServerRequest($method, '/', $parameters); $request = $request->withParsedBody($parameters); $controller = new ProxyController(); $this->assertInstanceOf(Controller::class, $controller->setRequest($request)); $this->assertEquals($parameters, $controller->getPostParameters()); $this->assertTrue($controller->hasPostParameter('titi')); $this->assertFalse($controller->hasPostParameter('notexist')); $this->assertEquals('headers', $controller->getPostParameter('titi')); $this->assertEmpty($controller->getPostParameter('notexist')); } /** * @dataProvider httpMethodProvider() * @param string $method Http Method to be tested */ public function testHttpGetParameters($method) { $parameters = ['toto' => 'header', 'titi' => 'headers']; $request = new ServerRequest($method, '/', $parameters); $request = $request->withQueryParams($parameters); $controller = new ProxyController(); $this->assertInstanceOf(Controller::class, $controller->setRequest($request)); $this->assertEquals($parameters, $controller->getGetParameters()); $this->assertTrue($controller->hasGetParameter('titi')); $this->assertFalse($controller->hasGetParameter('notexist')); $this->assertEquals('headers', $controller->getGetParameter('titi')); $this->assertEmpty($controller->getGetParameter('notexist')); } /** * @dataProvider httpMethodProvider() * @param string $method Http Method to be tested */ public function testHttpAttributesParameter($method) { $parameters = ['toto' => 'header', 'titi' => 'headers']; $request = new ServerRequest($method, '/', $parameters); foreach ($parameters as $attribute => $value) { $request = $request->withAttribute($attribute, $value); } $controller = new ProxyController(); $this->assertInstanceOf(Controller::class, $controller->setRequest($request)); $this->assertEquals($parameters, $controller->getAttributeParameters()); $this->assertTrue($controller->hasAttributeParameter('titi')); $this->assertFalse($controller->hasAttributeParameter('notexist')); $this->assertEquals('headers', $controller->getAttributeParameter('titi')); $this->assertEmpty($controller->getAttributeParameter('notexist')); } /** * @dataProvider httpMethodProvider() * @param string $method Http Method to be tested */ public function testHttpCookie($method) { $parameters = ['toto' => 'header', 'titi' => 'headers']; $request = new ServerRequest($method, '/', $parameters); $request = $request->withCookieParams($parameters); $controller = new ProxyController(); $this->assertInstanceOf(Controller::class, $controller->setRequest($request)); $this->assertEquals($parameters, $controller->getCookieParams()); $this->assertTrue($controller->hasCookie('titi')); $this->assertFalse($controller->hasCookie('notexist')); $this->assertEquals('headers', $controller->getCookie('titi')); $this->assertEmpty($controller->getCookie('notexist')); } /** * @dataProvider httpMethodProvider() * @param string $method Http Method to be tested */ public function testHttpMethod($method) { $request = new ServerRequest($method, '/'); $controller = new ProxyController(); $this->assertInstanceOf(Controller::class, $controller->setRequest($request)); $this->assertSame($method, $controller->getRequestMethod()); $name = 'isRequest' . $method; $this->assertTrue($controller->$name()); } public function httpMethodProvider() { return [ ['GET'], ['POST'], ['PUT'], ['HEAD'], ['DELETE'], ]; } public function testHttpHelpers() { $request = new ServerRequest( 'GET', '/uri/path?query=string', [ 'content-type' => 'titi', 'user-agent' => 'toto', ], null, '1.1', [ 'HTTP_X_REQUESTED_WITH' => 'xmlhttprequest' ] ); $controller = new ProxyController(); $this->assertInstanceOf(Controller::class, $controller->setRequest($request)); $this->assertTrue($controller->isXmlHttpRequest()); $this->assertEquals(['toto'], $controller->getUserAgent()); $this->assertEquals(['titi'], $controller->getContentType()); $this->assertEquals('/uri/path', $controller->getRequestURI()); $this->assertEquals('query=string', $controller->getQueryString()); } public function testEmptyHttpHelpers() { $request = new ServerRequest('GET', '/'); $controller = new ProxyController(); $this->assertInstanceOf(Controller::class, $controller->setRequest($request)); $this->assertFalse($controller->isXmlHttpRequest()); $this->assertEmpty($controller->getUserAgent()); $this->assertEmpty($controller->getContentType()); $this->assertEquals('/', $controller->getRequestURI()); $this->assertEquals('', $controller->getQueryString()); } }