function createHttpRequestService() { $config = Environment::getConfig('httpRequest'); // params can be taken from config or command line if needed $uri = new UriScript(); $uri->scheme = 'http'; $uri->port = Uri::$defaultPorts['http']; $uri->host = $config->host; $uri->path = $config->path; // $uri->path = '/'; $uri->canonicalize(); $uri->path = String::fixEncoding($uri->path); $uri->scriptPath = '/'; $req = new HttpRequest(); $req->setUri($uri); return $req; }
public function assertRoute(Route $route, $uri, $expectedReq, $expectedUri) { $uri = new UriScript("http://admin.texy.info{$uri}"); $uri->scriptPath = '/'; $uri->appendQuery(array('test' => 'testvalue', 'presenter' => 'querypresenter')); $httpRequest = new HttpRequest(); $httpRequest->initialize(); $httpRequest->setUri($uri); $request = $route->match($httpRequest); if ($request) { // matched $params = $request->getParams(); //asort($params); asort($expectedReq['params']); $this->assertTrue($request->getPresenterName() === $expectedReq['presenter'] && $params === $expectedReq['params']); unset($params['extra']); $request->setParams($params); $result = $route->constructUrl($request, $httpRequest); $result = strncmp($result, 'http://admin.texy.info', 22) ? $result : substr($result, 22); $this->assertEquals($expectedUri, $result); } else { // not matched $this->assertEquals($expectedReq, $request); } }