Router.php

<?php

namespace Liaison\Test\Addon;

class Router extends \Tlf\Tester {

    public function testCacheRoutes(){
        // this test is bunk. The dump prints the object id like Lia\\Package\\Server#38 & this object id is different between different instances so I'm not making useful comparisons.
        $this->disable();
        return;
        $_SERVER['REQUEST_URI'] = '/';
        $dir = $this->file('test/Server');
        $cache_dir = $this->file('test/Server/cache/');

        // how to test (each step is a new lia instance)
        // 1: get the route map without cached routes
        // 2: enable cache & run the server so routes are loaded & then cached. add some routes & get the modified (uncached) route map
        // 3: enable cache, add several routes (which will do nothing), and get the cached routes
        // 4: compare #1 route map to #3 route map (should be same)
        // 5: compare #2 route map to #3 route map (should be different)

        // 1: no cache
        $lia = new \Lia();
        $main = new \Lia\Package\Server($lia, 'server');
        $test = new \Lia\Package\Server($lia, 'site', $dir);
        $lia->cache->dir = $cache_dir;
        $cached_routes = $lia->cache_file('lia:server.router.cached_routes_map','def', -1);
        $lia->router->cache_routes = false;
        $lia->ready();
        $uncached_routes = $lia->router->routeMap;

        // 2: Create cache
        $lia = new \Lia();
        $main = new \Lia\Package\Server($lia, 'server');
        $test = new \Lia\Package\Server($lia, 'site', $dir);
        $lia->cache->dir = $cache_dir;
        $lia->router->cache_routes = true;
        $lia->ready();
        // this prepares the cache
        $response = $lia->getResponse('/', 'GET');
        $f = function(){};
        $lia->addRoute('abc', $f);
        $lia->addRoute('abcd', $f);
        $lia->addRoute('abcde', $f);
        $lia->addRoute('abcdef', $f);
        $modified_routes = $lia->router->routeMap;

        // 3: Use the cache
        $lia = new \Lia();
        $main = new \Lia\Package\Server($lia, 'server');
        $test = new \Lia\Package\Server($lia, 'site', $dir);
        $lia->cache->dir = $cache_dir;
        $lia->router->cache_routes = true;
        $lia->ready();
        // this prepares the cache
        $response = $lia->getResponse('/', 'GET');
        $f = function(){};
        $lia->addRoute('abc', $f);
        $lia->addRoute('abcd', $f);
        $lia->addRoute('abcde', $f);
        $lia->addRoute('abcdef', $f);
        $cached_routes = $lia->router->routeMap;


        // $lia->dump($cached_routes);
        // exit;
        $this->compare_dump($uncached_routes, $cached_routes);
        $this->invert();
        $this->compare_dump($cached_routes, $modified_routes);
        $this->compare_dump($uncached_routes, $modified_routes);
        $this->invert();
    }

}