Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
},
"require-dev": {
"orchestra/testbench": "^9.0 || ^10.0",
"phpunit/phpunit": "^11.0 || ^12.0"
"pestphp/pest": "^3.8",
"pestphp/pest-plugin-type-coverage": "^3.5"
},
"minimum-stability": "stable",
"prefer-stable": true,
Expand All @@ -58,6 +59,7 @@
"dragon-code/codestyler": true,
"ergebnis/composer-normalize": true,
"friendsofphp/php-cs-fixer": true,
"pestphp/pest-plugin": true,
"symfony/thanks": true
},
"preferred-install": "dist",
Expand All @@ -78,7 +80,7 @@
"build": "@php vendor/bin/testbench workbench:build --ansi",
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"test": "@php vendor/bin/phpunit",
"test-coverage": "@test --coverage-text --coverage-html=.build/phpunit/"
"test": "@php vendor/bin/pest --compact",
"test-coverage": "@test --type-coverage"
}
}
13 changes: 13 additions & 0 deletions config/route.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?php

/**
* This file is part of the "dragon-code/laravel-route-names" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <[email protected]>
* @copyright 2025 Andrey Helldar
* @license MIT
*
* @see https://github.com/TheDragonCode/laravel-route-names
*/

declare(strict_types=1);

return [
Expand Down
14 changes: 14 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--~
~ This file is part of the "dragon-code/laravel-route-names" project.
~
~ For the full copyright and license information, please view the LICENSE
~ file that was distributed with this source code.
~
~ @author Andrey Helldar <[email protected]>
~ @copyright 2025 Andrey Helldar
~ @license MIT
~
~ @see https://github.com/TheDragonCode/laravel-route-names
-->

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
Expand Down
13 changes: 13 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?php

/**
* This file is part of the "dragon-code/laravel-route-names" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <[email protected]>
* @copyright 2025 Andrey Helldar
* @license MIT
*
* @see https://github.com/TheDragonCode/laravel-route-names
*/

declare(strict_types=1);

namespace DragonCode\LaravelRouteNames;
Expand Down
13 changes: 13 additions & 0 deletions src/Facades/Action.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?php

/**
* This file is part of the "dragon-code/laravel-route-names" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <[email protected]>
* @copyright 2025 Andrey Helldar
* @license MIT
*
* @see https://github.com/TheDragonCode/laravel-route-names
*/

declare(strict_types=1);

namespace DragonCode\LaravelRouteNames\Facades;
Expand Down
13 changes: 13 additions & 0 deletions src/Facades/Name.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?php

/**
* This file is part of the "dragon-code/laravel-route-names" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <[email protected]>
* @copyright 2025 Andrey Helldar
* @license MIT
*
* @see https://github.com/TheDragonCode/laravel-route-names
*/

declare(strict_types=1);

namespace DragonCode\LaravelRouteNames\Facades;
Expand Down
13 changes: 13 additions & 0 deletions src/Helpers/Action.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?php

/**
* This file is part of the "dragon-code/laravel-route-names" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <[email protected]>
* @copyright 2025 Andrey Helldar
* @license MIT
*
* @see https://github.com/TheDragonCode/laravel-route-names
*/

declare(strict_types=1);

namespace DragonCode\LaravelRouteNames\Helpers;
Expand Down
15 changes: 14 additions & 1 deletion src/Helpers/Name.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?php

/**
* This file is part of the "dragon-code/laravel-route-names" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <[email protected]>
* @copyright 2025 Andrey Helldar
* @license MIT
*
* @see https://github.com/TheDragonCode/laravel-route-names
*/

declare(strict_types=1);

namespace DragonCode\LaravelRouteNames\Helpers;
Expand All @@ -16,7 +29,7 @@ public function get(array $methods, string $uri): string
$suffix = $this->getMethodSuffix($methods, $uri);

return $resolved
->when($this->doesntSame($resolved, $suffix), static fn ($items) => $items->push($suffix))
->when($this->doesntSame($resolved, $suffix), static fn (Collection $items) => $items->push($suffix))
->implode('.');
}

Expand Down
13 changes: 13 additions & 0 deletions src/Providers/RoutingServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?php

/**
* This file is part of the "dragon-code/laravel-route-names" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <[email protected]>
* @copyright 2025 Andrey Helldar
* @license MIT
*
* @see https://github.com/TheDragonCode/laravel-route-names
*/

declare(strict_types=1);

namespace DragonCode\LaravelRouteNames\Providers;
Expand Down
13 changes: 13 additions & 0 deletions src/Routing/Route.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?php

/**
* This file is part of the "dragon-code/laravel-route-names" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <[email protected]>
* @copyright 2025 Andrey Helldar
* @license MIT
*
* @see https://github.com/TheDragonCode/laravel-route-names
*/

declare(strict_types=1);

namespace DragonCode\LaravelRouteNames\Routing;
Expand Down
20 changes: 18 additions & 2 deletions src/Routing/Router.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?php

/**
* This file is part of the "dragon-code/laravel-route-names" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <[email protected]>
* @copyright 2025 Andrey Helldar
* @license MIT
*
* @see https://github.com/TheDragonCode/laravel-route-names
*/

declare(strict_types=1);

namespace DragonCode\LaravelRouteNames\Routing;
Expand All @@ -8,8 +21,11 @@

class Router extends BaseRouter
{
public function newRoute($methods, $uri, $action): Route
{
public function newRoute(
$methods, // @pest-ignore-type
$uri, // @pest-ignore-type
$action // @pest-ignore-type
): Route {
return (new Route($methods, $uri, $action))
->setRouter($this)
->setContainer($this->container);
Expand Down
13 changes: 13 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?php

/**
* This file is part of the "dragon-code/laravel-route-names" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <[email protected]>
* @copyright 2025 Andrey Helldar
* @license MIT
*
* @see https://github.com/TheDragonCode/laravel-route-names
*/

declare(strict_types=1);

namespace DragonCode\LaravelRouteNames;
Expand Down
26 changes: 0 additions & 26 deletions tests/Extenders/RouteNameExtender.php

This file was deleted.

43 changes: 43 additions & 0 deletions tests/Fixtures/Extenders/RouteNameExtender.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/**
* This file is part of the "dragon-code/laravel-route-names" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <[email protected]>
* @copyright 2025 Andrey Helldar
* @license MIT
*
* @see https://github.com/TheDragonCode/laravel-route-names
*/

declare(strict_types=1);

namespace Tests\Fixtures\Extenders;

use DragonCode\LaravelRouteNames\Routing\Route;
use Illuminate\Support\Str;

class RouteNameExtender
{
public function __invoke(string $name, Route $route): string
{
if ($this->has($route->uri())) {
return $this->replace($name);
}

return $name;
}

protected function has(string $uri): bool
{
return Str::of($uri)->startsWith('api/v1');
}

protected function replace(string $name): string
{
return Str::replaceFirst('api.v1', 'api.v2', $name);
}
}
34 changes: 34 additions & 0 deletions tests/Helpers/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* This file is part of the "dragon-code/laravel-route-names" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <[email protected]>
* @copyright 2025 Andrey Helldar
* @license MIT
*
* @see https://github.com/TheDragonCode/laravel-route-names
*/

declare(strict_types=1);

use Illuminate\Routing\Route as RouteCore;
use Illuminate\Support\Facades\Route;
use Workbench\App\Http\Controllers\SomeController;

function routeAction(string $action, string $controller = SomeController::class): ?RouteCore
{
return Route::getRoutes()->getByAction($controller . '@' . $action);
}

function routeName(string $action, string $controller = SomeController::class): string
{
if ($route = routeAction($action, $controller)) {
return $route->getName();
}

throw new RuntimeException(sprintf('Unknown route action: %s@%s.', $controller, $action));
}
20 changes: 20 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* This file is part of the "dragon-code/laravel-route-names" project.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Andrey Helldar <[email protected]>
* @copyright 2025 Andrey Helldar
* @license MIT
*
* @see https://github.com/TheDragonCode/laravel-route-names
*/

declare(strict_types=1);

pest()
->extend(Tests\TestCase::class)
->in('Unit');
Loading