Skip to content

Commit

Permalink
Routes: BC: Use - instead of _ in generated url prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
pionl committed Sep 23, 2022
1 parent 15baa73 commit 49ad8b4
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/Actions/BootServiceProviderAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use LaraStrict\Contracts\HasCustomServiceName;
use LaraStrict\Contracts\RunAppServiceProviderPipesActionContract;
use LaraStrict\Entities\AppServiceProviderEntity;
use LaraStrict\Providers\Pipes\LoadRoutesProviderPipe;
use LaraStrict\Providers\Pipes\LoadProviderRoutesPipe;
use LogicException;
use ReflectionClass;

Expand All @@ -27,7 +27,7 @@ public function execute(Application $application, ServiceProvider $provider): vo

$dir = $this->getRootDirectory($reflection);
$serviceName = $this->getServiceName($reflection, $provider);
$pipes = [LoadRoutesProviderPipe::class];
$pipes = [LoadProviderRoutesPipe::class];

$app = new AppServiceProviderEntity($application, $provider, $serviceName, $dir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use LogicException;
use Psr\Log\LoggerInterface;

class LoadRoutesProviderPipe implements AppServiceProviderPipeContract
class LoadProviderRoutesPipe implements AppServiceProviderPipeContract
{
public function __construct(
private readonly Container $container,
Expand Down Expand Up @@ -177,7 +177,7 @@ protected function makeRoute(): RouteRegistrar

private function getUrlPrefix(string $serviceName, AppServiceProviderEntity $appServiceProvider): string
{
$prefix = Str::plural($serviceName);
$prefix = str_replace('_', '-', Str::plural($serviceName));
return $appServiceProvider->serviceProvider instanceof HasCustomPrefixRoutes
? $appServiceProvider->serviceProvider->getRoutePrefix($prefix)
: $prefix;
Expand Down
20 changes: 10 additions & 10 deletions tests/Feature/Providers/AbstractServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function setUp(): void
public function testBootWithWebOnly(): void
{
$this->assertRoutes($this->app, WithWebServiceProvider::class, [
'GET' => ['with_webs/3_url_web'],
'GET' => ['with-webs/3-url-web'],
]);
}

Expand Down Expand Up @@ -64,32 +64,32 @@ public function testWithoutAnyUrl(): void
public function testWithApiAndWeb(): void
{
$this->assertRoutes($this->app, WithBothServiceProvider::class, [
'GET' => ['api/with_boths/2_url_api', 'with_boths/2_url_web'],
'GET' => ['api/with-boths/2-url-api', 'with-boths/2-url-web'],
]);
}

public function testWithApiOnly(): void
{
$this->assertRoutes($this->app, WithApiServiceProvider::class, [
'GET' => ['api/with_apis/1_api'],
'GET' => ['api/with-apis/1-api'],
]);
}

public function testWithVersionedApiOnly(): void
{
$this->assertRoutes($this->app, WithVersionedApiServiceProvider::class, [
'GET' => ['api/v1/test/1_api', 'api/v2/test/2_api'],
'GET' => ['api/v1/test/1-api', 'api/v2/test/2-api'],
]);
}

public function testWithCustomOnly(): void
{
$this->assertRoutes($this->app, WithCustomServiceProvider::class, [
'GET' => [
'with_customs/1_admin' => function (Route $route) {
'with-customs/1-admin' => function (Route $route) {
$this->assertEquals(['admin'], $route->gatherMiddleware());
},
'dev/with_customs/1_dev' => function (Route $route) {
'dev/with-customs/1-dev' => function (Route $route) {
$this->assertEquals([], $route->gatherMiddleware());
},
],
Expand All @@ -100,16 +100,16 @@ public function testWithAll(): void
{
$this->assertRoutes($this->app, WithAllServiceProvider::class, [
'GET' => [
'api/with_alls/2_url_api' => function (Route $route) {
'api/with-alls/2-url-api' => function (Route $route) {
$this->assertEquals(['api'], $route->gatherMiddleware());
},
'with_alls/2_url_web' => function (Route $route) {
'with-alls/2-url-web' => function (Route $route) {
$this->assertEquals(['web'], $route->gatherMiddleware());
},
'with_alls/1_admin' => function (Route $route) {
'with-alls/1-admin' => function (Route $route) {
$this->assertEquals(['admin'], $route->gatherMiddleware());
},
'dev/with_alls/1_dev' => function (Route $route) {
'dev/with-alls/1-dev' => function (Route $route) {
$this->assertEquals([], $route->gatherMiddleware());
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

use Illuminate\Support\Facades\Route;

Route::get('1_admin', static function () {
Route::get('1-admin', static function () {
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

use Illuminate\Support\Facades\Route;

Route::get('2_url_api', static function () {
Route::get('2-url-api', static function () {
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

use Illuminate\Support\Facades\Route;

Route::get('1_dev', static function () {
Route::get('1-dev', static function () {
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

use Illuminate\Support\Facades\Route;

Route::get('2_url_web', static function () {
Route::get('2-url-web', static function () {
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

use Illuminate\Support\Facades\Route;

Route::get('1_api', static function () {
Route::get('1-api', static function () {
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

use Illuminate\Support\Facades\Route;

Route::get('2_url_api', static function () {
Route::get('2-url-api', static function () {
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

use Illuminate\Support\Facades\Route;

Route::get('2_url_web', static function () {
Route::get('2-url-web', static function () {
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

use Illuminate\Support\Facades\Route;

Route::get('1_admin', static function () {
Route::get('1-admin', static function () {
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

use Illuminate\Support\Facades\Route;

Route::get('1_dev', static function () {
Route::get('1-dev', static function () {
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

use Illuminate\Support\Facades\Route;

Route::get('1_api', static function () {
Route::get('1-api', static function () {
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

use Illuminate\Support\Facades\Route;

Route::get('2_api', static function () {
Route::get('2-api', static function () {
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

use Illuminate\Support\Facades\Route;

Route::get('3_url_web', static function () {
Route::get('3-url-web', static function () {
});
4 changes: 2 additions & 2 deletions tests/Unit/Core/Actions/BootServiceProviderActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Tests\LaraStrict\Unit\Core\Actions;

use LaraStrict\Actions\BootServiceProviderAction;
use LaraStrict\Providers\Pipes\LoadRoutesProviderPipe;
use LaraStrict\Providers\Pipes\LoadProviderRoutesPipe;
use LaraStrict\Testing\Actions\TestRunAppServiceProviderAction;
use LaraStrict\Testing\Laravel\TestingApplication;
use LaraStrict\Testing\Laravel\TestingServiceProvider;
Expand All @@ -16,7 +16,7 @@ class BootServiceProviderActionTest extends TestCase
public function testExecute(): void
{
$runAction = new TestRunAppServiceProviderAction(
expectedPipes: [LoadRoutesProviderPipe::class],
expectedPipes: [LoadProviderRoutesPipe::class],
expectedServiceName: 'laravel', // taken from App\Testing\Laravel namespace
expectServiceRootDirToEndWith: 'src/Testing/Laravel',
);
Expand Down

0 comments on commit 49ad8b4

Please sign in to comment.