function testLoad() { $file = __DIR__ . "/file.php"; file_put_contents($file, "<?php return array('a' => 'b');"); $cache = new Cache($file); $this->assertEquals("b", $cache->get("a")); unset($cache); unlink($file); }
function testMethodNotAllowedMatch() { $this->cache->get("router")->shouldBeCalled()->willReturn(TestResource::expectedTable()); $router = new Router($this->cache->reveal(), new UrlTools()); $resources = array(__NAMESPACE__ . "\\TestResource"); $match = $router->match($resources, "POST", "/this/is/static"); $this->assertEquals(Router::METHOD_NOT_ALLOWED, $match->status, "Match"); $this->assertEquals(array("GET"), $match->allowed, "Allowed"); }
/** * Returns an array containing the compiled routing information based off of * the provided resource objects. * * !!! WARNING !!! This will use the cached version of the table if available * without checking for updates. It is the end users job to ensure that this * cache file is kept updated. * * @param array $resources * @return array */ public function getRoutingTable(array $resources) { if ($table = $this->cache->get("router")) { return $table; } $table = array("static" => array(), "dynamic" => array()); foreach ($resources as $resourceName) { $routes = $this->buildRoutingTableEntryForResource($resourceName); $table["static"] += $routes["static"]; $table["dynamic"] += $routes["dynamic"]; } return $table; }