Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1972 generate double namspace separators #1973

Merged
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
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');
});