/** * Test that router returns matched routes based on URI only, not * based on the HTTP method. */ public function testRouterMatchesRoutesByUriOnly() { Slim_Environment::mock(array('REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '', 'PATH_INFO' => '/foo', 'QUERY_STRING' => 'one=1&two=2&three=3', 'SERVER_NAME' => 'slim', 'SERVER_PORT' => 80, 'slim.url_scheme' => 'http', 'slim.input' => '', 'slim.errors' => fopen('php://stderr', 'w'), 'HTTP_HOST' => 'slim')); $this->env = Slim_Environment::getInstance(); $this->req = new Slim_Http_Request($this->env); $this->res = new Slim_Http_Response(); $router = new Slim_Router($this->req, $this->res); $router->map('/foo', function () { })->via('GET'); $router->map('/foo', function () { })->via('POST'); $router->map('/foo', function () { })->via('PUT'); $router->map('/foo/bar/xyz', function () { })->via('DELETE'); $this->assertEquals(3, count($router->getMatchedRoutes())); }
/** * Test valid resource handle to php://stdErr */ public function testErrorResource() { $env = Slim_Environment::getInstance(true); $this->assertTrue(is_resource($env['slim.errors'])); }
public function testDispatchWithoutCallable() { Slim_Environment::mock(array('REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '', 'PATH_INFO' => '/hello/josh', 'QUERY_STRING' => 'one=1&two=2&three=3', 'SERVER_NAME' => 'slim', 'SERVER_PORT' => 80, 'slim.url_scheme' => 'http', 'slim.input' => '', 'slim.errors' => fopen('php://stderr', 'w'), 'HTTP_HOST' => 'slim')); $env = Slim_Environment::getInstance(); $req = new Slim_Http_Request($env); $res = new Slim_Http_Response(); $router = new Slim_Router($req, $res); $route = new Slim_Route('/hello/:name', 'foo'); $route->setRouter($router); $route->matches($req->getResourceUri()); //<-- Extracts params from resource URI $this->assertFalse($route->dispatch()); }
/** * Constructor * @param array $userSettings Key-Value array of application settings * @return void */ public function __construct($userSettings = array()) { //Setup Slim application $this->environment = Slim_Environment::getInstance(); $this->request = new Slim_Http_Request($this->environment); $this->response = new Slim_Http_Response(); $this->router = new Slim_Router($this->request->getResourceUri()); $this->settings = array_merge(self::getDefaultSettings(), $userSettings); $this->middleware = array($this); $this->add(new Slim_Middleware_Flash()); $this->add(new Slim_Middleware_MethodOverride()); //Determine application mode $this->getMode(); //Setup view $this->view($this->config('view')); //Make default if first instance if (is_null(self::getInstance())) { $this->setName('default'); } //Set default logger that writes to stderr (may be overridden with middleware) $logWriter = $this->config('log.writer'); if (!$logWriter) { $logWriter = new Slim_LogWriter($this->environment['slim.errors']); } $log = new Slim_Log($logWriter); $log->setEnabled($this->config('log.enabled')); $log->setLevel($this->config('log.level')); $this->environment['slim.log'] = $log; //Set global error handler set_error_handler(array('Slim', 'handleErrors')); }
public function __construct() { $this->environment = Slim_Environment::getInstance(); }
/** * Test get refererer */ public function testGetUserAgentWhenNotExists() { $env = Slim_Environment::getInstance(); $req = new Slim_Http_Request($env); $this->assertNull($req->getUserAgent()); }