diff --git a/src/Modules.php b/src/Modules.php index 5480dae0..05544af4 100644 --- a/src/Modules.php +++ b/src/Modules.php @@ -18,12 +18,12 @@ public function getModule(string $name): \Nwidart\Modules\Module public function convertPathToNamespace(string $fullPath): string { - $base = str(trim(config('modules.paths.modules', base_path('Modules')), DIRECTORY_SEPARATOR . '/')); - $relative = str($fullPath)->afterLast($base)->replaceFirst(DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR); + $base = str(trim(config('modules.paths.modules', base_path('Modules')), '/\\')); + $relative = str($fullPath)->afterLast($base)->ltrim('/\\app'); return str($relative) - ->ltrim(DIRECTORY_SEPARATOR . '/') - ->prepend(DIRECTORY_SEPARATOR . '/') + ->ltrim('/\\') + ->prepend(DIRECTORY_SEPARATOR) ->prepend(config('modules.namespace', 'Modules')) ->replace(DIRECTORY_SEPARATOR, '\\') ->replace('\\\\', '\\') diff --git a/tests/Unit/ModulesSingletonTest.php b/tests/Unit/ModulesSingletonTest.php index abb5e141..9e729654 100644 --- a/tests/Unit/ModulesSingletonTest.php +++ b/tests/Unit/ModulesSingletonTest.php @@ -3,9 +3,7 @@ use Coolsam\Modules\Facades\FilamentModules; test('can convert path to namespace correctly', function () { - $path = DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Providers' . DIRECTORY_SEPARATOR . 'AppServiceProvider.php'; - - $path = config('modules.paths.modules') . '/app/Providers/TestServiceProvider.php'; + $path = config('modules.paths.modules') . '\app\Providers\TestServiceProvider.php'; $namespace = FilamentModules::convertPathToNamespace($path); expect($namespace)->toBe($expected = 'Modules\\Providers\\TestServiceProvider', "Expected $expected Instead got " . $namespace); });