diff --git a/Test/Microservices/DataThing/resources/views/welcome.blade.php b/Test/Microservices/DataThing/resources/views/welcome.blade.php
new file mode 100644
index 0000000..936395c
--- /dev/null
+++ b/Test/Microservices/DataThing/resources/views/welcome.blade.php
@@ -0,0 +1,17 @@
+
+
+
+
+
+ Enjoy your new Laraca generated service!
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Test/Microservices/New_Object/resources/views/welcome.blade.php b/Test/Microservices/New_Object/resources/views/welcome.blade.php
new file mode 100644
index 0000000..38b324b
--- /dev/null
+++ b/Test/Microservices/New_Object/resources/views/welcome.blade.php
@@ -0,0 +1,17 @@
+
+
+
+
+
+ Enjoy your new Laraca generated service!
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Test/Microservices/PackageClass/resources/views/welcome.blade.php b/Test/Microservices/PackageClass/resources/views/welcome.blade.php
new file mode 100644
index 0000000..af5627f
--- /dev/null
+++ b/Test/Microservices/PackageClass/resources/views/welcome.blade.php
@@ -0,0 +1,17 @@
+
+
+
+
+
+ Enjoy your new Laraca generated service!
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Test/Microservices/Testy/resources/views/welcome.blade.php b/Test/Microservices/Testy/resources/views/welcome.blade.php
new file mode 100644
index 0000000..4b935b6
--- /dev/null
+++ b/Test/Microservices/Testy/resources/views/welcome.blade.php
@@ -0,0 +1,17 @@
+
+
+
+
+
+ Enjoy your new Laraca generated service!
+
+
+
+
+
+
\ No newline at end of file
diff --git a/config/config.php b/config/config.php
index 3613849..8e4e76c 100644
--- a/config/config.php
+++ b/config/config.php
@@ -4,23 +4,12 @@
* Laraca config
*/
return [
- /*
- |--------------------------------------------------------------------------
- | Domains
- |--------------------------------------------------------------------------
- | Enables optional domain argument in make commands
- */
- 'domains' => [
- 'enabled' => true,
- 'parent_dir' => 'Domains', // dir name or null
- ],
-
/*
|--------------------------------------------------------------------------
| Directory structure config
|--------------------------------------------------------------------------
*/
- 'structure' => [
+ 'struct' => [
/*
|--------------------------------------------------------------------------
| Cast Path
@@ -87,6 +76,18 @@
'parent' => 'base',
],
+ /*
+ |--------------------------------------------------------------------------
+ | Domains
+ |--------------------------------------------------------------------------
+ | Enables optional domain argument in make commands
+ */
+ 'domain' => [
+ 'enabled' => true,
+ 'path' => 'Domains', // dir name or null
+ 'parent' => 'app',
+ ],
+
/*
|--------------------------------------------------------------------------
| Enum Path
@@ -164,6 +165,18 @@
'parent' => 'app',
],
+ /*
+ |--------------------------------------------------------------------------
+ | Microservice Path
+ |--------------------------------------------------------------------------
+ | make:micro
+ */
+ 'microservice' => [
+ 'enabled' => true,
+ 'path' => 'Microservices',
+ 'parent' => 'app',
+ ],
+
/*
|--------------------------------------------------------------------------
| Middleware Path
diff --git a/docs/config-domains.md b/docs/config-domains.md
index 6ac4870..30550ce 100644
--- a/docs/config-domains.md
+++ b/docs/config-domains.md
@@ -5,19 +5,20 @@ If you're interested in domain-driven design or even separating your application
```php
'domains' => [
'enabled' => true,
- 'parent_dir' => 'Domains', // dir name or null
+ 'path' => 'Domains', // dir name or null
+ 'parent' => 'app',
],
```
-| Option | Description |
-| ------------ | :---------------------------------------------------------------------: |
-| `parent_dir` | The directory you want to use as a parent. It can be whatever you like. |
+| Option | Description |
+| ------ | :---------------------------------------------------------------------: |
+| `path` | The directory you want to use as a parent. It can be whatever you like. |
Examples:
-- `'parent_dir' => 'Domains'` => `(app/Domains/Foo)`
-- `'parent_dir' => 'Service'` => `(app/Service/Foo)`
-- `'parent_dir' => null` => `(app/Foo)`
+- `'path' => 'Domains'` => `(app/Domains/Foo)`
+- `'path' => 'Service'` => `(app/Service/Foo)`
+- `'path' => null` => `(app/Foo)`
## Use with make commands
diff --git a/docs/config-structure.md b/docs/config-structure.md
index 3969fd9..7e8836f 100644
--- a/docs/config-structure.md
+++ b/docs/config-structure.md
@@ -6,7 +6,7 @@ outline: deep
Generally, every key in the config corresponds to a fairly obvious command.
-Ex: `cast` key in `structure` corresponds to `make:cast`
+Ex: `cast` key in `struct` corresponds to `make:cast`
## Buildng Your Structure
@@ -35,7 +35,7 @@ Results: `app/Data/Models`
### Via Parent
-Additional keys can be added to the `structure` to serve as parent directories.
+Additional keys can be added to the `struct` to serve as parent directories.
```php
'data' => [
diff --git a/src/Commands/DomainListCommand.php b/src/Commands/DomainListCommand.php
index 3f5de4e..4df98f9 100644
--- a/src/Commands/DomainListCommand.php
+++ b/src/Commands/DomainListCommand.php
@@ -57,7 +57,7 @@ public function handle()
{
$domains = [];
- $domainDir = Config::get('laraca.domains.parent_dir');
+ $domainDir = Config::get('laraca.struct.domain.path');
$domainPath = app_path($domainDir);
if ($this->files->isDirectory($domainPath)) {
diff --git a/src/Commands/InitMicroserviceCommand.php b/src/Commands/InitMicroserviceCommand.php
new file mode 100644
index 0000000..4965b11
--- /dev/null
+++ b/src/Commands/InitMicroserviceCommand.php
@@ -0,0 +1,215 @@
+serviceName = $this->getClassName($this->input->getArgument('name'));
+ $servicePath = $this->getGenerationPath('microservice');
+ $this->servicePath = "$servicePath/$this->serviceName";
+
+ if (! parent::handle()) {
+ return false;
+ }
+
+ $this->makeDirectories();
+
+ $this->makeProviders();
+
+ $this->makeRouteFiles();
+
+ $this->makeFile('welcome', __DIR__.'/stubs/welcome.stub');
+
+ $this->components->bulletList($this->generated);
+ $this->components->info('Microservice created successfully.');
+ $this->components->info('Don\'t forget to
+
+ Enjoy your new Laraca generated service!
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Exceptions/InvalidConfigKeyException.php b/src/Exceptions/InvalidConfigKeyException.php
index b5a6ef4..aad5f7d 100644
--- a/src/Exceptions/InvalidConfigKeyException.php
+++ b/src/Exceptions/InvalidConfigKeyException.php
@@ -6,5 +6,8 @@
class InvalidConfigKeyException extends Exception
{
- //
+ public function __construct($key)
+ {
+ $this->message = 'Invalid configuration key: '.$key;
+ }
}
diff --git a/src/Exceptions/StubNotFoundException.php b/src/Exceptions/StubNotFoundException.php
new file mode 100644
index 0000000..dce2e89
--- /dev/null
+++ b/src/Exceptions/StubNotFoundException.php
@@ -0,0 +1,10 @@
+ ArtiMigrationCommand::class,
+ 'InitMicroservice' => InitMicroserviceCommand::class,
+ 'InitStructure' => InitStructureCommand::class,
'MakeCast' => MakeCastCommand::class,
'MakeChannel' => MakeChannelCommand::class,
'MakeCommand' => MakeCommandCommand::class,
@@ -80,7 +82,6 @@ class LaracaServiceProvider extends ServiceProvider
'MakeScope' => MakeScopeCommand::class,
'MakeService' => MakeServiceCommand::class,
'MakeSeeder' => MakeSeederCommand::class,
- 'MakeStructure' => InitStructureCommand::class,
'MakeTest' => MakeTestCommand::class,
'MakeValue' => MakeValueCommand::class,
'MakeView' => MakeViewCommand::class,
@@ -99,10 +100,7 @@ public function boot(): void
$this->app->useDatabasePath($this->assembleFullPath('database'));
- $domainsEnabled = Config::get('laraca.domains.enabled');
- $domainsParentDir = Config::get('laraca.domains.parent_dir');
-
- if ($domainsEnabled && $domainsParentDir) {
+ if ($this->domainsEnabled() && $this->domainParentDir()) {
$this->commands['DomainList'] = DomainListCommand::class;
}
diff --git a/src/Traits/GetsConfigValues.php b/src/Traits/GetsConfigValues.php
index 62058fb..a7c01b2 100644
--- a/src/Traits/GetsConfigValues.php
+++ b/src/Traits/GetsConfigValues.php
@@ -14,7 +14,7 @@ trait GetsConfigValues
*/
public static function domainsEnabled(): bool
{
- $domainsEnabled = Config::get('laraca.domains.enabled');
+ $domainsEnabled = Config::get('laraca.struct.domain.enabled');
return $domainsEnabled;
}
@@ -22,26 +22,43 @@ public static function domainsEnabled(): bool
/**
* Domain parent dir
*/
- public static function domainParentDir(): string
+ public static function domainParentDir(): ?string
{
- $parentDir = Config::get('laraca.domains.parent_dir');
+ $parentDir = Config::get('laraca.struct.domain.path');
+
+ return $parentDir;
+ }
+
+ /**
+ * Using domains
+ */
+ public static function microservicesEnabled(): bool
+ {
+ $microservicesEnabled = Config::get('laraca.struct.microservice.enabled');
+
+ return $microservicesEnabled;
+ }
+
+ /**
+ * Domain parent dir
+ */
+ public static function microserviceParentDir(): ?string
+ {
+ $parentDir = Config::get('laraca.struct.microservice.path');
return $parentDir;
}
/**
* assembleRelativePath
- *
- * @param string $key
- * @param bool $full
*/
- public static function assembleRelativePath($key, $domain = null): string
+ public static function assembleRelativePath(string $key, ?string $domain = null, ?string $service = null, bool $withRoot = true): string
{
- [$pathArray, $root] = self::assemblePathArray($key, $domain);
+ [$pathArray, $root] = self::assemblePathArray($key, $domain, $service);
$path = implode('/', $pathArray);
- if ($root == 'app') {
+ if ($root == 'app' && $withRoot) {
$path = 'app/'.$path;
}
@@ -50,20 +67,19 @@ public static function assembleRelativePath($key, $domain = null): string
/**
* assembleFullPath
- *
- * @param string $key
- * @param string $domain
*/
- public static function assembleFullPath($key, $domain = null): string
+ public static function assembleFullPath(string $key, ?string $domain = null, ?string $service = null, bool $withRoot = true): string
{
- [$pathArray, $root] = self::assemblePathArray($key, $domain);
+ [$pathArray, $root] = self::assemblePathArray($key, $domain, $service);
$path = implode('/', $pathArray);
- if ($root == 'app') {
- $path = app_path($path);
- } elseif ($root == 'base') {
- $path = base_path($path);
+ if ($withRoot) {
+ if ($root == 'app') {
+ $path = app_path($path);
+ } elseif ($root == 'base') {
+ $path = base_path($path);
+ }
}
return $path;
@@ -71,13 +87,10 @@ public static function assembleFullPath($key, $domain = null): string
/**
* assembleNamespace
- *
- * @param string $key
- * @param string $domain
*/
- public static function assembleNamespace($key, $domain = null): string
+ public static function assembleNamespace(string $key, ?string $domain = null, ?string $service = null, bool $withRoot = true): string
{
- [$pathArray, $root] = self::assemblePathArray($key, $domain);
+ [$pathArray, $root] = self::assemblePathArray($key, $domain, $service);
if ($key === 'test') {
array_shift($pathArray);
@@ -89,7 +102,7 @@ public static function assembleNamespace($key, $domain = null): string
$namespace = implode('\\', $pathArray);
- if ($root == 'app') {
+ if ($root == 'app' && $withRoot) {
$namespace = app()->getNamespace().$namespace;
}
@@ -98,17 +111,15 @@ public static function assembleNamespace($key, $domain = null): string
/**
* assemblePathArray
- *
- * @param string,string $key
*/
- protected static function assemblePathArray($key, $domain = null): array
+ protected static function assemblePathArray(string $key, ?string $domain = null, ?string $service = null): array
{
- if (! Config::has('laraca.structure.'.$key)) {
- throw new InvalidConfigKeyException();
+ if (! Config::has('laraca.struct.'.$key)) {
+ throw new InvalidConfigKeyException($key);
}
$path = [];
- $current = Config::get('laraca.structure.'.$key);
+ $current = Config::get('laraca.struct.'.$key);
$done = false;
do {
@@ -116,7 +127,7 @@ protected static function assemblePathArray($key, $domain = null): array
$path = array_merge(explode('/', $current['path']), $path);
} else {
// key config missing path or namespace value
- throw new MissingPathNamespaceKeyException();
+ throw new MissingPathNamespaceKeyException($key);
}
if (array_key_exists('parent', $current) && (bool) $current['parent']) {
@@ -132,17 +143,25 @@ protected static function assemblePathArray($key, $domain = null): array
}
}
+ if (self::microservicesEnabled() && $service) {
+ array_unshift($path, ucfirst($service));
+
+ if (self::microserviceParentDir()) {
+ array_unshift($path, self::microserviceParentDir());
+ }
+ }
+
$base = $parentKey;
$done = true;
- } elseif (Config::has('laraca.structure.'.$parentKey)) {
- $current = Config::get('laraca.structure.'.$parentKey);
+ } elseif (Config::has('laraca.struct.'.$parentKey)) {
+ $current = Config::get('laraca.struct.'.$parentKey);
} else {
// parent key not found in config
- throw new InvalidConfigKeyException();
+ throw new InvalidConfigKeyException($parentKey);
}
} else {
// path has led up to parent never finding 'base' or 'app' as a root
- throw new MissingRootPathException();
+ throw new MissingRootPathException($key);
}
} while ($done !== true);
diff --git a/tests/Feature/ArtiMigrationCommandTest.php b/tests/Feature/ArtiMigrationCommandTest.php
index e3a407e..58ad11f 100644
--- a/tests/Feature/ArtiMigrationCommandTest.php
+++ b/tests/Feature/ArtiMigrationCommandTest.php
@@ -7,7 +7,7 @@
describe('arti:migration', function () {
it('should create the Migration class when used', function (string $class) {
- Config::set('laraca.structure.database.path', 'test/database');
+ Config::set('laraca.struct.database.path', 'test/database');
$this->artisan('arti:migration',
['name' => $class]);
@@ -30,7 +30,7 @@
})->with('classes');
it('should create the Migration class using path option', function (string $class) {
- Config::set('laraca.structure.database.path', 'test/database');
+ Config::set('laraca.struct.database.path', 'test/database');
$this->artisan('arti:migration',
['name' => $class, '--path' => 'test/db/migrations']);
diff --git a/tests/Feature/DomainListTest.php b/tests/Feature/DomainListTest.php
index bb02e62..3dd673e 100644
--- a/tests/Feature/DomainListTest.php
+++ b/tests/Feature/DomainListTest.php
@@ -5,14 +5,14 @@
describe('domain:list', function () {
it('should list direct children of the configured domain folder', function (string $class, string $domain) {
- Config::set('laraca.domains.enabled', true);
- Config::set('laraca.domains.parent_dir', 'TestDomains');
+ Config::set('laraca.struct.domain.enabled', true);
+ Config::set('laraca.struct.domain.path', 'TestDomains');
$this->artisan('make:controller',
['name' => $class,
- 'domain' => $domain]);
+ '--domain' => $domain]);
$this->artisan('make:job',
['name' => $class,
- 'domain' => $domain]);
+ '--domain' => $domain]);
$this->artisan('domain:list');
@@ -23,16 +23,16 @@
})->with('classes', 'domains');
it('should not be available when domains are disabled', function () {
- Config::set('laraca.domains.enabled', false);
- Config::set('laraca.domains.parent_dir', 'TestDomains');
+ Config::set('laraca.struct.domain.enabled', false);
+ Config::set('laraca.struct.domain.path', 'TestDomains');
$output = Artisan::output();
expect($output)
->not->toContain('domain:list');
});
it('should not be available when domain parent dir is null', function () {
- Config::set('laraca.domains.enabled', true);
- Config::set('laraca.domains.parent_dir', null);
+ Config::set('laraca.struct.domain.enabled', true);
+ Config::set('laraca.struct.domain.path', null);
$output = Artisan::output();
expect($output)
->not->toContain('domain:list');
diff --git a/tests/Feature/DomainsTest.php b/tests/Feature/DomainsTest.php
index 90e221b..c8c894b 100644
--- a/tests/Feature/DomainsTest.php
+++ b/tests/Feature/DomainsTest.php
@@ -6,21 +6,44 @@
describe('use domains', function () {
it('should use domain settings in path/namespace when enabled and domain arg', function (string $class, string $domain) {
- Config::set('laraca.domains.enabled', true);
- Config::set('laraca.domains.parent_dir', 'TestDomains');
+ Config::set('laraca.struct.domain.enabled', true);
+ Config::set('laraca.struct.domain.path', 'TestDomains');
$this->artisan('make:controller',
['name' => $class,
- 'domain' => $domain]);
+ '--domain' => $domain]);
$output = Artisan::output();
$configPath = assembleFullPath('controller', $domain);
$filePath = "$configPath/$class.php";
+ $configNamespace = fullNamespaceStr("App\TestDomains\\".ucfirst($domain)."\Http\Controllers");
+
expect(File::exists($filePath))
->toBe(true, "File not created at expected path:\n".$filePath."\nCommand result:\n".$output."\n\n");
- $configNamespace = fullNamespaceStr("App\TestDomains\\".ucfirst($domain)."\Http\Controllers");
+ expect(File::get($filePath))
+ ->toContain($configNamespace);
+
+ })->with('classes', 'domains');
+
+ it('should not use parent domain when path is null', function (string $class, string $domain) {
+ Config::set('laraca.struct.domain.enabled', true);
+ Config::set('laraca.struct.domain.path', null);
+ Config::set('laraca.struct.enum.path', 'Test/Enums');
+ $this->artisan('make:enum',
+ ['name' => $class,
+ '--domain' => $domain]);
+
+ $configPath = assembleFullPath('enum', $domain);
+ $filePath = "$configPath/$class.php";
+
+ $configNamespace = fullNamespaceStr('App\\'.ucfirst($domain)."\Test\Enums");
+
+ $output = Artisan::output();
+
+ expect(File::exists($filePath))
+ ->toBe(true, "File not created at expected path:\n".$filePath."\nCommand result:\n".$output."\n\n");
expect(File::get($filePath))
->toContain($configNamespace);
@@ -28,22 +51,22 @@
})->with('classes', 'domains');
it('should not use domain settings in path/namespace when enabled and no domain arg', function (string $class) {
- Config::set('laraca.domains.enabled', true);
- Config::set('laraca.domains.parent_dir', 'TestDomains');
- Config::set('laraca.structure.controller.path', 'Test/Http/Controllers');
+ Config::set('laraca.struct.domain.enabled', true);
+ Config::set('laraca.struct.domain.path', 'TestDomains');
+ Config::set('laraca.struct.controller.path', 'Test/Http/Controllers');
$this->artisan('make:controller',
['name' => $class]);
$configPath = assembleFullPath('controller');
$filePath = "$configPath/$class.php";
+ $configNamespace = fullNamespaceStr('App\Test\Http\Controllers');
+
$output = Artisan::output();
expect(File::exists($filePath))
->toBe(true, "File not created at expected path:\n".$filePath."\nCommand result:\n".$output."\n\n");
- $configNamespace = fullNamespaceStr('App\Test\Http\Controllers');
-
expect(File::get($filePath))
->toContain($configNamespace);
diff --git a/tests/Feature/InitMicroserviceCommandTest.php b/tests/Feature/InitMicroserviceCommandTest.php
new file mode 100644
index 0000000..7dcd7b0
--- /dev/null
+++ b/tests/Feature/InitMicroserviceCommandTest.php
@@ -0,0 +1,83 @@
+artisan('init:micro', [
+ 'name' => $class,
+ ]))->toBe(0);
+
+ $output = Artisan::output();
+
+ $class = ucfirst($class);
+ $slug = Str::slug($class);
+
+ $paths = [
+ "app/Test/Microservices/$class/Broadcasting",
+ "app/Test/Microservices/$class/Http/Controllers",
+ "app/Test/Microservices/$class/Providers",
+ "app/Test/Microservices/$class/resources/views",
+ "app/Test/Microservices/$class/routes",
+ "app/Test/Microservices/$class/tests",
+ ];
+
+ foreach ($paths as $p) {
+ $dirPath = base_path($p);
+ expect(File::isDirectory($dirPath))
+ ->toBe(true, "Directory not created:\n".$dirPath."\n");
+ }
+
+ $root = "Test/Microservices/$class";
+ $servicePath = app_path($root.'/'.$class.'ServiceProvider.php');
+ $routeServicePath = app_path("$root/Providers/RouteServiceProvider.php");
+ $broadcastServicePath = app_path("$root/Providers/BroadcastServiceProvider.php");
+ $welcomePath = app_path("$root/resources/views/welcome.blade.php");
+ $routesPath = app_path("$root/routes/");
+
+ $serviceNamespace = fullNamespaceStr("App\\Test\\Microservices\\$class");
+ $providerNamespace = fullNamespaceStr("App\\Test\\Microservices\\$class\\Providers");
+
+ expect(File::exists($servicePath))
+ ->toBe(true, "File not created at expected path:\n".$servicePath."\nCommand result:\n".$output."\n\n");
+ expect(File::get($servicePath))
+ ->toContain($serviceNamespace);
+
+ expect(File::exists($routeServicePath))
+ ->toBe(true, "File not created at expected path:\n".$routeServicePath."\nCommand result:\n".$output."\n\n");
+ expect(File::get($routeServicePath))
+ ->toContain($providerNamespace)
+ ->toContain('require __DIR__.\'/../routes/web.php\';');
+
+ expect(File::exists($broadcastServicePath))
+ ->toBe(true, "File not created at expected path:\n".$broadcastServicePath."\nCommand result:\n".$output."\n\n");
+ expect(File::get($broadcastServicePath))
+ ->toContain($providerNamespace)
+ ->toContain('require __DIR__.\'/../routes/channels.php\';');
+
+ expect(File::exists($routesPath.'web.php'))
+ ->toBe(true, "File not created at expected path:\n".$routesPath.'web.php'."\nCommand result:\n".$output."\n\n");
+ expect(File::get($routesPath.'web.php'))
+ ->toContain($slug)
+ ->toContain("prefix: /$slug");
+
+ expect(File::exists($routesPath.'api.php'))
+ ->toBe(true, "File not created at expected path:\n".$routesPath.'api.php'."\nCommand result:\n".$output."\n\n");
+ expect(File::get($routesPath.'api.php'))
+ ->toContain($slug)
+ ->toContain("/api/$slug");
+
+ expect(File::exists($routesPath.'channels.php'))
+ ->toBe(true, "File not created at expected path:\n".$routesPath.'api.php'."\nCommand result:\n".$output."\n\n");
+ expect(File::get($routesPath.'channels.php'))
+ ->toContain($class)
+ ->toContain('Broadcast::channel(\''.$class.'.User.{id}\', function ($user, $id) {');
+
+ expect(File::exists($welcomePath))
+ ->toBe(true, "File not created at expected path:\n".$welcomePath."\nCommand result:\n".$output."\n\n");
+ })->with('classes');
+});
diff --git a/tests/Feature/InitStructureCommandTest.php b/tests/Feature/InitStructureCommandTest.php
index 89950e1..9aea4d3 100644
--- a/tests/Feature/InitStructureCommandTest.php
+++ b/tests/Feature/InitStructureCommandTest.php
@@ -8,30 +8,30 @@
describe('init:structure', function () {
it('should create directory Structure from config', function () {
- Config::set('laraca.structure.database.path', 'test/database');
- Config::set('laraca.structure.cast.path', 'Test/Data/Casts');
- Config::set('laraca.structure.channel.path', 'Test/Broadcasting');
- Config::set('laraca.structure.command.path', 'Test/Console/Commands');
- Config::set('laraca.structure.component.path', 'Test/View/Components');
- Config::set('laraca.structure.controller.path', 'Test/Http/Controllers');
- Config::set('laraca.structure.event.path', 'Test/Events');
- Config::set('laraca.structure.enum.path', 'Test/Enums');
- Config::set('laraca.structure.exception.path', 'Test/Exceptions');
- Config::set('laraca.structure.job.path', 'Test/Jobs');
- Config::set('laraca.structure.listener.path', 'Test/Listeners');
- Config::set('laraca.structure.mail.path', 'Test/Mail');
- Config::set('laraca.structure.middleware.path', 'Test/Http/Middleware');
- Config::set('laraca.structure.model.path', 'Test/Data/Models');
- Config::set('laraca.structure.notification.path', 'Test/Notifications');
- Config::set('laraca.structure.observer.path', 'Test/Data/Observers');
- Config::set('laraca.structure.policy.path', 'Test/Policies');
- Config::set('laraca.structure.provider.path', 'Test/Providers');
- Config::set('laraca.structure.request.path', 'Test/Http/Requests');
- Config::set('laraca.structure.resource.path', 'Test/Http/Resources');
- Config::set('laraca.structure.rule.path', 'Test/Rules');
- Config::set('laraca.structure.test.path', 'test/tests');
- Config::set('laraca.structure.value.path', 'Test/Data/Values');
- Config::set('laraca.structure.view.path', 'test/resources/views');
+ Config::set('laraca.struct.database.path', 'test/database');
+ Config::set('laraca.struct.cast.path', 'Test/Data/Casts');
+ Config::set('laraca.struct.channel.path', 'Test/Broadcasting');
+ Config::set('laraca.struct.command.path', 'Test/Console/Commands');
+ Config::set('laraca.struct.component.path', 'Test/View/Components');
+ Config::set('laraca.struct.controller.path', 'Test/Http/Controllers');
+ Config::set('laraca.struct.event.path', 'Test/Events');
+ Config::set('laraca.struct.enum.path', 'Test/Enums');
+ Config::set('laraca.struct.exception.path', 'Test/Exceptions');
+ Config::set('laraca.struct.job.path', 'Test/Jobs');
+ Config::set('laraca.struct.listener.path', 'Test/Listeners');
+ Config::set('laraca.struct.mail.path', 'Test/Mail');
+ Config::set('laraca.struct.middleware.path', 'Test/Http/Middleware');
+ Config::set('laraca.struct.model.path', 'Test/Data/Models');
+ Config::set('laraca.struct.notification.path', 'Test/Notifications');
+ Config::set('laraca.struct.observer.path', 'Test/Data/Observers');
+ Config::set('laraca.struct.policy.path', 'Test/Policies');
+ Config::set('laraca.struct.provider.path', 'Test/Providers');
+ Config::set('laraca.struct.request.path', 'Test/Http/Requests');
+ Config::set('laraca.struct.resource.path', 'Test/Http/Resources');
+ Config::set('laraca.struct.rule.path', 'Test/Rules');
+ Config::set('laraca.struct.test.path', 'test/tests');
+ Config::set('laraca.struct.value.path', 'Test/Data/Values');
+ Config::set('laraca.struct.view.path', 'test/resources/views');
expect($this->artisan('init:structure'))
->toBe(0);
@@ -76,27 +76,27 @@
->toBe(true, "File not created at expected path:\n".$keepFile."\n\n");
}
- })->with('classes');
+ });
it('throws a MissingPathNamespaceKeyException when a key has no path or namespace', function () {
- Config::set('laraca.structure.empty_key', []);
- Config::set('laraca.structure.command.parent', 'empty_key');
+ Config::set('laraca.struct.empty_key', []);
+ Config::set('laraca.struct.command.parent', 'empty_key');
$this->artisan('init:structure');
- })->with('classes')->throws(MissingPathNamespaceKeyException::class);
+ })->throws(MissingPathNamespaceKeyException::class);
it('throws an InvalidConfigKeyException when a parent key does not exist in the config', function () {
- Config::set('laraca.structure.model.parent', 'nonexistent_key');
+ Config::set('laraca.struct.model.parent', 'nonexistent_key');
$this->artisan('init:structure');
- })->with('classes')->throws(InvalidConfigKeyException::class);
+ })->throws(InvalidConfigKeyException::class);
it('throws a MissingRootPathException when a tree does not lead to a base or app parent', function () {
- Config::set('laraca.structure.model.parent', '');
+ Config::set('laraca.struct.model.parent', '');
$this->artisan('init:structure');
- })->with('classes')->throws(MissingRootPathException::class);
+ })->throws(MissingRootPathException::class);
});
diff --git a/tests/Feature/MakeCastCommandTest.php b/tests/Feature/MakeCastCommandTest.php
index 630a1f9..09a8722 100644
--- a/tests/Feature/MakeCastCommandTest.php
+++ b/tests/Feature/MakeCastCommandTest.php
@@ -6,7 +6,7 @@
describe('make:cast', function () {
it('should create Cast class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.cast.path', 'Test/Data/Casts');
+ Config::set('laraca.struct.cast.path', 'Test/Data/Casts');
$this->artisan('make:cast',
['name' => $class]);
diff --git a/tests/Feature/MakeChannelCommandTest.php b/tests/Feature/MakeChannelCommandTest.php
index 468ad12..3946c06 100644
--- a/tests/Feature/MakeChannelCommandTest.php
+++ b/tests/Feature/MakeChannelCommandTest.php
@@ -6,7 +6,7 @@
describe('make:channel', function () {
it('should create Channel class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.channel.path', 'Test/Broadcasting');
+ Config::set('laraca.struct.channel.path', 'Test/Broadcasting');
$this->artisan('make:channel',
['name' => $class]);
diff --git a/tests/Feature/MakeCommandCommandTest.php b/tests/Feature/MakeCommandCommandTest.php
index fc68637..abf1279 100644
--- a/tests/Feature/MakeCommandCommandTest.php
+++ b/tests/Feature/MakeCommandCommandTest.php
@@ -6,7 +6,7 @@
describe('make:command', function () {
it('should create Command class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.command.path', 'Test/Console/Commands');
+ Config::set('laraca.struct.command.path', 'Test/Console/Commands');
$this->artisan('make:command',
['name' => $class]);
diff --git a/tests/Feature/MakeComponentCommandTest.php b/tests/Feature/MakeComponentCommandTest.php
deleted file mode 100644
index b9abfec..0000000
--- a/tests/Feature/MakeComponentCommandTest.php
+++ /dev/null
@@ -1,51 +0,0 @@
-artisan('make:component',
- ['name' => $class]);
-
- $configPath = assembleFullPath('component');
- $filePath = "$configPath/$class.php";
-
- $output = Artisan::output();
-
- expect(File::exists($filePath))
- ->toBe(true, "File not created at expected path:\n".$filePath."\nCommand result:\n".$output."\n\n");
-
- $configNamespace = fullNamespaceStr('App\Test\View\Components');
-
- expect(File::get($filePath))
- ->toContain($configNamespace);
-
- $snake_class = Str::snake($class, '-');
- $viewPath = assembleFullPath('view')."/components/{$snake_class}.blade.php";
-
- expect(File::exists($viewPath))
- ->toBe(true, "File not created at expected path:\n".$viewPath."\nCommand result:\n".$output."\n\n");
-
- })->with('classes');
-
- it('should create blade file at Laravel configured path when view not set in laraca config', function (string $class) {
- Config::set('laraca.structure.component.path', 'Test/View/Components');
- Config::offsetUnset('laraca.structure.view');
- $this->artisan('make:component',
- ['name' => $class]);
-
- $output = Artisan::output();
-
- $snake_class = Str::snake($class, '-');
- $viewPath = base_path("resources/views/components/{$snake_class}.blade.php");
-
- expect(File::exists($viewPath))
- ->toBe(true, "File not created at expected path:\n".$viewPath."\nCommand result:\n".$output."\n\n");
-
- })->with('classes');
-});
diff --git a/tests/Feature/MakeControllerCommandTest.php b/tests/Feature/MakeControllerCommandTest.php
index ec648c4..03941f6 100644
--- a/tests/Feature/MakeControllerCommandTest.php
+++ b/tests/Feature/MakeControllerCommandTest.php
@@ -6,7 +6,7 @@
describe('make:controller', function () {
it('should create Controller class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.controller.path', 'Test/Http/Controllers');
+ Config::set('laraca.struct.controller.path', 'Test/Http/Controllers');
$this->artisan('make:controller',
['name' => $class]);
diff --git a/tests/Feature/MakeEnumCommandTest.php b/tests/Feature/MakeEnumCommandTest.php
index 6973f7e..53ba442 100644
--- a/tests/Feature/MakeEnumCommandTest.php
+++ b/tests/Feature/MakeEnumCommandTest.php
@@ -6,7 +6,7 @@
describe('make:enum', function () {
it('should create Enum class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.enum.path', 'Test/Enums');
+ Config::set('laraca.struct.enum.path', 'Test/Enums');
$this->artisan('make:enum',
['name' => $class]);
diff --git a/tests/Feature/MakeEventCommandTest.php b/tests/Feature/MakeEventCommandTest.php
index fc6663c..db85562 100644
--- a/tests/Feature/MakeEventCommandTest.php
+++ b/tests/Feature/MakeEventCommandTest.php
@@ -6,7 +6,7 @@
describe('make:event', function () {
it('should create Event class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.event.path', 'Test/Events');
+ Config::set('laraca.struct.event.path', 'Test/Events');
$this->artisan('make:event',
['name' => $class]);
diff --git a/tests/Feature/MakeExceptionCommandTest.php b/tests/Feature/MakeExceptionCommandTest.php
index e4d9493..b596dd2 100644
--- a/tests/Feature/MakeExceptionCommandTest.php
+++ b/tests/Feature/MakeExceptionCommandTest.php
@@ -6,7 +6,7 @@
describe('make:exception', function () {
it('should create Exception class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.exception.path', 'Test/Exceptions');
+ Config::set('laraca.struct.exception.path', 'Test/Exceptions');
$this->artisan('make:exception',
['name' => $class]);
diff --git a/tests/Feature/MakeFactoryCommandTest.php b/tests/Feature/MakeFactoryCommandTest.php
index fc98ba5..45631b1 100644
--- a/tests/Feature/MakeFactoryCommandTest.php
+++ b/tests/Feature/MakeFactoryCommandTest.php
@@ -6,7 +6,7 @@
describe('make:factory', function () {
it('should create Factory class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.database.path', 'test/database');
+ Config::set('laraca.struct.database.path', 'test/database');
$this->artisan('make:factory',
['name' => $class]);
diff --git a/tests/Feature/MakeJobCommandTest.php b/tests/Feature/MakeJobCommandTest.php
index 5e6035d..940e5bc 100644
--- a/tests/Feature/MakeJobCommandTest.php
+++ b/tests/Feature/MakeJobCommandTest.php
@@ -6,7 +6,7 @@
describe('make:job', function () {
it('should create Job class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.job.path', 'Test/Jobs');
+ Config::set('laraca.struct.job.path', 'Test/Jobs');
$this->artisan('make:job',
['name' => $class]);
diff --git a/tests/Feature/MakeListenerCommandTest.php b/tests/Feature/MakeListenerCommandTest.php
index 0d0ecb5..dfb23bb 100644
--- a/tests/Feature/MakeListenerCommandTest.php
+++ b/tests/Feature/MakeListenerCommandTest.php
@@ -6,7 +6,7 @@
describe('make:listener', function () {
it('should create Listener class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.listener.path', 'Test/Listeners');
+ Config::set('laraca.struct.listener.path', 'Test/Listeners');
$this->artisan('make:listener',
['name' => $class]);
diff --git a/tests/Feature/MakeMailCommandTest.php b/tests/Feature/MakeMailCommandTest.php
index 3ab392f..9764dd1 100644
--- a/tests/Feature/MakeMailCommandTest.php
+++ b/tests/Feature/MakeMailCommandTest.php
@@ -6,7 +6,7 @@
describe('make:mail', function () {
it('should create Mail class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.mail.path', 'Test/Mail');
+ Config::set('laraca.struct.mail.path', 'Test/Mail');
$this->artisan('make:mail',
['name' => $class]);
diff --git a/tests/Feature/MakeMiddlewareCommandTest.php b/tests/Feature/MakeMiddlewareCommandTest.php
index 11f7a58..2360bba 100644
--- a/tests/Feature/MakeMiddlewareCommandTest.php
+++ b/tests/Feature/MakeMiddlewareCommandTest.php
@@ -6,7 +6,7 @@
describe('make:middleware', function () {
it('should create Middleware class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.middleware.path', 'Test/Http/Middleware');
+ Config::set('laraca.struct.middleware.path', 'Test/Http/Middleware');
$this->artisan('make:middleware',
['name' => $class]);
diff --git a/tests/Feature/MakeModelCommandTest.php b/tests/Feature/MakeModelCommandTest.php
index a01773d..8d1f737 100644
--- a/tests/Feature/MakeModelCommandTest.php
+++ b/tests/Feature/MakeModelCommandTest.php
@@ -6,7 +6,7 @@
describe('make:model', function () {
it('should create Model class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.model.path', 'Test/Data/Models');
+ Config::set('laraca.struct.model.path', 'Test/Data/Models');
$this->artisan('make:model',
['name' => $class]);
@@ -26,7 +26,7 @@
})->with('classes');
it('should create a Model class with HasUuids trait', function (string $class) {
- Config::set('laraca.structure.model.path', 'Test/Data/Models');
+ Config::set('laraca.struct.model.path', 'Test/Data/Models');
$this->artisan('make:model',
['name' => $class, '--uuid' => true]);
diff --git a/tests/Feature/MakeNotificationCommandTest.php b/tests/Feature/MakeNotificationCommandTest.php
index 2aa277f..312789f 100644
--- a/tests/Feature/MakeNotificationCommandTest.php
+++ b/tests/Feature/MakeNotificationCommandTest.php
@@ -6,7 +6,7 @@
describe('make:notification', function () {
it('should create Notification class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.notification.path', 'Test/Notifications');
+ Config::set('laraca.struct.notification.path', 'Test/Notifications');
$this->artisan('make:notification',
['name' => $class]);
diff --git a/tests/Feature/MakeObserverCommandTest.php b/tests/Feature/MakeObserverCommandTest.php
index 9784aaf..9d7ae1f 100644
--- a/tests/Feature/MakeObserverCommandTest.php
+++ b/tests/Feature/MakeObserverCommandTest.php
@@ -6,7 +6,7 @@
describe('make:observer', function () {
it('should create Observer class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.observer.path', 'Test/Data/Observers');
+ Config::set('laraca.struct.observer.path', 'Test/Data/Observers');
$this->artisan('make:observer',
['name' => $class]);
diff --git a/tests/Feature/MakePolicyCommandTest.php b/tests/Feature/MakePolicyCommandTest.php
index de8dcb8..65e40be 100644
--- a/tests/Feature/MakePolicyCommandTest.php
+++ b/tests/Feature/MakePolicyCommandTest.php
@@ -6,7 +6,7 @@
describe('make:policy', function () {
it('should create Policy class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.policy.path', 'Test/Policies');
+ Config::set('laraca.struct.policy.path', 'Test/Policies');
$this->artisan('make:policy',
['name' => $class]);
diff --git a/tests/Feature/MakeProviderCommandTest.php b/tests/Feature/MakeProviderCommandTest.php
index 72a4815..250f544 100644
--- a/tests/Feature/MakeProviderCommandTest.php
+++ b/tests/Feature/MakeProviderCommandTest.php
@@ -6,7 +6,7 @@
describe('make:provider', function () {
it('should create Provider class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.provider.path', 'Test/Providers');
+ Config::set('laraca.struct.provider.path', 'Test/Providers');
$this->artisan('make:provider',
['name' => $class]);
diff --git a/tests/Feature/MakeRequestCommandTest.php b/tests/Feature/MakeRequestCommandTest.php
index 006103b..dcc5ec1 100644
--- a/tests/Feature/MakeRequestCommandTest.php
+++ b/tests/Feature/MakeRequestCommandTest.php
@@ -6,7 +6,7 @@
describe('make:request', function () {
it('should create Request class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.request.path', 'Test/Http/Requests');
+ Config::set('laraca.struct.request.path', 'Test/Http/Requests');
$this->artisan('make:request',
['name' => $class]);
diff --git a/tests/Feature/MakeResourceCommandTest.php b/tests/Feature/MakeResourceCommandTest.php
index 1ae0105..67fa03f 100644
--- a/tests/Feature/MakeResourceCommandTest.php
+++ b/tests/Feature/MakeResourceCommandTest.php
@@ -6,7 +6,7 @@
describe('make:resource', function () {
it('should create Resource class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.resource.path', 'Test/Http/Resources');
+ Config::set('laraca.struct.resource.path', 'Test/Http/Resources');
$this->artisan('make:resource',
['name' => $class]);
diff --git a/tests/Feature/MakeRuleCommandTest.php b/tests/Feature/MakeRuleCommandTest.php
index daad56d..b698825 100644
--- a/tests/Feature/MakeRuleCommandTest.php
+++ b/tests/Feature/MakeRuleCommandTest.php
@@ -6,7 +6,7 @@
describe('make:rule', function () {
it('should create Rule class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.rule.path', 'Test/Rules');
+ Config::set('laraca.struct.rule.path', 'Test/Rules');
$this->artisan('make:rule',
['name' => $class]);
diff --git a/tests/Feature/MakeScopeCommandTest.php b/tests/Feature/MakeScopeCommandTest.php
index 2152d7d..446f82a 100644
--- a/tests/Feature/MakeScopeCommandTest.php
+++ b/tests/Feature/MakeScopeCommandTest.php
@@ -6,7 +6,7 @@
describe('make:scope', function () {
it('should create Scope class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.model.path', 'Test/Data/Models');
+ Config::set('laraca.struct.model.path', 'Test/Data/Models');
$this->artisan('make:scope',
['name' => $class]);
diff --git a/tests/Feature/MakeSeederCommandTest.php b/tests/Feature/MakeSeederCommandTest.php
index fd314a0..8fae14b 100644
--- a/tests/Feature/MakeSeederCommandTest.php
+++ b/tests/Feature/MakeSeederCommandTest.php
@@ -6,7 +6,7 @@
describe('make:seeder', function () {
it('should create Seeder class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.database.path', 'test/database');
+ Config::set('laraca.struct.database.path', 'test/database');
$this->artisan('make:seeder',
['name' => $class]);
diff --git a/tests/Feature/MakeServiceCommandTest.php b/tests/Feature/MakeServiceCommandTest.php
index d163d78..32d6359 100644
--- a/tests/Feature/MakeServiceCommandTest.php
+++ b/tests/Feature/MakeServiceCommandTest.php
@@ -6,9 +6,11 @@
describe('make:service', function () {
it('should create Service class and interface with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.service.path', 'Test/Services');
- $this->artisan('make:service',
- ['name' => $class]);
+ Config::set('laraca.struct.service.path', 'Test/Services');
+ $this->artisan(
+ 'make:service',
+ ['name' => $class]
+ );
$class = ucfirst($class);
$configPath = assembleFullPath('service');
@@ -30,6 +32,5 @@
expect(File::get($interfaceFilePath))
->toContain($configNamespace);
-
})->with('classes');
});
diff --git a/tests/Feature/MakeTestCommandTest.php b/tests/Feature/MakeTestCommandTest.php
index 08d1bc7..99ef1b0 100644
--- a/tests/Feature/MakeTestCommandTest.php
+++ b/tests/Feature/MakeTestCommandTest.php
@@ -6,7 +6,7 @@
describe('make:test', function () {
it('should create Test class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.test.path', 'test/tests');
+ Config::set('laraca.struct.test.path', 'test/tests');
$this->artisan('make:test',
['name' => $class]);
diff --git a/tests/Feature/MakeValueCommandTest.php b/tests/Feature/MakeValueCommandTest.php
index 4cf6a10..a2584da 100644
--- a/tests/Feature/MakeValueCommandTest.php
+++ b/tests/Feature/MakeValueCommandTest.php
@@ -7,7 +7,7 @@
describe('make:value', function () {
it('should create Value class with namespace and path created from configured vals', function (string $class) {
- Config::set('laraca.structure.value.path', 'Test/Data/Values');
+ Config::set('laraca.struct.value.path', 'Test/Data/Values');
$this->artisan('make:value',
['name' => $class]);
diff --git a/tests/Feature/MakeViewCommandTest.php b/tests/Feature/MakeViewCommandTest.php
index 4505733..f073177 100644
--- a/tests/Feature/MakeViewCommandTest.php
+++ b/tests/Feature/MakeViewCommandTest.php
@@ -6,7 +6,7 @@
describe('make:view', function () {
it('should create blade file at package configured path', function (string $class) {
- Config::set('laraca.structure.view.path', 'test/resources/views');
+ Config::set('laraca.struct.view.path', 'test/resources/views');
$this->artisan('make:view',
['name' => $class]);
diff --git a/tests/Pest.php b/tests/Pest.php
index f908621..88778df 100644
--- a/tests/Pest.php
+++ b/tests/Pest.php
@@ -18,9 +18,9 @@
*
* @param string $key
*/
-function assembleFullPath($key, $domain = null): string
+function assembleFullPath($key, $domain = null, $service = null): string
{
- return HandsomeBrown\Laraca\Traits\GetsConfigValues::assembleFullPath($key, $domain);
+ return HandsomeBrown\Laraca\Traits\GetsConfigValues::assembleFullPath($key, $domain, $service);
}
/**
@@ -36,7 +36,7 @@ function assembleNamespace($key): string
/**
* fullNamespaceStr
*/
-function fullNamespaceStr(string $namespace, bool $app = true): string
+function fullNamespaceStr(string $namespace): string
{
return 'namespace '.$namespace.';';
}
diff --git a/tests/Unit/ConfigPathTest.php b/tests/Unit/ConfigPathTest.php
index 6007e1e..5f73a3c 100644
--- a/tests/Unit/ConfigPathTest.php
+++ b/tests/Unit/ConfigPathTest.php
@@ -7,8 +7,8 @@
describe('Config path assembly exceptions', function () {
it('throws a MissingPathNamespaceKeyException when a key has no path or namespace', function () {
- Config::set('laraca.structure.empty_key', []);
- Config::set('laraca.structure.command.parent', 'empty_key');
+ Config::set('laraca.struct.empty_key', []);
+ Config::set('laraca.struct.command.parent', 'empty_key');
assembleFullPath('command');
@@ -21,14 +21,14 @@
})->with('classes')->throws(InvalidConfigKeyException::class);
it('throws an InvalidConfigKeyException when a parent key does not exist in the config', function () {
- Config::set('laraca.structure.model.parent', 'nonexistent_key');
+ Config::set('laraca.struct.model.parent', 'nonexistent_key');
assembleFullPath('model');
})->with('classes')->throws(InvalidConfigKeyException::class);
it('throws a MissingRootPathException when a tree does not lead to a base or app parent', function () {
- Config::set('laraca.structure.model.parent', '');
+ Config::set('laraca.struct.model.parent', '');
assembleFullPath('model');