Skip to content

Commit 15a9e72

Browse files
authored
Merge pull request #1973 from semsphy/1972-modules-generate-double-separators
Fixes #1972 generate double namspace separators
2 parents 3da6b7c + 79031fa commit 15a9e72

4 files changed

+72
-1
lines changed

src/Generators/ModuleGenerator.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,14 @@ protected function getReplacement($stub): array
486486
}
487487
foreach ($keys as $key) {
488488
if (method_exists($this, $method = 'get'.ucfirst(Str::studly(strtolower($key))).'Replacement')) {
489-
$replaces[$key] = $this->$method();
489+
$replace = $this->$method();
490+
491+
if($stub === 'routes/web' || $stub === 'routes/api' ){
492+
$replace = str_replace('\\\\', '\\', $replace);
493+
}
494+
495+
$replaces[$key] = $replace;
496+
490497
} else {
491498
$replaces[$key] = null;
492499
}

tests/Commands/Make/ModuleMakeCommandTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ public function test_it_generates_web_route_file()
9595
$this->assertSame(0, $code);
9696
}
9797

98+
public function test_it_generates_web_route_file_with_multi_segment_default_namespace()
99+
{
100+
$this->app['config']->set('modules.namespace', 'Custom\Modules');
101+
$files = $this->app['modules']->config('stubs.files');
102+
$code = $this->artisan('module:make', ['name' => ['Blog']]);
103+
104+
$path = $this->modulePath.'/'.$files['routes/web'];
105+
106+
$this->assertMatchesSnapshot($this->finder->get($path));
107+
$this->assertSame(0, $code);
108+
}
109+
98110
public function test_it_generates_api_route_file()
99111
{
100112
$files = $this->app['modules']->config('stubs.files');
@@ -106,6 +118,20 @@ public function test_it_generates_api_route_file()
106118
$this->assertSame(0, $code);
107119
}
108120

121+
public function test_it_generates_api_route_file_with_multi_segment_default_namespace()
122+
{
123+
$this->app['config']->set('modules.namespace', 'Custom\Modules');
124+
$files = $this->app['modules']->config('stubs.files');
125+
126+
$code = $this->artisan('module:make', ['name' => ['Blog']]);
127+
128+
$path = $this->modulePath.'/'.$files['routes/api'];
129+
130+
$this->assertMatchesSnapshot($this->finder->get($path));
131+
$this->assertSame(0, $code);
132+
}
133+
134+
109135
public function test_it_generates_vite_file()
110136
{
111137
$code = $this->artisan('module:make', ['name' => ['Blog']]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Route;
4+
use Custom\Modules\Blog\Http\Controllers\BlogController;
5+
6+
/*
7+
*--------------------------------------------------------------------------
8+
* API Routes
9+
*--------------------------------------------------------------------------
10+
*
11+
* Here is where you can register API routes for your application. These
12+
* routes are loaded by the RouteServiceProvider within a group which
13+
* is assigned the "api" middleware group. Enjoy building your API!
14+
*
15+
*/
16+
17+
Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () {
18+
Route::apiResource('blog', BlogController::class)->names('blog');
19+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Route;
4+
use Custom\Modules\Blog\Http\Controllers\BlogController;
5+
6+
/*
7+
|--------------------------------------------------------------------------
8+
| Web Routes
9+
|--------------------------------------------------------------------------
10+
|
11+
| Here is where you can register web routes for your application. These
12+
| routes are loaded by the RouteServiceProvider within a group which
13+
| contains the "web" middleware group. Now create something great!
14+
|
15+
*/
16+
17+
Route::group([], function () {
18+
Route::resource('blog', BlogController::class)->names('blog');
19+
});

0 commit comments

Comments
 (0)