Skip to content

Commit

Permalink
Merge pull request #23 from imponeer/sunrise/http-router-bumped-up-to-v3
Browse files Browse the repository at this point in the history
sunrise/http-router bumped up to v3
  • Loading branch information
MekDrop authored Apr 2, 2024
2 parents e2025dc + 0aed755 commit 043140b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
2 changes: 1 addition & 1 deletion src/UrlFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
30 changes: 15 additions & 15 deletions tests/UrlFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down

0 comments on commit 043140b

Please sign in to comment.