}
next($params);
}
- $func = create_function('$matches',
- 'static $p = '.var_export($params, true).'; '.
- '$a = current($p); '.
- 'next($p); '.
- 'return $a;');
+ $params_index = 0;
+ $func = function($matches) use($params, &$params_index) {
+ return $params[$params_index++];
+ };
$url = preg_replace_callback($groups, $func, $url_regex);
}
$url = substr(substr($url, 2), 0, -2);
--- /dev/null
+<?php
+
+class Router_Test extends PHPUnit_Framework_TestCase
+{
+ public function testReverseWithoutParams()
+ {
+ $route = new IPF_Router_RegexMatch('#^/admin/login/$#i');
+ $this->assertEquals($route->reverse([]), "/admin/login/");
+ }
+
+ public function testReverseWithParams()
+ {
+ $route = new IPF_Router_RegexMatch('#^/admin/([\w\_\-]+)/([\w\_\-]+)/([\w\_\-]+)/delete/$#i');
+ $this->assertEquals($route->reverse(['auth', 'user', 123]), "/admin/auth/user/123/delete/");
+ }
+}