Skip to content

Commit

Permalink
Fixes #1972 modules:make generate double separator
Browse files Browse the repository at this point in the history
  • Loading branch information
semsphy committed Nov 4, 2024
1 parent fb1f6bd commit 79031fa
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Generators/ModuleGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,14 @@ protected function getReplacement($stub): array
}
foreach ($keys as $key) {
if (method_exists($this, $method = 'get'.ucfirst(Str::studly(strtolower($key))).'Replacement')) {
$replaces[$key] = $this->$method();
$replace = $this->$method();

if($stub === 'routes/web' || $stub === 'routes/api' ){
$replace = str_replace('\\\\', '\\', $replace);
}

$replaces[$key] = $replace;

} else {
$replaces[$key] = null;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/Commands/Make/ModuleMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ public function test_it_generates_web_route_file()
$this->assertSame(0, $code);
}

public function test_it_generates_web_route_file_with_multi_segment_default_namespace()
{
$this->app['config']->set('modules.namespace', 'Custom\Modules');
$files = $this->app['modules']->config('stubs.files');
$code = $this->artisan('module:make', ['name' => ['Blog']]);

$path = $this->modulePath.'/'.$files['routes/web'];

$this->assertMatchesSnapshot($this->finder->get($path));
$this->assertSame(0, $code);
}

public function test_it_generates_api_route_file()
{
$files = $this->app['modules']->config('stubs.files');
Expand All @@ -106,6 +118,20 @@ public function test_it_generates_api_route_file()
$this->assertSame(0, $code);
}

public function test_it_generates_api_route_file_with_multi_segment_default_namespace()
{
$this->app['config']->set('modules.namespace', 'Custom\Modules');
$files = $this->app['modules']->config('stubs.files');

$code = $this->artisan('module:make', ['name' => ['Blog']]);

$path = $this->modulePath.'/'.$files['routes/api'];

$this->assertMatchesSnapshot($this->finder->get($path));
$this->assertSame(0, $code);
}


public function test_it_generates_vite_file()
{
$code = $this->artisan('module:make', ['name' => ['Blog']]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Illuminate\Support\Facades\Route;
use Custom\Modules\Blog\Http\Controllers\BlogController;

/*
*--------------------------------------------------------------------------
* API Routes
*--------------------------------------------------------------------------
*
* Here is where you can register API routes for your application. These
* routes are loaded by the RouteServiceProvider within a group which
* is assigned the "api" middleware group. Enjoy building your API!
*
*/

Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () {
Route::apiResource('blog', BlogController::class)->names('blog');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Illuminate\Support\Facades\Route;
use Custom\Modules\Blog\Http\Controllers\BlogController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::group([], function () {
Route::resource('blog', BlogController::class)->names('blog');
});

0 comments on commit 79031fa

Please sign in to comment.