diff --git a/.github/workflows/on-pull-request.yml b/.github/workflows/on-pull-request.yml index 13c2f3e..5ef21bf 100644 --- a/.github/workflows/on-pull-request.yml +++ b/.github/workflows/on-pull-request.yml @@ -13,11 +13,9 @@ jobs: max-parallel: 3 matrix: php: - - 7.3 - - 7.4 - - 8.0 - 8.1 - 8.2 + - 8.3 name: Test - php:${{ matrix.php }}; composer:${{ matrix.composer }} steps: - name: Checkout diff --git a/composer.json b/composer.json index 40e1817..356230c 100644 --- a/composer.json +++ b/composer.json @@ -4,10 +4,11 @@ "type": "library", "require": { "imponeer/smarty-extensions-contracts": "^3.0", - "php": "^7.3 || ^8.0", - "sunrise/http-router": "^2" + "php": "^8.1", + "sunrise/http-router": "^3" }, "license": "MIT", + "minimum-stability": "beta", "authors": [ { "name": "Raimondas Rimkevičius (aka MekDrop)", 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); }