From 0aed75584f159849fb7c7fe5e152847b389ecf46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raimondas=20Rimkevi=C4=8Dius?= Date: Tue, 2 Apr 2024 06:54:37 +0300 Subject: [PATCH] Fixed passing tests --- src/UrlFunction.php | 2 +- tests/UrlFunctionTest.php | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/UrlFunction.php b/src/UrlFunction.php index 6796cc4..b8ea920 100644 --- a/src/UrlFunction.php +++ b/src/UrlFunction.php @@ -55,6 +55,6 @@ public function execute($params, Smarty_Internal_Template $template) throw new SmartyException('name not set for url function'); } - return $this->router->generateUri($params['name'], $attributes); + return $this->router->buildRoute($params['name'], $attributes); } } \ No newline at end of file diff --git a/tests/UrlFunctionTest.php b/tests/UrlFunctionTest.php index 0139a0f..722806a 100644 --- a/tests/UrlFunctionTest.php +++ b/tests/UrlFunctionTest.php @@ -2,10 +2,9 @@ use Imponeer\Smarty\Extensions\SunriseHTTPRouter\UrlFunction; use PHPUnit\Framework\TestCase; -use Sunrise\Http\Router\Exception\MissingAttributeValueException; -use Sunrise\Http\Router\Exception\RouteNotFoundException; +use Sunrise\Http\Router\Exception\InvalidRouteBuildingValueException; +use Sunrise\Http\Router\Exception\NoRouteFoundException; use Sunrise\Http\Router\Route; -use Sunrise\Http\Router\RouteCollector; use Sunrise\Http\Router\Router; class UrlFunctionTest extends TestCase @@ -21,17 +20,18 @@ class UrlFunctionTest extends TestCase protected function setUp(): void { - $collector = new RouteCollector(); - $collector->get("home", "/", function ($request) { - return "test"; - }); - $collector->get("test", "/test/{a}", function ($request) { - return "test 2"; - }); - - $router = new Router(); + $router = new Sunrise\Http\Router\Router(); $router->addRoute( - ...$collector->getCollection()->all() + new Route("home", "/", function ($request) { + return "test"; + }, [ + "GET" + ]), + new Route("test", "/test/{a}", function ($request) { + return "test 2"; + }, [ + "GET" + ]), ); $this->plugin = new UrlFunction($router); @@ -63,7 +63,7 @@ public function testInvokingWithCorrectAttributes() { public function testInvokingWithIncorrectAttributes() { $src = urlencode('{url name="test" attributes=["b" => "x"]}'); - $this->expectException(MissingAttributeValueException::class); + $this->expectException(InvalidRouteBuildingValueException::class); $this->smarty->fetch('eval:urlencode:'.$src); } @@ -76,7 +76,7 @@ public function testInvokingWithoutAttributes() { public function testInvokingWithInvalidRouteName() { $src = urlencode('{url name="home2"}'); - $this->expectException(RouteNotFoundException::class); + $this->expectException(NoRouteFoundException::class); $this->smarty->fetch('eval:urlencode:'.$src); }