FiltersTraitTest.php

<?php

namespace Liaison\Test\Traits;

class Filters extends \Taeluf\Tester {

    public function testFilters(){
        $lia = new \Liaison(['bare'=>true]);

        $randomNumber = 37;
        $catName = 'Bob is a weird name for a cat.';
        $pref = 'a';
        $url = '/';

        $lia->addFilter('Test.Filter.routes', [$this, 'removeFirstRoute'], $catName, $pref);
        $lia->sortFilter('Test.Filter.routes', [$this, 'sortRouteFilters'], $pref);
        $lia->addFilter('Test.Filter.routes', [$this, 'filterRoutes'], $randomNumber);

        $aRoutes = $lia->filter('Test.Filter.routes', ['route1', 'route2', 'route3'], $url);
        $tRoutes = ['route3'];

        return $this->test('FinalCompare')->compare($tRoutes, $aRoutes);
    }
    public function filterRoutes($randomNumber, array $routes, $url){
        $this->test('FilterRoutes')->compare(['route2','route3'],$routes);
        if ($randomNumber==37
            &&$url=='/'
            &&$routes[1]=='route3'
            &&empty($routes[2]))return [$routes[1]];

        return $routes;
    }

    public function removeFirstRoute($catName, $pref, array $routes, $url){
        $this->test('RemoveFirstRoute')->compare(['route1','route2','route3'], $routes);
        if ($routes[0]=='route1')array_shift($routes);
        return $routes;
    }

    public function sortRouteFilters($pref, $routeFilters){
        usort($routeFilters,
            function($a, $b){
                if ($a->funcName=='removeFirstRoute')return -1;
                return 1;
            }
        );
        $this->test('SortFilters')->compare(['removeFirstRoute','filterRoutes'],[$routeFilters[0]->funcName,$routeFilters[1]->funcName]);
        return $routeFilters;
    }

}

Filters::runAll();