Skip to content

Commit 870fd6a

Browse files
Tests was migrated to Pest
1 parent a267091 commit 870fd6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+788
-306
lines changed

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
},
3838
"require-dev": {
3939
"orchestra/testbench": "^9.0 || ^10.0",
40-
"phpunit/phpunit": "^11.0 || ^12.0"
40+
"pestphp/pest": "^3.8",
41+
"pestphp/pest-plugin-type-coverage": "^3.5"
4142
},
4243
"minimum-stability": "stable",
4344
"prefer-stable": true,
@@ -58,6 +59,7 @@
5859
"dragon-code/codestyler": true,
5960
"ergebnis/composer-normalize": true,
6061
"friendsofphp/php-cs-fixer": true,
62+
"pestphp/pest-plugin": true,
6163
"symfony/thanks": true
6264
},
6365
"preferred-install": "dist",
@@ -78,7 +80,7 @@
7880
"build": "@php vendor/bin/testbench workbench:build --ansi",
7981
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
8082
"prepare": "@php vendor/bin/testbench package:discover --ansi",
81-
"test": "@php vendor/bin/phpunit",
82-
"test-coverage": "@test --coverage-text --coverage-html=.build/phpunit/"
83+
"test": "@php vendor/bin/pest --compact",
84+
"test-coverage": "@test --type-coverage"
8385
}
8486
}

config/route.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
22

3+
/**
4+
* This file is part of the "dragon-code/laravel-route-names" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
* @copyright 2025 Andrey Helldar
11+
* @license MIT
12+
*
13+
* @see https://github.com/TheDragonCode/laravel-route-names
14+
*/
15+
316
declare(strict_types=1);
417

518
return [

phpunit.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--~
4+
~ This file is part of the "dragon-code/laravel-route-names" project.
5+
~
6+
~ For the full copyright and license information, please view the LICENSE
7+
~ file that was distributed with this source code.
8+
~
9+
~ @author Andrey Helldar <[email protected]>
10+
~ @copyright 2025 Andrey Helldar
11+
~ @license MIT
12+
~
13+
~ @see https://github.com/TheDragonCode/laravel-route-names
14+
-->
15+
216
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
317
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
418
bootstrap="vendor/autoload.php"

src/Application.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
22

3+
/**
4+
* This file is part of the "dragon-code/laravel-route-names" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
* @copyright 2025 Andrey Helldar
11+
* @license MIT
12+
*
13+
* @see https://github.com/TheDragonCode/laravel-route-names
14+
*/
15+
316
declare(strict_types=1);
417

518
namespace DragonCode\LaravelRouteNames;

src/Facades/Action.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
22

3+
/**
4+
* This file is part of the "dragon-code/laravel-route-names" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
* @copyright 2025 Andrey Helldar
11+
* @license MIT
12+
*
13+
* @see https://github.com/TheDragonCode/laravel-route-names
14+
*/
15+
316
declare(strict_types=1);
417

518
namespace DragonCode\LaravelRouteNames\Facades;

src/Facades/Name.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
22

3+
/**
4+
* This file is part of the "dragon-code/laravel-route-names" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
* @copyright 2025 Andrey Helldar
11+
* @license MIT
12+
*
13+
* @see https://github.com/TheDragonCode/laravel-route-names
14+
*/
15+
316
declare(strict_types=1);
417

518
namespace DragonCode\LaravelRouteNames\Facades;

src/Helpers/Action.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
22

3+
/**
4+
* This file is part of the "dragon-code/laravel-route-names" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
* @copyright 2025 Andrey Helldar
11+
* @license MIT
12+
*
13+
* @see https://github.com/TheDragonCode/laravel-route-names
14+
*/
15+
316
declare(strict_types=1);
417

518
namespace DragonCode\LaravelRouteNames\Helpers;

src/Helpers/Name.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
22

3+
/**
4+
* This file is part of the "dragon-code/laravel-route-names" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
* @copyright 2025 Andrey Helldar
11+
* @license MIT
12+
*
13+
* @see https://github.com/TheDragonCode/laravel-route-names
14+
*/
15+
316
declare(strict_types=1);
417

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

1831
return $resolved
19-
->when($this->doesntSame($resolved, $suffix), static fn ($items) => $items->push($suffix))
32+
->when($this->doesntSame($resolved, $suffix), static fn (Collection $items) => $items->push($suffix))
2033
->implode('.');
2134
}
2235

src/Providers/RoutingServiceProvider.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
22

3+
/**
4+
* This file is part of the "dragon-code/laravel-route-names" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
* @copyright 2025 Andrey Helldar
11+
* @license MIT
12+
*
13+
* @see https://github.com/TheDragonCode/laravel-route-names
14+
*/
15+
316
declare(strict_types=1);
417

518
namespace DragonCode\LaravelRouteNames\Providers;

src/Routing/Route.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
22

3+
/**
4+
* This file is part of the "dragon-code/laravel-route-names" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
* @copyright 2025 Andrey Helldar
11+
* @license MIT
12+
*
13+
* @see https://github.com/TheDragonCode/laravel-route-names
14+
*/
15+
316
declare(strict_types=1);
417

518
namespace DragonCode\LaravelRouteNames\Routing;

src/Routing/Router.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
22

3+
/**
4+
* This file is part of the "dragon-code/laravel-route-names" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
* @copyright 2025 Andrey Helldar
11+
* @license MIT
12+
*
13+
* @see https://github.com/TheDragonCode/laravel-route-names
14+
*/
15+
316
declare(strict_types=1);
417

518
namespace DragonCode\LaravelRouteNames\Routing;
@@ -8,8 +21,11 @@
821

922
class Router extends BaseRouter
1023
{
11-
public function newRoute($methods, $uri, $action): Route
12-
{
24+
public function newRoute(
25+
$methods, // @pest-ignore-type
26+
$uri, // @pest-ignore-type
27+
$action // @pest-ignore-type
28+
): Route {
1329
return (new Route($methods, $uri, $action))
1430
->setRouter($this)
1531
->setContainer($this->container);

src/ServiceProvider.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<?php
22

3+
/**
4+
* This file is part of the "dragon-code/laravel-route-names" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
* @copyright 2025 Andrey Helldar
11+
* @license MIT
12+
*
13+
* @see https://github.com/TheDragonCode/laravel-route-names
14+
*/
15+
316
declare(strict_types=1);
417

518
namespace DragonCode\LaravelRouteNames;

tests/Extenders/RouteNameExtender.php

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the "dragon-code/laravel-route-names" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
* @copyright 2025 Andrey Helldar
11+
* @license MIT
12+
*
13+
* @see https://github.com/TheDragonCode/laravel-route-names
14+
*/
15+
16+
declare(strict_types=1);
17+
18+
namespace Tests\Fixtures\Extenders;
19+
20+
use DragonCode\LaravelRouteNames\Routing\Route;
21+
use Illuminate\Support\Str;
22+
23+
class RouteNameExtender
24+
{
25+
public function __invoke(string $name, Route $route): string
26+
{
27+
if ($this->has($route->uri())) {
28+
return $this->replace($name);
29+
}
30+
31+
return $name;
32+
}
33+
34+
protected function has(string $uri): bool
35+
{
36+
return Str::of($uri)->startsWith('api/v1');
37+
}
38+
39+
protected function replace(string $name): string
40+
{
41+
return Str::replaceFirst('api.v1', 'api.v2', $name);
42+
}
43+
}

tests/Helpers/routes.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the "dragon-code/laravel-route-names" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
* @copyright 2025 Andrey Helldar
11+
* @license MIT
12+
*
13+
* @see https://github.com/TheDragonCode/laravel-route-names
14+
*/
15+
16+
declare(strict_types=1);
17+
18+
use Illuminate\Routing\Route as RouteCore;
19+
use Illuminate\Support\Facades\Route;
20+
use Workbench\App\Http\Controllers\SomeController;
21+
22+
function routeAction(string $action, string $controller = SomeController::class): ?RouteCore
23+
{
24+
return Route::getRoutes()->getByAction($controller . '@' . $action);
25+
}
26+
27+
function routeName(string $action, string $controller = SomeController::class): string
28+
{
29+
if ($route = routeAction($action, $controller)) {
30+
return $route->getName();
31+
}
32+
33+
throw new RuntimeException(sprintf('Unknown route action: %s@%s.', $controller, $action));
34+
}

tests/Pest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the "dragon-code/laravel-route-names" project.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @author Andrey Helldar <[email protected]>
10+
* @copyright 2025 Andrey Helldar
11+
* @license MIT
12+
*
13+
* @see https://github.com/TheDragonCode/laravel-route-names
14+
*/
15+
16+
declare(strict_types=1);
17+
18+
pest()
19+
->extend(Tests\TestCase::class)
20+
->in('Unit');

0 commit comments

Comments
 (0)