Skip to content

Commit d927a3b

Browse files
author
Jonathan
committed
add test
1 parent 88d55db commit d927a3b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Services/PathsAndNamespacesService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function getServiceStubPath(): string
193193

194194
public function getRealpathBaseService(): string
195195
{
196-
return config('crudgen.paths.service.path') ?? $this->getRealpathBase('app'.DIRECTORY_SEPARATOR).'Services';
196+
return config('crudgen.paths.service.path') ?? $this->getRealpathBase('app').DIRECTORY_SEPARATOR.'Services';
197197
}
198198

199199
public function getRealpathBaseCustomService($namingConvention): string

tests/Console/MakeServiceTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Illuminate\Support\Facades\Artisan;
99
use Tests\TestCase;
1010
use Illuminate\Support\Facades\File;
11+
use Illuminate\Config\Repository;
12+
use Illuminate\Support\Arr;
1113

1214
class MakeServiceTest extends TestCase
1315
{
@@ -40,6 +42,26 @@ public function test_create_service_custom_path()
4042
$this->assertSame(preg_replace('/\s+/', '', File::get(__DIR__.DIRECTORY_SEPARATOR.'resultsOk/service/OtherPostService.php')), preg_replace('/\s+/', '', File::get(app_path('Services2/PostService.php'))));
4143
}
4244

45+
public function test_create_service_without_config_file()
46+
{
47+
app()->instance('config', new class extends Repository {
48+
public function unset($key)
49+
{
50+
Arr::forget($this->items, $key);
51+
}
52+
});
53+
54+
config()->unset('crudgen.paths.service.path');
55+
config()->unset('crudgen.paths.service.namespace');
56+
57+
$serviceExisting = array_map(fn($path) => basename($path), glob(app_path('Services/').'*'));
58+
$this->assertCount(0, $serviceExisting);
59+
60+
$this->artisan('make:service', ['service_name'=>"PostService"]);
61+
62+
$this->assertSame(preg_replace('/\s+/', '', File::get(__DIR__.DIRECTORY_SEPARATOR.'resultsOk/service/PostService.php')), preg_replace('/\s+/', '', File::get(app_path('Services/PostService.php'))));
63+
}
64+
4365
public function tearDown():void
4466
{
4567
$this->artisan('rm:service', ['service_name'=>"PostService", "--force"=>true]);

0 commit comments

Comments
 (0)