diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 66c5b8be3..1540daa65 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,3 +1,4 @@ # These are supported funding model platforms github: nwidart +github: dcblogdev diff --git a/.github/stale.yml b/.github/stale.yml deleted file mode 100644 index 3b6ae488c..000000000 --- a/.github/stale.yml +++ /dev/null @@ -1,17 +0,0 @@ -# Number of days of inactivity before an issue becomes stale -daysUntilStale: 15 -# Number of days of inactivity before a stale issue is closed -daysUntilClose: 7 -# Issues with these labels will never be considered stale -exemptLabels: - - pinned - - security -# Label to use when marking an issue as stale -staleLabel: stale -# Comment to post when marking an issue as stale. Set to `false` to disable -markComment: > - This issue has been automatically marked as stale because it has not had - recent activity. It will be closed if no further activity occurs. Thank you - for your contributions. -# Comment to post when closing a stale issue. Set to `false` to disable -closeComment: false diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index d4a140f06..966043c1e 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -10,12 +10,12 @@ jobs: strategy: max-parallel: 2 matrix: - php-versions: ['8.1'] + php-versions: ['8.2', '8.3'] name: PHP ${{ matrix.php-versions }} steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@master diff --git a/.gitignore b/.gitignore index 582942a3e..7a0015c03 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,7 @@ coverage .php_cs.cache .phpunit.result.cache .idea +.php-cs-fixer.cache +.DS_Store +src/.DS_Store +tests/.DS_Store diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index bc7239069..1efd6b3d4 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -19,8 +19,6 @@ 'no_whitespace_in_blank_line' => true, // There MUST be one blank line after the namespace declaration. 'blank_line_after_namespace' => true, - // There should be exactly one blank line before a namespace declaration. - 'single_blank_line_before_namespace' => true, // Each namespace use MUST go on its own line and there MUST be one blank line after the use statements block. 'single_line_after_imports' => true, // Ensure there is no code on the same line as the PHP open tag and it is followed by a blankline. diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e3fb380a..2b3ec5196 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,192 @@ All Notable changes to `laravel-modules` will be documented in this file. ## Next -## 10.0 - 2023-02-14 +- [@omerbaflah](https://github.com/omerbaflah) Fixes Invokable Controller Stub +- [@solomon-ochepa](https://github.com/solomon-ochepa) Added create module:make-class command + +## 11.0.10 - 2024-05-05 + +- [@dcblogdev](https://github.com/dcblogdev) Update controller, service, helper, and action methods +- [@omerbaflah](https://github.com/omerbaflah) Update service stubs +- [@omerbaflah](https://github.com/omerbaflah) Update action stubs +- [@AbdulkarimOmer](https://github.com/AbdulkarimOmer) Added invokable option into make-controller command +- [@dcblogdev](https://github.com/dcblogdev) Updated vite-module-loader.js to handle case when a modules does not have a vite.config.js file +- [@alissn](https://github.com/alissn) Added direction option to command module:seed + +## 11.0.9 - 2024-04-30 + +- [@dcblogdev](https://github.com/dcblogdev) added make-event-provider command, modules come with event as default now + +## 11.0.8 - 2024-04-29 + +- [@solomon-ochepa](https://github.com/solomon-ochepa) Remove custom namespaces from generator [factory and seeder] +- [@dcblogdev](https://github.com/dcblogdev) added make-action command +- [@dcblogdev](https://github.com/dcblogdev) added make-cast command +- [@dcblogdev](https://github.com/dcblogdev) added make-enum command +- [@dcblogdev](https://github.com/dcblogdev) added make-exception command +- [@dcblogdev](https://github.com/dcblogdev) added make-helper command +- [@dcblogdev](https://github.com/dcblogdev) added make-interface command +- [@dcblogdev](https://github.com/dcblogdev) added make-scope command +- [@dcblogdev](https://github.com/dcblogdev) added make-trait command +- [@dcblogdev](https://github.com/dcblogdev) added missing return type for make-service command +- [@dcblogdev](https://github.com/dcblogdev) updated config + +## 11.0.7 - 2024-04-25 + +## Changes + +- [@dcblogdev](https://github.com/dcblogdev) Force the config replacement option for composer 'APP_FOLDER_NAME', to be handled even when its not present. +- [@solomon-ochepa](https://github.com/solomon-ochepa) Path Namespace - generate a well-formatted StudlyCase namespace from paths +- [@korridor](https://github.com/korridor) Fixed public path for octane setup +- [@dcblogdev](https://github.com/dcblogdev) added invokable and force options into make-service command +- [@dcblogdev](https://github.com/dcblogdev) Restrict fresh migration to module scope +- [@kowston](https://github.com/kowston) Changed wording for command descriptions to be consistent + +## 11.0.6 - 2024-04-21 + +- [@alissn](https://github.com/alissn) change package version to Pretty on php artisan about +- [@alissn](https://github.com/alissn) fix stubs composer for app_folder +- [@dcblogdev](https://github.com/dcblogdev) added make-service command + +## 11.0.5 - 2024-04-17 + +## Changes + +- [@alissn](https://github.com/alissn) check command has direction option, load module with 'priority' + + +## 11.0.4 - 2024-04-08 + +## Changes + +- [@dcblogdev](https://github.com/dcblogdev) Updated config to use namespace and path for seeders and factories +- [@solomon-ochepa](https://github.com/solomon-ochepa) Updated vendor / author keys for config/.env +- [@enterprime](https://github.com/enterprime) Corrected factories to Factories and added cache options to ENV + +## Added + +- [@dcblogdev](https://github.com/dcblogdev) Added return type array definition +- [@dcblogdev](https://github.com/dcblogdev) Added test to confirm author details + +## 11.0.3 - 2024-03-24 + +## Added + +- [@enterprime](https://github.com/enterprime) Passing the values of vendor, author's name, and author's email in a line during module creation. +- [@enterprime](https://github.com/enterprime) control the author through the .env configuration file. + +## 11.0.2 - 2024-03-24 + +## Fixed + +- [@enterprime](https://github.com/enterprime) fixed module:migrate-rollback command + +## 11.0.1 - 2024-03-23 + +## Added + +- [@alissn](https://github.com/alissn) add RouteServiceProvider Configuration in Generator +- [@alissn](https://github.com/alissn) added Laravel Modules package version to command 'about' +- [@dcblogdev](https://github.com/dcblogdev) Added view:make command to generate views + +## Changed + +- [@alissn](https://github.com/alissn) Run command php-cs-fixer fix +- [@solomon-ochepa](https://github.com/solomon-ochepa) updated route-provider.stub to loose the optional namespace + +## 11.0.0 - 2024-03-19 + +## Fixed + +- [@Subtixx](https://github.com/subtixx) Fix Issue #1752 - Hardcoded string + undefined variable +- [@jaymeh](https://github.com/jaymeh) fix: Failed to load module script for static assets such as images +- [@alissn](https://github.com/alissn) Fixing failing tests + +## Changed + +- [@dcblogdev](https://github.com/dcblogdev) ensure class_exists for both Capital and lower case namespaces +- [@dcblogdev](https://github.com/dcblogdev) create database folders by default +- [@dcblogdev](https://github.com/dcblogdev) set route service provider to use blank namespace by default +- [@dcblogdev](https://github.com/dcblogdev) updated tests for compatability with PhpUnit 12 +- [@dcblogdev](https://github.com/dcblogdev) added replacement placeholders in config for API stubs +- [@dcblogdev](https://github.com/dcblogdev) updated vite to rename placeholder with module name +- [@dcblogdev](https://github.com/dcblogdev) Added support for Laravel 11 +- [@solomon-ochepa](https://github.com/solomon-ochepa) updated API route stub to use controller +- [@solomon-ochepa](https://github.com/solomon-ochepa) updated config comments +- [@alissn](https://github.com/alissn) rearrange Command Classes into Folders and Update Namespace Structure +- [@alissn](https://github.com/alissn) delete command module:migrate-fresh +- [@alissn](https://github.com/alissn) Fixing Case of tests/Unit and tests/Feature +- [@alissn](https://github.com/alissn) Updated commands to use Laravel Prompt +- [@dcblogdev](https://github.com/dcblogdev) updated event stub to include Dispatchable and InteractsWithSockets traits + +## 10.0.6 - 2024-01-28 + +## Added + +- [@alissn](https://github.com/alissn) Add command module prune + +## 10.0.5 - 2024-01-22 + +## Added + +- [@azim-kordpour](https://github.com/azim-kordpour) Add PHPDoc static to all methods in Module facade + +## Changed + +- [@dcblogdev](https://github.com/dcblogdev) Reverted config to use `App` and `Database` namespace / folders by default +- [@alissn](https://github.com/alissn) Command Synchronization and Alphabetical Sorting in ConsoleServiceProvider +- [@fpermana](https://github.com/fpermana) Update ObserverMakeCommand.php + +## Fixed + +- [@alissn](https://github.com/alissn) revert extend class to ShowModelCommand +- [@benjaminniess](https://github.com/benjaminniess) Fix ModelShowCommand extends property + + +## 10.0.4 - 2023-11-13 + +## Changed +- [@dcblogdev](https://github.com/dcblogdev) updated module:publish-config to a dynamic path to the service provider + +## 10.0.3 - 2023-10-02 + +## Changed + +- [@solomon-ochepa](https://github.com/solomon-ochepa) updated multiple & config stubs to follow modern laravel standards +- [@dcblogdev](https://github.com/dcblogdev) updated enabled `$MODULE_NAMESPACE$` & `$CONTROLLER_NAMESPACE$` placeholders to be used inside stubs +- [@hungthai1401](https://github.com/hungthai1401) updated rule stub + +## Added + +- [@dcblogdev](https://github.com/dcblogdev) added support for using modules inside the main `vite.config.js` file https://github.com/nWidart/laravel-modules/pull/1682 +- [@dcblogdev](https://github.com/dcblogdev) added option to generate a factory by using the flag `-f` when generating a model +- [@hungthai1401](https://github.com/hungthai1401 ) added implicit rule https://github.com/nWidart/laravel-modules/pull/1664 + + +## 10.0.2 - 2023-09-18 + +## Changed + +- reordered config commands and added missing observer command + +## 10.0.1 - 2023-09-18 + +## Added + +- [@JaberWiki](https://github.com/JaberWiki) Added Include an optional flag `subpath` for rolling back a module's specific migration file [#1626](https://github.com/nWidart/laravel-modules/pull/1626) +- [@sergiy-petrov](https://github.com/sergiy-petrov) Added support for testing GitHub actions against PHP versions 8.2 and 8.3. [#1624](https://github.com/nWidart/laravel-modules/pull/1624) +- [@hanieas](https://github.com/hanieas) Added make Observer command. [#1623](https://github.com/nWidart/laravel-modules/pull/1623) +- [@alissn](https://github.com/alissn) Add phpdoc to Module facade class for IDE auto-completion. [#1589](https://github.com/nWidart/laravel-modules/pull/1589) +- [@aryala7](https://github.com/aryala7) Add command to create broadcasting channel [#1599](https://github.com/nWidart/laravel-modules/pull/1599) + +## Changed + +- [@Rattone](https://github.com/Rattone) Updated stubs for command from `name` to `signature` [#1625](https://github.com/nWidart/laravel-modules/pull/1625) +- [@moeen-basra](https://github.com/moeen-basra) Remove the unused Factory import [#1596](https://github.com/nWidart/laravel-modules/pull/1596) +- [@moeen-basra](https://github.com/moeen-basra) Replace the \Config::get with config function [#1596](https://github.com/nWidart/laravel-modules/pull/1596) +- [@aryala7](https://github.com/aryala7) Changed disable module Command to accept array of modules instead of single module to disable [#1591](https://github.com/nWidart/laravel-modules/pull/1591) + +## 10.0.0 - 2023-02-14 ### Changed diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..10bdde2e0 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,41 @@ +# CONTRIBUTING + +Contributions are welcome, and are accepted via pull requests. +Please review these guidelines before submitting any pull requests. + +## Process + +1. Fork the project +1. Create a new branch +1. Code, test, commit and push +1. Open a pull request detailing your changes. + +## Guidelines + +* Please ensure the coding style running `composer pcf`. +* * Pull requests should be accompanied by passing tests. +* Please remember ensure you commit to the correct major version, IE v11 for Laravel 11. + +## Setup + +Clone your fork, then install the dev dependencies: +```bash +composer install +``` +## PHP CS Fixer + +Run php-cs-fixer: +```bash +composer pcf +``` +## Tests + +Run all tests: +```bash +composer test +``` + +Check coverage: +```bash +composer test-coverage +``` diff --git a/README.md b/README.md index abee5b7ae..a0d8528f7 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,7 @@ [![Latest Version on Packagist](https://img.shields.io/packagist/v/nwidart/laravel-modules.svg?style=flat-square)](https://packagist.org/packages/nwidart/laravel-modules) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) -[![Build Status](https://img.shields.io/travis/nWidart/laravel-modules/master.svg?style=flat-square)](https://travis-ci.org/nWidart/laravel-modules) [![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/nWidart/laravel-modules.svg?maxAge=86400&style=flat-square)](https://scrutinizer-ci.com/g/nWidart/laravel-modules/?branch=master) -[![Quality Score](https://img.shields.io/scrutinizer/g/nWidart/laravel-modules.svg?style=flat-square)](https://scrutinizer-ci.com/g/nWidart/laravel-modules) [![Total Downloads](https://img.shields.io/packagist/dt/nwidart/laravel-modules.svg?style=flat-square)](https://packagist.org/packages/nwidart/laravel-modules) | **Laravel** | **laravel-modules** | @@ -19,18 +17,20 @@ | 8.0 | ^8.0 | | 9.0 | ^9.0 | | 10.0 | ^10.0 | +| 11.0 | ^11.0 | -`nwidart/laravel-modules` is a Laravel package which created to manage your large Laravel app using modules. Module is like a Laravel package, it has some views, controllers or models. This package is supported and tested in Laravel 10. +`nwidart/laravel-modules` is a Laravel package created to manage your large Laravel app using modules. A Module is like a Laravel package, it has some views, controllers or models. This package is supported and tested in Laravel 11. -This package is a re-published, re-organised and maintained version of [pingpong/modules](https://github.com/pingpong-labs/modules), which isn't maintained anymore. This package is used in [AsgardCMS](https://asgardcms.com/). +This package is a re-published, re-organised and maintained version of [pingpong/modules](https://github.com/pingpong-labs/modules), which isn't maintained anymore. -With one big added bonus that the original package didn't have: **tests**. +With one big bonus that the original package didn't have: **tests**. -Find out why you should use this package in the article: [Writing modular applications with laravel-modules](https://nicolaswidart.com/blog/writing-modular-applications-with-laravel-modules). +## upgrade +To upgrade to version V11 follow [Upgrade Guide](https://laravelmodules.com/docs/v11/upgrade) on official document. ## Install -To install through Composer, by run the following command: +To install via Composer, run: ``` bash composer require nwidart/laravel-modules @@ -46,26 +46,36 @@ php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProv ### Autoloading -By default, the module classes are not loaded automatically. You can autoload your modules using `psr-4`. For example: - -``` json -{ - "autoload": { - "psr-4": { - "App\\": "app/", - "Modules\\": "Modules/", - "Database\\Factories\\": "database/factories/", - "Database\\Seeders\\": "database/seeders/" - } - -} +By default, the module classes are not loaded automatically. You can autoload your modules by adding merge-plugin to the extra section: + +```json +"extra": { + "laravel": { + "dont-discover": [] + }, + "merge-plugin": { + "include": [ + "Modules/*/composer.json" + ] + } +}, ``` **Tip: don't forget to run `composer dump-autoload` afterwards.** ## Documentation -You'll find installation instructions and full documentation on [https://docs.laravelmodules.com/](https://docs.laravelmodules.com/). +You'll find installation instructions and full documentation on [https://laravelmodules.com/](https://laravelmodules.com/docs). + +## Demo + +You can see a demo using Laravel Breeze at https://github.com/laravel-modules-com/breeze-demo + +This is a complete application using Auth, Base and Profile modules. + +## Community + +We also have a Discord community. [https://discord.gg/hkF7BRvRZK](https://discord.gg/hkF7BRvRZK) For quick help, ask questions in the appropriate channel. ## Credits @@ -74,11 +84,6 @@ You'll find installation instructions and full documentation on [https://docs.la - [gravitano](https://github.com/gravitano) - [All Contributors](../../contributors) -## About Nicolas Widart - -Nicolas Widart is a freelance web developer specialising on the Laravel framework. View all my packages [on my website](https://nwidart.com/), or visit [my website](https://nicolaswidart.com). - - ## License The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/composer.json b/composer.json index 91c4c62a7..2bce92201 100644 --- a/composer.json +++ b/composer.json @@ -18,15 +18,17 @@ } ], "require": { - "php": ">=8.1", - "ext-json": "*" + "php": ">=8.2", + "ext-json": "*", + "wikimedia/composer-merge-plugin": "^2.1" }, "require-dev": { - "phpunit/phpunit": "^10.0", - "mockery/mockery": "^1.5", - "orchestra/testbench": "^8.0", - "friendsofphp/php-cs-fixer": "^3.6", - "laravel/framework": "^10.0", + "phpunit/phpunit": "^11.0", + "mockery/mockery": "^1.6", + "orchestra/testbench": "^v9.0", + "friendsofphp/php-cs-fixer": "^v3.52", + "laravel/framework": "^v11.0", + "laravel/pint": "^1.16", "spatie/phpunit-snapshot-assertions": "^5.0", "phpstan/phpstan": "^1.4" }, @@ -54,13 +56,19 @@ } }, "branch-alias": { - "dev-master": "10.0-dev" + "dev-master": "11.0-dev" + } + }, + "config": { + "allow-plugins": { + "wikimedia/composer-merge-plugin": true } }, "scripts": { - "update-snapshots": "./vendor/bin/phpunit --no-coverage -d --update-snapshots", - "test": "vendor/bin/phpunit", - "test-coverage": "vendor/bin/phpunit --coverage-html coverage", + "update-snapshots": "./phpunit --no-coverage -d --update-snapshots", + "lint": "pint", + "test": "phpunit", + "test-coverage": "phpunit --coverage-html coverage", "pcf": "vendor/bin/php-cs-fixer fix --verbose" }, "minimum-stability": "dev", diff --git a/config/config.php b/config/config.php index 0936d185d..d7228eaef 100644 --- a/config/config.php +++ b/config/config.php @@ -1,7 +1,7 @@ 'Modules', /* @@ -24,26 +23,25 @@ | Default module stubs. | */ - 'stubs' => [ 'enabled' => false, 'path' => base_path('vendor/nwidart/laravel-modules/src/Commands/stubs'), 'files' => [ - 'routes/web' => 'Routes/web.php', - 'routes/api' => 'Routes/api.php', - 'views/index' => 'Resources/views/index.blade.php', - 'views/master' => 'Resources/views/layouts/master.blade.php', - 'scaffold/config' => 'Config/config.php', + 'routes/web' => 'routes/web.php', + 'routes/api' => 'routes/api.php', + 'views/index' => 'resources/views/index.blade.php', + 'views/master' => 'resources/views/layouts/master.blade.php', + 'scaffold/config' => 'config/config.php', 'composer' => 'composer.json', - 'assets/js/app' => 'Resources/assets/js/app.js', - 'assets/sass/app' => 'Resources/assets/sass/app.scss', + 'assets/js/app' => 'resources/assets/js/app.js', + 'assets/sass/app' => 'resources/assets/sass/app.scss', 'vite' => 'vite.config.js', 'package' => 'package.json', ], 'replacements' => [ - 'routes/web' => ['LOWER_NAME', 'STUDLY_NAME'], - 'routes/api' => ['LOWER_NAME'], - 'vite' => ['LOWER_NAME'], + 'routes/web' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE', 'CONTROLLER_NAMESPACE'], + 'routes/api' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE', 'CONTROLLER_NAMESPACE'], + 'vite' => ['LOWER_NAME', 'STUDLY_NAME'], 'json' => ['LOWER_NAME', 'STUDLY_NAME', 'MODULE_NAMESPACE', 'PROVIDER_NAMESPACE'], 'views/index' => ['LOWER_NAME'], 'views/master' => ['LOWER_NAME', 'STUDLY_NAME'], @@ -56,6 +54,7 @@ 'AUTHOR_EMAIL', 'MODULE_NAMESPACE', 'PROVIDER_NAMESPACE', + 'APP_FOLDER_NAME', ], ], 'gitkeep' => true, @@ -66,127 +65,144 @@ | Modules path |-------------------------------------------------------------------------- | - | This path used for save the generated module. This path also will be added - | automatically to list of scanned folders. + | This path is used to save the generated module. + | This path will also be added automatically to the list of scanned folders. | */ - 'modules' => base_path('Modules'), + /* |-------------------------------------------------------------------------- | Modules assets path |-------------------------------------------------------------------------- | - | Here you may update the modules assets path. + | Here you may update the modules' assets path. | */ - 'assets' => public_path('modules'), + /* |-------------------------------------------------------------------------- - | The migrations path + | The migrations' path |-------------------------------------------------------------------------- | - | Where you run 'module:publish-migration' command, where do you publish the + | Where you run the 'module:publish-migration' command, where do you publish the | the migration files? | */ - 'migration' => base_path('database/migrations'), + + /* + |-------------------------------------------------------------------------- + | The app path + |-------------------------------------------------------------------------- + | + | app folder name + | for example can change it to 'src' or 'App' + */ + 'app_folder' => 'app/', + /* |-------------------------------------------------------------------------- | Generator path |-------------------------------------------------------------------------- | Customise the paths where the folders will be generated. - | Set the generate key to false to not generate that folder + | Setting the generate key to false will not generate that folder */ 'generator' => [ - 'config' => ['path' => 'Config', 'generate' => true], - 'command' => ['path' => 'Console', 'generate' => true], - 'migration' => ['path' => 'Database/Migrations', 'generate' => true], - 'seeder' => ['path' => 'Database/Seeders', 'generate' => true], - 'factory' => ['path' => 'Database/factories', 'generate' => true], - 'model' => ['path' => 'Entities', 'generate' => true], - 'routes' => ['path' => 'Routes', 'generate' => true], - 'controller' => ['path' => 'Http/Controllers', 'generate' => true], - 'filter' => ['path' => 'Http/Middleware', 'generate' => true], - 'request' => ['path' => 'Http/Requests', 'generate' => true], - 'provider' => ['path' => 'Providers', 'generate' => true], - 'assets' => ['path' => 'Resources/assets', 'generate' => true], - 'lang' => ['path' => 'Resources/lang', 'generate' => true], - 'views' => ['path' => 'Resources/views', 'generate' => true], - 'test' => ['path' => 'Tests/Unit', 'generate' => true], - 'test-feature' => ['path' => 'Tests/Feature', 'generate' => true], - 'repository' => ['path' => 'Repositories', 'generate' => false], - 'event' => ['path' => 'Events', 'generate' => false], - 'listener' => ['path' => 'Listeners', 'generate' => false], - 'policies' => ['path' => 'Policies', 'generate' => false], - 'rules' => ['path' => 'Rules', 'generate' => false], - 'jobs' => ['path' => 'Jobs', 'generate' => false], - 'emails' => ['path' => 'Emails', 'generate' => false], - 'notifications' => ['path' => 'Notifications', 'generate' => false], - 'resource' => ['path' => 'Transformers', 'generate' => false], - 'component-view' => ['path' => 'Resources/views/components', 'generate' => false], - 'component-class' => ['path' => 'View/Components', 'generate' => false], + // app/ + 'actions' => ['path' => 'app/Actions', 'generate' => false], + 'casts' => ['path' => 'app/Casts', 'generate' => false], + 'channels' => ['path' => 'app/Broadcasting', 'generate' => false], + 'class' => ['path' => 'app/Classes', 'generate' => false], + 'command' => ['path' => 'app/Console', 'generate' => false], + 'component-class' => ['path' => 'app/View/Components', 'generate' => false], + 'emails' => ['path' => 'app/Emails', 'generate' => false], + 'event' => ['path' => 'app/Events', 'generate' => false], + 'enums' => ['path' => 'app/Enums', 'generate' => false], + 'exceptions' => ['path' => 'app/Exceptions', 'generate' => false], + 'jobs' => ['path' => 'app/Jobs', 'generate' => false], + 'helpers' => ['path' => 'app/Helpers', 'generate' => false], + 'interfaces' => ['path' => 'app/Interfaces', 'generate' => false], + 'listener' => ['path' => 'app/Listeners', 'generate' => false], + 'model' => ['path' => 'app/Models', 'generate' => false], + 'notifications' => ['path' => 'app/Notifications', 'generate' => false], + 'observer' => ['path' => 'app/Observers', 'generate' => false], + 'policies' => ['path' => 'app/Policies', 'generate' => false], + 'provider' => ['path' => 'app/Providers', 'generate' => true], + 'repository' => ['path' => 'app/Repositories', 'generate' => false], + 'resource' => ['path' => 'app/Transformers', 'generate' => false], + 'route-provider' => ['path' => 'app/Providers', 'generate' => true], + 'rules' => ['path' => 'app/Rules', 'generate' => false], + 'services' => ['path' => 'app/Services', 'generate' => false], + 'scopes' => ['path' => 'app/Models/Scopes', 'generate' => false], + 'traits' => ['path' => 'app/Traits', 'generate' => false], + + // app/Http/ + 'controller' => ['path' => 'app/Http/Controllers', 'generate' => true], + 'filter' => ['path' => 'app/Http/Middleware', 'generate' => false], + 'request' => ['path' => 'app/Http/Requests', 'generate' => false], + + // config/ + 'config' => ['path' => 'config', 'generate' => true], + + // database/ + 'factory' => ['path' => 'database/factories', 'generate' => true], + 'migration' => ['path' => 'database/migrations', 'generate' => true], + 'seeder' => ['path' => 'database/seeders', 'generate' => true], + + // lang/ + 'lang' => ['path' => 'lang', 'generate' => false], + + // resource/ + 'assets' => ['path' => 'resources/assets', 'generate' => true], + 'component-view' => ['path' => 'resources/views/components', 'generate' => false], + 'views' => ['path' => 'resources/views', 'generate' => true], + + // routes/ + 'routes' => ['path' => 'routes', 'generate' => true], + + // tests/ + 'test-feature' => ['path' => 'tests/Feature', 'generate' => true], + 'test-unit' => ['path' => 'tests/Unit', 'generate' => true], ], ], + /* + |-------------------------------------------------------------------------- + | Auto Discover of Modules + |-------------------------------------------------------------------------- + | + | Here you configure auto discover of module + | This is useful for simplify module providers. + | + */ + 'auto-discover' => [ + /* + |-------------------------------------------------------------------------- + | Migrations + |-------------------------------------------------------------------------- + | + | This option for register migration automatically. + | + */ + 'migrations' => true, + + ], + /* |-------------------------------------------------------------------------- | Package commands |-------------------------------------------------------------------------- | | Here you can define which commands will be visible and used in your - | application. If for example you don't use some of the commands provided - | you can simply comment them out. + | application. You can add your own commands to merge section. | */ - 'commands' => [ - Commands\CommandMakeCommand::class, - Commands\ComponentClassMakeCommand::class, - Commands\ComponentViewMakeCommand::class, - Commands\ControllerMakeCommand::class, - Commands\DisableCommand::class, - Commands\DumpCommand::class, - Commands\EnableCommand::class, - Commands\EventMakeCommand::class, - Commands\JobMakeCommand::class, - Commands\ListenerMakeCommand::class, - Commands\MailMakeCommand::class, - Commands\MiddlewareMakeCommand::class, - Commands\NotificationMakeCommand::class, - Commands\ProviderMakeCommand::class, - Commands\RouteProviderMakeCommand::class, - Commands\InstallCommand::class, - Commands\ListCommand::class, - Commands\ModuleDeleteCommand::class, - Commands\ModuleMakeCommand::class, - Commands\FactoryMakeCommand::class, - Commands\PolicyMakeCommand::class, - Commands\RequestMakeCommand::class, - Commands\RuleMakeCommand::class, - Commands\MigrateCommand::class, - Commands\MigrateFreshCommand::class, - Commands\MigrateRefreshCommand::class, - Commands\MigrateResetCommand::class, - Commands\MigrateRollbackCommand::class, - Commands\MigrateStatusCommand::class, - Commands\MigrationMakeCommand::class, - Commands\ModelMakeCommand::class, - Commands\PublishCommand::class, - Commands\PublishConfigurationCommand::class, - Commands\PublishMigrationCommand::class, - Commands\PublishTranslationCommand::class, - Commands\SeedCommand::class, - Commands\SeedMakeCommand::class, - Commands\SetupCommand::class, - Commands\UnUseCommand::class, - Commands\UpdateCommand::class, - Commands\UseCommand::class, - Commands\ResourceMakeCommand::class, - Commands\TestMakeCommand::class, - Commands\LaravelModulesV6Migrator::class, - ], + 'commands' => ConsoleServiceProvider::defaultCommands() + ->merge([ + // New commands go here + ])->toArray(), /* |-------------------------------------------------------------------------- @@ -197,27 +213,26 @@ | directory. This is useful if you host the package in packagist website. | */ - 'scan' => [ 'enabled' => false, 'paths' => [ base_path('vendor/*/*'), ], ], + /* |-------------------------------------------------------------------------- | Composer File Template |-------------------------------------------------------------------------- | - | Here is the config for composer.json file, generated by this package + | Here is the config for the composer.json file, generated by this package | */ - 'composer' => [ - 'vendor' => 'nwidart', + 'vendor' => env('MODULE_VENDOR', 'nwidart'), 'author' => [ - 'name' => 'Nicolas Widart', - 'email' => 'n.widart@gmail.com', + 'name' => env('MODULE_AUTHOR_NAME', 'Nicolas Widart'), + 'email' => env('MODULE_AUTHOR_EMAIL', 'n.widart@gmail.com'), ], 'composer-output' => false, ], @@ -227,15 +242,16 @@ | Caching |-------------------------------------------------------------------------- | - | Here is the config for setting up caching feature. + | Here is the config for setting up the caching feature. | */ 'cache' => [ - 'enabled' => false, - 'driver' => 'file', - 'key' => 'laravel-modules', - 'lifetime' => 60, + 'enabled' => env('MODULES_CACHE_ENABLED', false), + 'driver' => env('MODULES_CACHE_DRIVER', 'file'), + 'key' => env('MODULES_CACHE_KEY', 'laravel-modules'), + 'lifetime' => env('MODULES_CACHE_LIFETIME', 60), ], + /* |-------------------------------------------------------------------------- | Choose what laravel-modules will register as custom namespaces. @@ -247,10 +263,6 @@ 'translations' => true, /** * load files on boot or register method - * - * Note: boot not compatible with asgardcms - * - * @example boot|register */ 'files' => 'register', ], @@ -260,7 +272,7 @@ | Activators |-------------------------------------------------------------------------- | - | You can define new types of activators here, file, database etc. The only + | You can define new types of activators here, file, database, etc. The only | required parameter is 'class'. | The file activator will store the activation status in storage/installed_modules */ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4712d716f..0526c79bc 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,26 +1,23 @@ - - - - tests - - - - - src/ - - - - - - - - - - + + + + tests + + + + + + + + + + + + + + + src/ + + diff --git a/pint.json b/pint.json new file mode 100644 index 000000000..93061b6bd --- /dev/null +++ b/pint.json @@ -0,0 +1,3 @@ +{ + "preset": "laravel" +} diff --git a/scripts/vite-module-loader.js b/scripts/vite-module-loader.js new file mode 100644 index 000000000..ffaa429d0 --- /dev/null +++ b/scripts/vite-module-loader.js @@ -0,0 +1,47 @@ +import fs from 'fs/promises'; +import path from 'path'; + +async function collectModuleAssetsPaths(paths, modulesPath) { + modulesPath = path.join(__dirname, modulesPath); + + const moduleStatusesPath = path.join(__dirname, 'modules_statuses.json'); + + try { + // Read module_statuses.json + const moduleStatusesContent = await fs.readFile(moduleStatusesPath, 'utf-8'); + const moduleStatuses = JSON.parse(moduleStatusesContent); + + // Read module directories + const moduleDirectories = await fs.readdir(modulesPath); + + for (const moduleDir of moduleDirectories) { + if (moduleDir === '.DS_Store') { + // Skip .DS_Store directory + continue; + } + + // Check if the module is enabled (status is true) + if (moduleStatuses[moduleDir] === true) { + const viteConfigPath = path.join(modulesPath, moduleDir, 'vite.config.js'); + + try { + await fs.access(viteConfigPath); + // Import the module-specific Vite configuration + const moduleConfig = await import(viteConfigPath); + + if (moduleConfig.paths && Array.isArray(moduleConfig.paths)) { + paths.push(...moduleConfig.paths); + } + } catch (error) { + // vite.config.js does not exist, skip this module + } + } + } + } catch (error) { + console.error(`Error reading module statuses or module configurations: ${error}`); + } + + return paths; +} + +export default collectModuleAssetsPaths; diff --git a/src/Activators/FileActivator.php b/src/Activators/FileActivator.php index 6e09c06d4..9548583a6 100644 --- a/src/Activators/FileActivator.php +++ b/src/Activators/FileActivator.php @@ -70,8 +70,6 @@ public function __construct(Container $app) /** * Get the path of the file where statuses are stored - * - * @return string */ public function getStatusesFilePath(): string { @@ -79,7 +77,7 @@ public function getStatusesFilePath(): string } /** - * @inheritDoc + * {@inheritDoc} */ public function reset(): void { @@ -91,7 +89,7 @@ public function reset(): void } /** - * @inheritDoc + * {@inheritDoc} */ public function enable(Module $module): void { @@ -99,7 +97,7 @@ public function enable(Module $module): void } /** - * @inheritDoc + * {@inheritDoc} */ public function disable(Module $module): void { @@ -107,11 +105,11 @@ public function disable(Module $module): void } /** - * @inheritDoc + * {@inheritDoc} */ public function hasStatus(Module $module, bool $status): bool { - if (!isset($this->modulesStatuses[$module->getName()])) { + if (! isset($this->modulesStatuses[$module->getName()])) { return $status === false; } @@ -119,7 +117,7 @@ public function hasStatus(Module $module, bool $status): bool } /** - * @inheritDoc + * {@inheritDoc} */ public function setActive(Module $module, bool $active): void { @@ -127,7 +125,7 @@ public function setActive(Module $module, bool $active): void } /** - * @inheritDoc + * {@inheritDoc} */ public function setActiveByName(string $name, bool $status): void { @@ -137,11 +135,11 @@ public function setActiveByName(string $name, bool $status): void } /** - * @inheritDoc + * {@inheritDoc} */ public function delete(Module $module): void { - if (!isset($this->modulesStatuses[$module->getName()])) { + if (! isset($this->modulesStatuses[$module->getName()])) { return; } unset($this->modulesStatuses[$module->getName()]); @@ -159,12 +157,12 @@ private function writeJson(): void /** * Reads the json file that contains the activation statuses. - * @return array + * * @throws FileNotFoundException */ private function readJson(): array { - if (!$this->files->exists($this->statusesFile)) { + if (! $this->files->exists($this->statusesFile)) { return []; } @@ -174,12 +172,12 @@ private function readJson(): array /** * Get modules statuses, either from the cache or from * the json statuses file if the cache is disabled. - * @return array + * * @throws FileNotFoundException */ private function getModulesStatuses(): array { - if (!$this->config->get('modules.cache.enabled')) { + if (! $this->config->get('modules.cache.enabled')) { return $this->readJson(); } @@ -191,13 +189,11 @@ private function getModulesStatuses(): array /** * Reads a config parameter under the 'activators.file' key * - * @param string $key - * @param $default * @return mixed */ private function config(string $key, $default = null) { - return $this->config->get('modules.activators.file.' . $key, $default); + return $this->config->get('modules.activators.file.'.$key, $default); } /** diff --git a/src/Collection.php b/src/Collection.php index 05ac08328..36351fcd2 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -27,7 +27,7 @@ public function toArray() return array_map(function ($value) { if ($value instanceof Module) { $attributes = $value->json()->getAttributes(); - $attributes["path"] = $value->getPath(); + $attributes['path'] = $value->getPath(); return $attributes; } diff --git a/src/Commands/CheckLangCommand.php b/src/Commands/Actions/CheckLangCommand.php similarity index 73% rename from src/Commands/CheckLangCommand.php rename to src/Commands/Actions/CheckLangCommand.php index 83e355555..73111f971 100644 --- a/src/Commands/CheckLangCommand.php +++ b/src/Commands/Actions/CheckLangCommand.php @@ -1,14 +1,12 @@ langPath = DIRECTORY_SEPARATOR . config('modules.paths.generator.lang.path', 'Resources/lang'); - - $this->components->alert('Checking languages ...'); - - $this->newLine(); - - if ($name = $this->argument('module')) { - $this->check($name); - - return 0; - } - - $this->checkAll(); - - return 0; - + $this->langPath = DIRECTORY_SEPARATOR.config('modules.paths.generator.lang.path', 'Resources/lang'); } - /** - * enableAll - * - * @return void - */ - public function checkAll() + public function executeAction($name): void { - $modules = $this->laravel['modules']->all(); - - foreach ($modules as $module) { - $this->check($module); - } - } - - /** - * enable - * - * @param string $name - * @return void - */ - public function check($name) - { - if ($name instanceof Module) { - $module = $name; - } else { - $module = $this->laravel['modules']->findOrFail($name); - } + $module = $this->getModuleModel($name); $directories = $this->getDirectories($module); @@ -90,22 +46,15 @@ public function check($name) } - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() + public function getInfo(): ?string { - return [ - ['module', InputArgument::OPTIONAL, 'Module name.'], - ]; + return 'Checking languages ...'; } private function getLangFiles($module) { $files = []; - $path = $module->getPath() . $this->langPath; + $path = $module->getPath().$this->langPath; if (is_dir($path)) { $files = array_merge($files, $this->laravel['files']->all($path)); } @@ -116,28 +65,31 @@ private function getLangFiles($module) private function getDirectories($module) { $moduleName = $module->getStudlyName(); - $path = $module->getPath() . '/Resources/lang'; + $path = $module->getPath().$this->langPath; + $directories = []; if (is_dir($path)) { $directories = $this->laravel['files']->directories($path); $directories = array_map(function ($directory) use ($moduleName) { return [ - 'name' => basename($directory), + 'name' => basename($directory), 'module' => $moduleName, - 'path' => $directory, - 'files' => array_map(function ($file) { + 'path' => $directory, + 'files' => array_map(function ($file) { return basename($file); - }, \File::glob($directory . DIRECTORY_SEPARATOR . "*")), + }, \File::glob($directory.DIRECTORY_SEPARATOR.'*')), ]; }, $directories); } if (count($directories) == 0) { $this->components->info("No language files found in module $moduleName"); + return false; } if (count($directories) == 1) { $this->components->warn("Only one language file found in module $moduleName"); + return false; } @@ -184,15 +136,14 @@ private function checkMissingFiles(Collection $directories) private function checkMissingKeys(Collection $directories) { //show missing keys - $uniqeLangFiles = $directories->pluck('files')->flatten()->unique(); + $uniqeLangFiles = $directories->pluck('files')->flatten()->unique(); $langDirectories = $directories->pluck('name'); - $missingKeysMessage = []; $directories->each(function ($directory) use ($uniqeLangFiles, $langDirectories, &$missingKeysMessage) { $uniqeLangFiles->each(function ($file) use ($directory, $langDirectories, &$missingKeysMessage) { - $langKeys = $this->getLangKeys($directory['path'] . DIRECTORY_SEPARATOR . $file); + $langKeys = $this->getLangKeys($directory['path'].DIRECTORY_SEPARATOR.$file); if ($langKeys == false) { return; @@ -204,7 +155,7 @@ private function checkMissingKeys(Collection $directories) $basePath = str_replace($directory['name'], $langDirectory, $directory['path']); - $otherLangKeys = $this->getLangKeys($basePath . DIRECTORY_SEPARATOR . $file); + $otherLangKeys = $this->getLangKeys($basePath.DIRECTORY_SEPARATOR.$file); if ($otherLangKeys == false) { return; @@ -223,7 +174,6 @@ private function checkMissingKeys(Collection $directories) }); }); - if (count($missingKeysMessage) > 0) { collect($missingKeysMessage)->each(function ($messages, $langDirectory) { @@ -243,6 +193,7 @@ private function getLangKeys($file) { if (\File::exists($file)) { $lang = \File::getRequire($file); + return collect(\Arr::dot($lang))->keys(); } else { return false; diff --git a/src/Commands/Actions/DisableCommand.php b/src/Commands/Actions/DisableCommand.php new file mode 100644 index 000000000..03c192a61 --- /dev/null +++ b/src/Commands/Actions/DisableCommand.php @@ -0,0 +1,47 @@ +getModuleModel($name); + + $status = $module->isDisabled() + ? 'Disabled' + : 'Enabled'; + + $this->components->task("Disabling {$module->getName()} Module, old status: $status", function () use ($module) { + $module->disable(); + }); + } + + public function getInfo(): ?string + { + return 'Disabling module ...'; + } +} diff --git a/src/Commands/Actions/DumpCommand.php b/src/Commands/Actions/DumpCommand.php new file mode 100644 index 000000000..094aad8d3 --- /dev/null +++ b/src/Commands/Actions/DumpCommand.php @@ -0,0 +1,38 @@ +getModuleModel($name); + + $this->components->task("Generating for {$module->getName()} Module", function () use ($module) { + chdir($module->getPath()); + + passthru('composer dump -o -n -q'); + }); + } + + public function getInfo(): ?string + { + return 'Generating optimized autoload modules'; + } +} diff --git a/src/Commands/Actions/EnableCommand.php b/src/Commands/Actions/EnableCommand.php new file mode 100644 index 000000000..10e3be36e --- /dev/null +++ b/src/Commands/Actions/EnableCommand.php @@ -0,0 +1,40 @@ +getModuleModel($name); + + $status = $module->isDisabled() + ? 'Disabled' + : 'Enabled'; + + $this->components->task("Enabling {$module->getName()} Module, old status: $status", function () use ($module) { + $module->enable(); + }); + } + + public function getInfo(): ?string + { + return 'Disabling module ...'; + } +} diff --git a/src/Commands/InstallCommand.php b/src/Commands/Actions/InstallCommand.php similarity index 92% rename from src/Commands/InstallCommand.php rename to src/Commands/Actions/InstallCommand.php index 108a5c3a3..3d8e707a9 100644 --- a/src/Commands/InstallCommand.php +++ b/src/Commands/Actions/InstallCommand.php @@ -1,6 +1,6 @@ error("File 'modules.json' does not exist in your project root."); return E_ERROR; @@ -82,10 +82,10 @@ protected function installFromFile(): int /** * Install the specified module. * - * @param string $name - * @param string $version - * @param string $type - * @param bool $tree + * @param string $name + * @param string $version + * @param string $type + * @param bool $tree */ protected function install($name, $version = 'dev-master', $type = 'composer', $tree = false) { @@ -110,7 +110,7 @@ protected function install($name, $version = 'dev-master', $type = 'composer', $ $installer->run(); - if (!$this->option('no-update')) { + if (! $this->option('no-update')) { $this->call('module:update', [ 'module' => $installer->getModuleName(), ]); diff --git a/src/Commands/ListCommand.php b/src/Commands/Actions/ListCommand.php similarity index 98% rename from src/Commands/ListCommand.php rename to src/Commands/Actions/ListCommand.php index 5a4e023bf..b5236a581 100644 --- a/src/Commands/ListCommand.php +++ b/src/Commands/Actions/ListCommand.php @@ -1,6 +1,6 @@ option('all')) { + $input->setArgument('module', [self::ALL]); + + return; + } + + $selected_item = multiselect( + label : 'Select Modules', + options : [ + self::ALL, + ...array_keys(Module::all()), + ], + required: 'You must select at least one module', + ); + + $input->setArgument( + 'module', + value: in_array(self::ALL, $selected_item) + ? [self::ALL] + : $selected_item + ); + } + + /** + * Determine the models that should be pruned. + */ + protected function models(): Collection + { + if (! empty($models = $this->option('model'))) { + return collect($models)->filter(function ($model) { + return class_exists($model); + })->values(); + } + + $except = $this->option('except'); + + if (! empty($models) && ! empty($except)) { + throw new InvalidArgumentException('The --models and --except options cannot be combined.'); + } + + if ($this->argument('module') == [self::ALL]) { + $path = sprintf( + '%s/*/%s', + config('modules.paths.modules'), + config('modules.paths.generator.model.path') + ); + } else { + $path = sprintf( + '%s/{%s}/%s', + config('modules.paths.modules'), + collect($this->argument('module'))->implode(','), + config('modules.paths.generator.model.path') + ); + } + + return collect(Finder::create()->in($path)->files()->name('*.php')) + ->map(function ($model) { + + $namespace = config('modules.namespace'); + + return $namespace.str_replace( + ['/', '.php'], + ['\\', ''], + Str::after($model->getRealPath(), realpath(config('modules.paths.modules'))) + ); + })->values() + ->when(! empty($except), function ($models) use ($except) { + return $models->reject(function ($model) use ($except) { + return in_array($model, $except); + }); + })->filter(function ($model) { + return class_exists($model); + })->filter(function ($model) { + return $this->isPrunable($model); + })->values(); + } +} diff --git a/src/Commands/ModelShowCommand.php b/src/Commands/Actions/ModelShowCommand.php similarity index 80% rename from src/Commands/ModelShowCommand.php rename to src/Commands/Actions/ModelShowCommand.php index 75eddf411..1fe385a75 100644 --- a/src/Commands/ModelShowCommand.php +++ b/src/Commands/Actions/ModelShowCommand.php @@ -1,6 +1,6 @@ getModuleModel($name); + $this->components->task("Deleting {$module->getName()} Module", function () use ($module) { + $module->delete(); + }); + } + + public function getInfo(): ?string + { + return 'deleting module ...'; + } + + public function getConfirmableLabel(): string + { + return 'Warning: Do you want to remove the module?'; + } +} diff --git a/src/Commands/Actions/UnUseCommand.php b/src/Commands/Actions/UnUseCommand.php new file mode 100644 index 000000000..4e94d86fe --- /dev/null +++ b/src/Commands/Actions/UnUseCommand.php @@ -0,0 +1,36 @@ +getModuleModel($name); + + $this->components->task("Forget Using {$module->getName()} Module", function () use ($module) { + $this->laravel['modules']->forgetUsed($module); + }); + } + + public function getInfo(): ?string + { + return 'Forget Using Module ...'; + } +} diff --git a/src/Commands/Actions/UpdateCommand.php b/src/Commands/Actions/UpdateCommand.php new file mode 100644 index 000000000..cbdbf3c03 --- /dev/null +++ b/src/Commands/Actions/UpdateCommand.php @@ -0,0 +1,36 @@ +getModuleModel($name); + + $this->components->task("Updating {$module->getName()} Module", function () use ($module) { + $this->laravel['modules']->update($module); + }); + } + + public function getInfo(): ?string + { + return 'Updating Module ...'; + } +} diff --git a/src/Commands/Actions/UseCommand.php b/src/Commands/Actions/UseCommand.php new file mode 100644 index 000000000..e9d9852e7 --- /dev/null +++ b/src/Commands/Actions/UseCommand.php @@ -0,0 +1,36 @@ +getModuleModel($name); + + $this->components->task("Using {$module->getName()} Module", function () use ($module) { + $this->laravel['modules']->setUsed($module); + }); + } + + public function getInfo(): ?string + { + return 'Using Module ...'; + } +} diff --git a/src/Commands/BaseCommand.php b/src/Commands/BaseCommand.php new file mode 100644 index 000000000..dcb740df1 --- /dev/null +++ b/src/Commands/BaseCommand.php @@ -0,0 +1,146 @@ +getDefinition()->addOption( + option: new InputOption( + name: strtolower(self::ALL), + shortcut: 'a', + mode: InputOption::VALUE_NONE, + description: 'Check all Modules', + ) + ); + + $this->getDefinition()->addArgument( + argument: new InputArgument( + name: 'module', + mode: InputArgument::IS_ARRAY, + description: 'The name of module will be used.', + ) + ); + + if ($this instanceof ConfirmableCommand) { + $this->configureConfirmable(); + } + } + + abstract public function executeAction($name); + + public function getInfo(): ?string + { + return null; + } + + public function getConfirmableLabel(): ?string + { + return 'Warning'; + } + + /** + * Execute the console command. + */ + public function handle() + { + if ($this instanceof ConfirmableCommand) { + if ($this->isProhibited() || + ! $this->confirmToProceed($this->getConfirmableLabel(), fn () => true)) { + return 1; + } + } + + if (! is_null($info = $this->getInfo())) { + $this->components->info($info); + } + + $modules = (array) $this->argument('module'); + + foreach ($modules as $module) { + $this->executeAction($module); + } + } + + protected function promptForMissingArguments(InputInterface $input, OutputInterface $output): void + { + $modules = $this->hasOption('direction') + ? array_keys($this->laravel['modules']->getOrdered($input->hasOption('direction'))) + : array_keys($this->laravel['modules']->all()); + + if ($input->getOption(strtolower(self::ALL))) { + $input->setArgument('module', $modules); + + return; + } + + if (! empty($input->getArgument('module'))) { + return; + } + + $selected_item = multisearch( + label: 'Select Modules', + options: function (string $search_value) use ($modules) { + return collect([ + self::ALL, + ...$modules, + ])->when(strlen($search_value) > 0, function (Collection &$modules) use ($search_value) { + return $modules->filter(fn ($item) => str_contains(strtolower($item), strtolower($search_value))); + })->values()->toArray(); + }, + required: 'You must select at least one module', + ); + + $input->setArgument( + 'module', + value: in_array(self::ALL, $selected_item) + ? $modules + : $selected_item + ); + } + + protected function getModuleModel($name) + { + return $name instanceof \Nwidart\Modules\Module + ? $name + : $this->laravel['modules']->findOrFail($name); + } + + private function configureConfirmable(): void + { + $this->getDefinition() + ->addOption( + option: new InputOption( + name: 'force', + shortcut: null, + mode: InputOption::VALUE_NONE, + description: 'Force the operation to run without confirmation.', + ) + ); + } +} diff --git a/src/Commands/ComposerUpdateCommand.php b/src/Commands/ComposerUpdateCommand.php new file mode 100644 index 000000000..753148fd1 --- /dev/null +++ b/src/Commands/ComposerUpdateCommand.php @@ -0,0 +1,60 @@ +getModuleModel($name); + + $this->components->task("Updating Composer.json {$module->getName()} Module", function () use ($module) { + + $composer_path = $module->getPath().DIRECTORY_SEPARATOR.'composer.json'; + + $composer = json_decode(File::get($composer_path), true); + + $autoload = data_get($composer, 'autoload.psr-4'); + + if (! $autoload) { + return; + } + + $key_name_with_app = sprintf('Modules\\%s\\App\\', $module->getStudlyName()); + + if (! array_key_exists($key_name_with_app, $autoload)) { + return; + } + + unset($autoload[$key_name_with_app]); + $key_name_with_out_app = sprintf('Modules\\%s\\', $module->getStudlyName()); + $autoload[$key_name_with_out_app] = 'app/'; + + data_set($composer, 'autoload.psr-4', $autoload); + + file_put_contents($composer_path, json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + + }); + } + + public function getInfo(): ?string + { + return 'Updating Composer.json of modules...'; + } +} diff --git a/src/Commands/Database/MigrateCommand.php b/src/Commands/Database/MigrateCommand.php new file mode 100644 index 000000000..9d6a35154 --- /dev/null +++ b/src/Commands/Database/MigrateCommand.php @@ -0,0 +1,82 @@ +migrator = app('migrator'); + $this->migration_list = collect($this->migrator->paths()); + } + + public function executeAction($name): void + { + $module = $this->getModuleModel($name); + + $this->components->twoColumnDetail("Running Migration {$module->getName()} Module"); + + $module_path = $module->getPath(); + + $paths = $this->migration_list + ->filter(fn ($path) => str_starts_with($path, $module_path)); + + $this->call('migrate', array_filter([ + '--path' => $paths->toArray(), + '--database' => $this->option('database'), + '--pretend' => $this->option('pretend'), + '--force' => $this->option('force'), + '--realpath' => true, + ])); + + if ($this->option('seed')) { + $this->call('module:seed', ['module' => $module->getName(), '--force' => $this->option('force')]); + } + + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return [ + ['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'], + ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], + ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'], + ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], + ['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'], + ['subpath', null, InputOption::VALUE_OPTIONAL, 'Indicate a subpath to run your migrations from'], + ]; + } +} diff --git a/src/Commands/Database/MigrateFreshCommand.php b/src/Commands/Database/MigrateFreshCommand.php new file mode 100644 index 000000000..24a3c4639 --- /dev/null +++ b/src/Commands/Database/MigrateFreshCommand.php @@ -0,0 +1,103 @@ +migrator = app('migrator'); + $this->migration_paths = collect($this->migrator->paths()); + } + + public function handle(): void + { + // drop tables + $this->components->task('Dropping all tables', fn () => $this->callSilent('db:wipe', array_filter([ + '--database' => $this->option('database'), + '--drop-views' => $this->option('drop-views'), + '--drop-types' => $this->option('drop-types'), + '--force' => true, + ])) == 0); + + // create migration table + $this->call('migrate:install', array_filter([ + '--database' => $this->option('database'), + ])) == 0; + + // run migration of root + $root_paths = $this->migration_paths + ->push($this->laravel->databasePath().DIRECTORY_SEPARATOR.'migrations') + ->reject(fn (string $path) => str_starts_with($path, config('modules.paths.modules'))); + + if ($root_paths->count() > 0) { + $this->components->twoColumnDetail('Running Migration of Root'); + + $this->call('migrate', array_filter([ + '--path' => $root_paths->toArray(), + '--database' => $this->option('database'), + '--pretend' => $this->option('pretend'), + '--force' => $this->option('force'), + '--realpath' => true, + ])); + } + + parent::handle(); + } + + public function executeAction($name): void + { + $module = $this->getModuleModel($name); + + $this->call('module:migrate', array_filter([ + 'module' => $module->getStudlyName(), + '--database' => $this->option('database'), + '--force' => $this->option('force'), + '--seed' => $this->option('seed'), + ])); + } + + /** + * Get the console command options. + */ + protected function getOptions(): array + { + return [ + ['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'], + ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], + ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], + ['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'], + ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'], + ['drop-views', null, InputOption::VALUE_NONE, 'Drop all tables and views'], + ['drop-types', null, InputOption::VALUE_NONE, 'Drop all tables and types (Postgres only)'], + ]; + } +} diff --git a/src/Commands/Database/MigrateRefreshCommand.php b/src/Commands/Database/MigrateRefreshCommand.php new file mode 100644 index 000000000..29aceb060 --- /dev/null +++ b/src/Commands/Database/MigrateRefreshCommand.php @@ -0,0 +1,61 @@ +getModuleModel($name); + + $this->components->task("Refreshing Migration {$module->getName()} module", function () use ($module) { + $this->call('module:migrate-reset', [ + 'module' => $module->getStudlyName(), + '--database' => $this->option('database'), + '--force' => $this->option('force'), + ]); + + $this->call('module:migrate', [ + 'module' => $module->getStudlyName(), + '--database' => $this->option('database'), + '--force' => $this->option('force'), + ]); + + if ($this->option('seed')) { + $this->call('module:seed', [ + 'module' => $module->getStudlyName(), + ]); + } + }); + + } + + /** + * Get the console command options. + */ + protected function getOptions(): array + { + return [ + ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], + ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], + ['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'], + ]; + } +} diff --git a/src/Commands/MigrateResetCommand.php b/src/Commands/Database/MigrateResetCommand.php similarity index 51% rename from src/Commands/MigrateResetCommand.php rename to src/Commands/Database/MigrateResetCommand.php index e468f1f0c..1d71430c3 100644 --- a/src/Commands/MigrateResetCommand.php +++ b/src/Commands/Database/MigrateResetCommand.php @@ -1,14 +1,13 @@ module = $this->laravel['modules']; - - $name = $this->argument('module'); - - if (!empty($name)) { - $this->reset($name); - - return 0; - } - - foreach ($this->module->getOrdered($this->option('direction')) as $module) { - $this->line('Running for module: ' . $module->getName() . ''); - - $this->reset($module); - } - - return 0; - } - - /** - * Rollback migration from the specified module. - * - * @param $module - */ - public function reset($module) + public function executeAction($name): void { - if (is_string($module)) { - $module = $this->module->findOrFail($module); - } + $module = $this->getModuleModel($name); $migrator = new Migrator($module, $this->getLaravel()); $database = $this->option('database'); - if (!empty($database)) { + if (! empty($database)) { $migrator->setDatabase($database); } @@ -84,19 +47,12 @@ public function reset($module) return; } - $this->comment('Nothing to rollback.'); + $this->components->warn("Nothing to rollback on module {$module->getName()}"); } - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() + public function getInfo(): ?string { - return [ - ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], - ]; + return null; } /** diff --git a/src/Commands/Database/MigrateRollbackCommand.php b/src/Commands/Database/MigrateRollbackCommand.php new file mode 100644 index 000000000..c7bf80f19 --- /dev/null +++ b/src/Commands/Database/MigrateRollbackCommand.php @@ -0,0 +1,74 @@ +getModuleModel($name); + + $migrator = new Migrator($module, $this->getLaravel(), $this->option('subpath')); + + $database = $this->option('database'); + + if (! empty($database)) { + $migrator->setDatabase($database); + } + + $migrated = $migrator->rollback(); + + if (count($migrated)) { + foreach ($migrated as $migration) { + $this->components->task("Rollback: {$migration}"); + } + + return; + } + + $this->components->warn("Nothing to rollback on module {$module->getName()}"); + + } + + public function getInfo(): ?string + { + return null; + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return [ + ['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'desc'], + ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], + ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], + ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'], + ['subpath', null, InputOption::VALUE_OPTIONAL, 'Indicate a subpath for modules specific migration file'], + ]; + } +} diff --git a/src/Commands/Database/MigrateStatusCommand.php b/src/Commands/Database/MigrateStatusCommand.php new file mode 100644 index 000000000..70ab2205f --- /dev/null +++ b/src/Commands/Database/MigrateStatusCommand.php @@ -0,0 +1,59 @@ +getModuleModel($name); + + $path = str_replace(base_path(), '', (new Migrator($module, $this->getLaravel()))->getPath()); + + $this->call('migrate:status', [ + '--path' => $path, + '--database' => $this->option('database'), + ]); + } + + public function getInfo(): ?string + { + return null; + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return [ + ['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'], + ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], + ]; + } +} diff --git a/src/Commands/SeedCommand.php b/src/Commands/Database/SeedCommand.php similarity index 72% rename from src/Commands/SeedCommand.php rename to src/Commands/Database/SeedCommand.php index 960c2a9ff..a3ae3fe1f 100644 --- a/src/Commands/SeedCommand.php +++ b/src/Commands/Database/SeedCommand.php @@ -1,20 +1,19 @@ argument('module')) { - $name = Str::studly($name); - $this->moduleSeed($this->getModuleByName($name)); - } else { - $modules = $this->getModuleRepository()->getOrdered(); - array_walk($modules, [$this, 'moduleSeed']); - $this->info('All modules seeded.'); + $module = $this->getModuleModel($name); + + $this->components->task("Seeding {$module->getName()} Module", function () use ($module) { + try { + $this->moduleSeed($module); + } catch (\Error $e) { + $e = new ErrorException($e->getMessage(), $e->getCode(), 1, $e->getFile(), $e->getLine(), $e); + $this->reportException($e); + $this->renderException($this->getOutput(), $e); + + return false; + } catch (\Exception $e) { + $this->reportException($e); + $this->renderException($this->getOutput(), $e); + + return false; } - } catch (\Error $e) { - $e = new ErrorException($e->getMessage(), $e->getCode(), 1, $e->getFile(), $e->getLine(), $e); - $this->reportException($e); - $this->renderException($this->getOutput(), $e); - - return E_ERROR; - } catch (\Exception $e) { - $this->reportException($e); - $this->renderException($this->getOutput(), $e); - - return E_ERROR; - } + }); + } - return 0; + public function getInfo(): ?string + { + return 'Seeding module ...'; } /** * @throws RuntimeException - * @return RepositoryInterface */ public function getModuleRepository(): RepositoryInterface { $modules = $this->laravel['modules']; - if (!$modules instanceof RepositoryInterface) { + if (! $modules instanceof RepositoryInterface) { throw new RuntimeException('Module repository not found!'); } @@ -77,11 +72,9 @@ public function getModuleRepository(): RepositoryInterface } /** - * @param $name + * @return Module * * @throws RuntimeException - * - * @return Module */ public function getModuleByName($name) { @@ -94,8 +87,6 @@ public function getModuleByName($name) } /** - * @param Module $module - * * @return void */ public function moduleSeed(Module $module) @@ -103,14 +94,18 @@ public function moduleSeed(Module $module) $seeders = []; $name = $module->getName(); $config = $module->get('migration'); + if (is_array($config) && array_key_exists('seeds', $config)) { - foreach ((array)$config['seeds'] as $class) { + foreach ((array) $config['seeds'] as $class) { if (class_exists($class)) { $seeders[] = $class; } } } else { $class = $this->getSeederName($name); //legacy support + + $class = implode('\\', array_map('ucwords', explode('\\', $class))); + if (class_exists($class)) { $seeders[] = $class; } else { @@ -133,12 +128,12 @@ public function moduleSeed(Module $module) /** * Seed the specified module. * - * @param string $className + * @param string $className */ protected function dbSeed($className) { if ($option = $this->option('class')) { - $params['--class'] = Str::finish(substr($className, 0, strrpos($className, '\\')), '\\') . $option; + $params['--class'] = Str::finish(substr($className, 0, strrpos($className, '\\')), '\\').$option; } else { $params = ['--class' => $className]; } @@ -157,8 +152,7 @@ protected function dbSeed($className) /** * Get master database seeder name for the specified module. * - * @param string $name - * + * @param string $name * @return string */ public function getSeederName($name) @@ -169,14 +163,13 @@ public function getSeederName($name) $config = GenerateConfigReader::read('seeder'); $seederPath = str_replace('/', '\\', $config->getPath()); - return $namespace . '\\' . $name . '\\' . $seederPath . '\\' . $name . 'DatabaseSeeder'; + return $namespace.'\\'.$name.'\\'.$seederPath.'\\'.$name.'DatabaseSeeder'; } /** * Get master database seeder name for the specified module under a different namespace than Modules. * - * @param string $name - * + * @param string $name * @return array $foundModules array containing namespace paths */ public function getSeederNames($name) @@ -189,7 +182,7 @@ public function getSeederNames($name) $foundModules = []; foreach ($this->laravel['modules']->config('scan.paths') as $path) { $namespace = array_slice(explode('/', $path), -1)[0]; - $foundModules[] = $namespace . '\\' . $name . '\\' . $seederPath . '\\' . $name . 'DatabaseSeeder'; + $foundModules[] = $namespace.'\\'.$name.'\\'.$seederPath.'\\'.$name.'DatabaseSeeder'; } return $foundModules; @@ -218,18 +211,6 @@ protected function reportException(\Exception $e) $this->laravel[ExceptionHandler::class]->report($e); } - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], - ]; - } - /** * Get the console command options. * @@ -238,6 +219,7 @@ protected function getArguments() protected function getOptions() { return [ + ['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'], ['class', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder.'], ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to seed.'], ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], diff --git a/src/Commands/DisableCommand.php b/src/Commands/DisableCommand.php deleted file mode 100644 index 69fef2b21..000000000 --- a/src/Commands/DisableCommand.php +++ /dev/null @@ -1,93 +0,0 @@ -components->info('Disabling module ...'); - - if ($name = $this->argument('module') ) { - $this->disable($name); - - return 0; - } - - $this->disableAll(); - - return 0; - } - - /** - * disableAll - * - * @return void - */ - public function disableAll() - { - /** @var Modules $modules */ - $modules = $this->laravel['modules']->all(); - - foreach ($modules as $module) { - $this->disable($module); - } - } - - /** - * disable - * - * @param string $name - * @return void - */ - public function disable($name) - { - if ($name instanceof Module) { - $module = $name; - }else { - $module = $this->laravel['modules']->findOrFail($name); - } - - if ($module->isEnabled()) { - $module->disable(); - - $this->components->info("Module [{$module}] disabled successful."); - } else { - $this->components->warn("Module [{$module}] has already disabled."); - } - - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'Module name.'], - ]; - } -} diff --git a/src/Commands/DumpCommand.php b/src/Commands/DumpCommand.php deleted file mode 100644 index b9665ee57..000000000 --- a/src/Commands/DumpCommand.php +++ /dev/null @@ -1,85 +0,0 @@ -components->info('Generating optimized autoload modules.'); - - if ($name = $this->argument('module') ) { - $this->dump($name); - - return 0; - } - - $this->dumpAll(); - - return 0; - } - - /** - * dumpAll - * - * @return void - */ - public function dumpAll() - { - /** @var Modules $modules */ - $modules = $this->laravel['modules']->all(); - - foreach ($modules as $module) { - $this->dump($module); - } - } - - public function dump($name) - { - if ($name instanceof Module) { - $module = $name; - } else { - $module = $this->laravel['modules']->findOrFail($name); - } - - $this->components->task("$module", function () use ($module) { - chdir($module->getPath()); - - passthru('composer dump -o -n -q'); - }); - - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'Module name.'], - ]; - } -} diff --git a/src/Commands/EnableCommand.php b/src/Commands/EnableCommand.php deleted file mode 100644 index 19a8a2d25..000000000 --- a/src/Commands/EnableCommand.php +++ /dev/null @@ -1,94 +0,0 @@ -components->info('Enabling module ...'); - - if ($name = $this->argument('module') ) { - $this->enable($name); - - return 0; - } - - $this->enableAll(); - - return 0; - } - - /** - * enableAll - * - * @return void - */ - public function enableAll() - { - /** @var Modules $modules */ - $modules = $this->laravel['modules']->all(); - - foreach ($modules as $module) { - $this->enable($module); - } - } - - /** - * enable - * - * @param string $name - * @return void - */ - public function enable($name) - { - if ($name instanceof Module) { - $module = $name; - }else { - $module = $this->laravel['modules']->findOrFail($name); - } - - if ($module->isDisabled()) { - $module->enable(); - - $this->components->info("Module [{$module}] enabled successful."); - }else { - $this->components->warn("Module [{$module}] has already enabled."); - } - - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'Module name.'], - ]; - } -} diff --git a/src/Commands/GeneratorCommand.php b/src/Commands/GeneratorCommand.php deleted file mode 100644 index 96c3a1e88..000000000 --- a/src/Commands/GeneratorCommand.php +++ /dev/null @@ -1,105 +0,0 @@ -getDestinationFilePath()); - - if (!$this->laravel['files']->isDirectory($dir = dirname($path))) { - $this->laravel['files']->makeDirectory($dir, 0777, true); - } - - $contents = $this->getTemplateContents(); - - try { - $this->components->task("Generating file {$path}",function () use ($path,$contents) { - $overwriteFile = $this->hasOption('force') ? $this->option('force') : false; - (new FileGenerator($path, $contents))->withFileOverwrite($overwriteFile)->generate(); - }); - - } catch (FileAlreadyExistException $e) { - $this->components->error("File : {$path} already exists."); - - return E_ERROR; - } - - return 0; - } - - /** - * Get class name. - * - * @return string - */ - public function getClass() - { - return class_basename($this->argument($this->argumentName)); - } - - /** - * Get default namespace. - * - * @return string - */ - public function getDefaultNamespace(): string - { - return ''; - } - - /** - * Get class namespace. - * - * @param \Nwidart\Modules\Module $module - * - * @return string - */ - public function getClassNamespace($module) - { - $extra = str_replace($this->getClass(), '', $this->argument($this->argumentName)); - - $extra = str_replace('/', '\\', $extra); - - $namespace = $this->laravel['modules']->config('namespace'); - - $namespace .= '\\' . $module->getStudlyName(); - - $namespace .= '\\' . $this->getDefaultNamespace(); - - $namespace .= '\\' . $extra; - - $namespace = str_replace('/', '\\', $namespace); - - return trim($namespace, '\\'); - } -} diff --git a/src/Commands/LaravelModulesV6Migrator.php b/src/Commands/LaravelModulesV6Migrator.php index f4c788af2..9766b3bfe 100644 --- a/src/Commands/LaravelModulesV6Migrator.php +++ b/src/Commands/LaravelModulesV6Migrator.php @@ -11,6 +11,7 @@ class LaravelModulesV6Migrator extends Command { protected $name = 'module:v6:migrate'; + protected $description = 'Migrate laravel-modules v5 modules statuses to v6.'; public function handle(): int diff --git a/src/Commands/Make/ActionMakeCommand.php b/src/Commands/Make/ActionMakeCommand.php new file mode 100644 index 000000000..58182868f --- /dev/null +++ b/src/Commands/Make/ActionMakeCommand.php @@ -0,0 +1,76 @@ +laravel['modules']->getModulePath($this->getModuleName()); + + $filePath = GenerateConfigReader::read('actions')->getPath() ?? config('modules.paths.app_folder').'Actions'; + + return $path.$filePath.'/'.$this->getActionName().'.php'; + } + + protected function getTemplateContents(): string + { + $module = $this->laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub($this->getStubName(), [ + 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClassNameWithoutNamespace(), + ]))->render(); + } + + protected function getArguments(): array + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the action class.'], + ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], + ]; + } + + protected function getOptions(): array + { + return [ + ['invokable', 'i', InputOption::VALUE_NONE, 'Generate an invokable action class', null], + ['force', 'f', InputOption::VALUE_NONE, 'su.'], + ]; + } + + protected function getActionName(): array|string + { + return Str::studly($this->argument('name')); + } + + private function getClassNameWithoutNamespace(): array|string + { + return class_basename($this->getActionName()); + } + + public function getDefaultNamespace(): string + { + return config('modules.paths.generator.actions.namespace', 'Actions'); + } + + protected function getStubName(): string + { + return $this->option('invokable') === true ? '/action-invoke.stub' : '/action.stub'; + } +} diff --git a/src/Commands/Make/CastMakeCommand.php b/src/Commands/Make/CastMakeCommand.php new file mode 100644 index 000000000..13ba40b11 --- /dev/null +++ b/src/Commands/Make/CastMakeCommand.php @@ -0,0 +1,75 @@ +laravel['modules']->getModulePath($this->getModuleName()); + + $filePath = GenerateConfigReader::read('casts')->getPath() ?? config('modules.paths.app_folder').'Casts'; + + return $path.$filePath.'/'.$this->getCastName().'.php'; + } + + protected function getTemplateContents(): string + { + $module = $this->laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub($this->getStubName(), [ + 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClassNameWithoutNamespace(), + ]))->render(); + } + + protected function getArguments(): array + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the cast class.'], + ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], + ]; + } + + protected function getOptions(): array + { + return [ + ['force', 'f', InputOption::VALUE_NONE, 'su.'], + ]; + } + + protected function getCastName(): array|string + { + return Str::studly($this->argument('name')); + } + + private function getClassNameWithoutNamespace(): array|string + { + return class_basename($this->getCastName()); + } + + public function getDefaultNamespace(): string + { + return config('modules.paths.generator.casts.namespace', 'Casts'); + } + + protected function getStubName(): string + { + return '/cast.stub'; + } +} diff --git a/src/Commands/Make/ChannelMakeCommand.php b/src/Commands/Make/ChannelMakeCommand.php new file mode 100644 index 000000000..405d8400b --- /dev/null +++ b/src/Commands/Make/ChannelMakeCommand.php @@ -0,0 +1,86 @@ +laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub('/channel.stub', [ + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClass(), + ]))->render(); + } + + /** + * Get the destination file path. + * + * @return string + */ + protected function getDestinationFilePath() + { + $path = $this->laravel['modules']->getModulePath($this->getModuleName()); + + $channelPath = GenerateConfigReader::read('channels'); + + return $path.$channelPath->getPath().'/'.$this->getFileName().'.php'; + } + + /** + * @return string + */ + private function getFileName() + { + return Str::studly($this->argument('name')); + } + + /** + * Get the console command arguments. + * + * @return array + */ + protected function getArguments() + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the channel class.'], + ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], + ]; + } +} diff --git a/src/Commands/Make/ClassMakeCommand.php b/src/Commands/Make/ClassMakeCommand.php new file mode 100644 index 000000000..a69ada417 --- /dev/null +++ b/src/Commands/Make/ClassMakeCommand.php @@ -0,0 +1,91 @@ +stub(), [ + 'NAMESPACE' => $this->getClassNamespace($this->module()), + 'CLASS' => $this->typeClass(), + ]))->render(); + } + + public function stub(): string + { + return $this->option('invokable') ? '/class-invoke.stub' : '/class.stub'; + } + + public function getDestinationFilePath(): string + { + $path = $this->laravel['modules']->getModulePath($this->getModuleName()); + + $filePath = GenerateConfigReader::read('class')->getPath() ?? config('modules.paths.app_folder').'Classes'; + + return $this->typePath($path.$filePath.'/'.$this->getFileName().'.php'); + } + + protected function getFileName(): string + { + $file = Str::studly($this->argument('name')); + + if ($this->option('suffix') === true) { + $names = [Str::plural($this->type()), Str::singular($this->type())]; + $file = Str::of($file)->remove($names, false); + $file .= Str::of($this->type())->studly(); + } + + return $file; + } + + /** + * Get the type of class e.g. class, service, repository, etc. + */ + protected function type(): string + { + return Str::of($this->option('type'))->remove('=')->singular(); + } + + protected function typePath(string $path): string + { + return ($this->type() === 'class') ? $path : Str::of($path)->replaceLast('Classes', Str::of($this->type())->plural()->studly()); + } + + public function typeClass(): string + { + return Str::of($this->getFileName())->basename()->studly(); + } + + public function getDefaultNamespace(): string + { + $type = $this->type(); + + return config("modules.paths.generator.{$type}.namespace", 'Classes'); + } +} diff --git a/src/Commands/CommandMakeCommand.php b/src/Commands/Make/CommandMakeCommand.php similarity index 84% rename from src/Commands/CommandMakeCommand.php rename to src/Commands/Make/CommandMakeCommand.php index 8470c9a84..66def43bc 100644 --- a/src/Commands/CommandMakeCommand.php +++ b/src/Commands/Make/CommandMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']; - - return $module->config('paths.generator.command.namespace') ?: $module->config('paths.generator.command.path', 'Console'); + return config('modules.paths.generator.command.namespace') + ?? ltrim(config('modules.paths.generator.command.path', 'Console'), config('modules.paths.app_folder', '')); } /** @@ -75,8 +74,8 @@ protected function getTemplateContents() return (new Stub('/command.stub', [ 'COMMAND_NAME' => $this->getCommandName(), - 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -97,7 +96,7 @@ protected function getDestinationFilePath() $commandPath = GenerateConfigReader::read('command'); - return $path . $commandPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$commandPath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/ComponentClassMakeCommand.php b/src/Commands/Make/ComponentClassMakeCommand.php similarity index 74% rename from src/Commands/ComponentClassMakeCommand.php rename to src/Commands/Make/ComponentClassMakeCommand.php index 1cac7e6b1..d18d9caac 100644 --- a/src/Commands/ComponentClassMakeCommand.php +++ b/src/Commands/Make/ComponentClassMakeCommand.php @@ -1,6 +1,6 @@ call('module:make-component-view', ['name' => $this->argument('name') , 'module' => $this->argument('module')]); + $this->call('module:make-component-view', ['name' => $this->argument('name'), 'module' => $this->argument('module')]); } public function getDefaultNamespace(): string { - $module = $this->laravel['modules']; - - return $module->config('paths.generator.component-class.namespace') ?: $module->config('paths.generator.component-class.path', 'View/Component'); + return config('modules.paths.generator.component-class.namespace') + ?? ltrim(config('modules.paths.generator.component-class.path', 'View/Component'), config('modules.paths.app_folder', '')); } /** @@ -71,6 +71,7 @@ protected function getArguments() ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], ]; } + /** * @return mixed */ @@ -79,10 +80,10 @@ protected function getTemplateContents() $module = $this->laravel['modules']->findOrFail($this->getModuleName()); return (new Stub('/component-class.stub', [ - 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), - 'LOWER_NAME' => $module->getLowerName(), - 'COMPONENT_NAME' => 'components.' . Str::lower($this->argument('name')), + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClass(), + 'LOWER_NAME' => $module->getLowerName(), + 'COMPONENT_NAME' => 'components.'.Str::lower($this->argument('name')), ]))->render(); } @@ -94,7 +95,7 @@ protected function getDestinationFilePath() $path = $this->laravel['modules']->getModulePath($this->getModuleName()); $factoryPath = GenerateConfigReader::read('component-class'); - return $path . $factoryPath->getPath() . '/' . $this->getFileName(); + return $path.$factoryPath->getPath().'/'.$this->getFileName(); } /** @@ -102,6 +103,6 @@ protected function getDestinationFilePath() */ private function getFileName() { - return Str::studly($this->argument('name')) . '.php'; + return Str::studly($this->argument('name')).'.php'; } } diff --git a/src/Commands/ComponentViewMakeCommand.php b/src/Commands/Make/ComponentViewMakeCommand.php similarity index 84% rename from src/Commands/ComponentViewMakeCommand.php rename to src/Commands/Make/ComponentViewMakeCommand.php index a78264da6..7a75ad95a 100644 --- a/src/Commands/ComponentViewMakeCommand.php +++ b/src/Commands/Make/ComponentViewMakeCommand.php @@ -1,6 +1,6 @@ Inspiring::quote()]))->render(); + return (new Stub('/component-view.stub', ['QUOTE' => Inspiring::quote()]))->render(); } /** @@ -63,7 +63,7 @@ protected function getDestinationFilePath() $path = $this->laravel['modules']->getModulePath($this->getModuleName()); $factoryPath = GenerateConfigReader::read('component-view'); - return $path . $factoryPath->getPath() . '/' . $this->getFileName(); + return $path.$factoryPath->getPath().'/'.$this->getFileName(); } /** @@ -71,6 +71,6 @@ protected function getDestinationFilePath() */ private function getFileName() { - return Str::lower($this->argument('name')) . '.blade.php'; + return Str::lower($this->argument('name')).'.blade.php'; } } diff --git a/src/Commands/ControllerMakeCommand.php b/src/Commands/Make/ControllerMakeCommand.php similarity index 72% rename from src/Commands/ControllerMakeCommand.php rename to src/Commands/Make/ControllerMakeCommand.php index 4c1126bb8..474c72919 100644 --- a/src/Commands/ControllerMakeCommand.php +++ b/src/Commands/Make/ControllerMakeCommand.php @@ -1,6 +1,6 @@ getPath() . '/' . $this->getControllerName() . '.php'; + return $path.$controllerPath->getPath().'/'.$this->getControllerName().'.php'; } /** @@ -56,16 +56,16 @@ protected function getTemplateContents() $module = $this->laravel['modules']->findOrFail($this->getModuleName()); return (new Stub($this->getStubName(), [ - 'MODULENAME' => $module->getStudlyName(), - 'CONTROLLERNAME' => $this->getControllerName(), - 'NAMESPACE' => $module->getStudlyName(), - 'CLASS_NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getControllerNameWithoutNamespace(), - 'LOWER_NAME' => $module->getLowerName(), - 'MODULE' => $this->getModuleName(), - 'NAME' => $this->getModuleName(), - 'STUDLY_NAME' => $module->getStudlyName(), - 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), + 'MODULENAME' => $module->getStudlyName(), + 'CONTROLLERNAME' => $this->getControllerName(), + 'NAMESPACE' => $module->getStudlyName(), + 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getControllerNameWithoutNamespace(), + 'LOWER_NAME' => $module->getLowerName(), + 'MODULE' => $this->getModuleName(), + 'NAME' => $this->getModuleName(), + 'STUDLY_NAME' => $module->getStudlyName(), + 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), ]))->render(); } @@ -90,6 +90,7 @@ protected function getOptions() return [ ['plain', 'p', InputOption::VALUE_NONE, 'Generate a plain controller', null], ['api', null, InputOption::VALUE_NONE, 'Exclude the create and edit methods from the controller.'], + ['invokable', 'i', InputOption::VALUE_NONE, 'Generate a single method, invokable controller class'], ]; } @@ -117,13 +118,13 @@ private function getControllerNameWithoutNamespace() public function getDefaultNamespace(): string { - $module = $this->laravel['modules']; - - return $module->config('paths.generator.controller.namespace') ?: $module->config('paths.generator.controller.path', 'Http/Controllers'); + return config('modules.paths.generator.controller.namespace') + ?? ltrim(config('modules.paths.generator.controller.path', 'Http/Controllers'), config('modules.paths.app_folder')); } /** * Get the stub file name based on the options + * * @return string */ protected function getStubName() @@ -132,6 +133,8 @@ protected function getStubName() $stub = '/controller-plain.stub'; } elseif ($this->option('api') === true) { $stub = '/controller-api.stub'; + } elseif ($this->option('invokable') === true) { + $stub = '/controller.invokable.stub'; } else { $stub = '/controller.stub'; } diff --git a/src/Commands/Make/EnumMakeCommand.php b/src/Commands/Make/EnumMakeCommand.php new file mode 100644 index 000000000..48d34ccdc --- /dev/null +++ b/src/Commands/Make/EnumMakeCommand.php @@ -0,0 +1,75 @@ +laravel['modules']->getModulePath($this->getModuleName()); + + $filePath = GenerateConfigReader::read('enums')->getPath() ?? config('modules.paths.app_folder').'Enums'; + + return $path.$filePath.'/'.$this->getEnumName().'.php'; + } + + protected function getTemplateContents(): string + { + $module = $this->laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub($this->getStubName(), [ + 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClassNameWithoutNamespace(), + ]))->render(); + } + + protected function getArguments(): array + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the enum class.'], + ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], + ]; + } + + protected function getOptions(): array + { + return [ + ['force', 'f', InputOption::VALUE_NONE, 'su.'], + ]; + } + + protected function getEnumName(): array|string + { + return Str::studly($this->argument('name')); + } + + private function getClassNameWithoutNamespace(): array|string + { + return class_basename($this->getEnumName()); + } + + public function getDefaultNamespace(): string + { + return config('modules.paths.generator.enums.namespace', 'Enums'); + } + + protected function getStubName(): string + { + return '/enum.stub'; + } +} diff --git a/src/Commands/EventMakeCommand.php b/src/Commands/Make/EventMakeCommand.php similarity index 80% rename from src/Commands/EventMakeCommand.php rename to src/Commands/Make/EventMakeCommand.php index d16fe6168..d411beb2f 100644 --- a/src/Commands/EventMakeCommand.php +++ b/src/Commands/Make/EventMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']->getModulePath($this->getModuleName()); + $path = $this->laravel['modules']->getModulePath($this->getModuleName()); $eventPath = GenerateConfigReader::read('event'); - return $path . $eventPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$eventPath->getPath().'/'.$this->getFileName().'.php'; } /** @@ -57,9 +57,8 @@ protected function getFileName() public function getDefaultNamespace(): string { - $module = $this->laravel['modules']; - - return $module->config('paths.generator.event.namespace') ?: $module->config('paths.generator.event.path', 'Events'); + return config('modules.paths.generator.event.namespace') + ?? ltrim(config('modules.paths.generator.event.path', 'Events'), config('modules.paths.app_folder', '')); } /** diff --git a/src/Commands/Make/EventProviderMakeCommand.php b/src/Commands/Make/EventProviderMakeCommand.php new file mode 100644 index 000000000..d5722dc8b --- /dev/null +++ b/src/Commands/Make/EventProviderMakeCommand.php @@ -0,0 +1,75 @@ +laravel['modules']->getModulePath($this->getModuleName()); + + $filePath = GenerateConfigReader::read('provider')->getPath(); + + return $path.$filePath.'/'.$this->getEventServiceProviderName().'.php'; + } + + protected function getTemplateContents(): string + { + $module = $this->laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub($this->getStubName(), [ + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClassNameWithoutNamespace(), + ]))->render(); + } + + protected function getArguments(): array + { + return [ + ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], + ]; + } + + protected function getOptions(): array + { + return [ + ['force', 'f', InputOption::VALUE_NONE, 'su.'], + ]; + } + + protected function getEventServiceProviderName(): array|string + { + return Str::studly('EventServiceProvider'); + } + + private function getClassNameWithoutNamespace(): array|string + { + return class_basename($this->getEventServiceProviderName()); + } + + public function getDefaultNamespace(): string + { + return config('modules.paths.generator.provider.namespace') + ?? ltrim(config('modules.paths.generator.provider.path', 'Providers'), config('modules.paths.app_folder', '')); + } + + protected function getStubName(): string + { + return '/event-provider.stub'; + } +} diff --git a/src/Commands/Make/ExceptionMakeCommand.php b/src/Commands/Make/ExceptionMakeCommand.php new file mode 100644 index 000000000..343ebae6f --- /dev/null +++ b/src/Commands/Make/ExceptionMakeCommand.php @@ -0,0 +1,85 @@ +laravel['modules']->getModulePath($this->getModuleName()); + + $filePath = GenerateConfigReader::read('exceptions')->getPath() ?? config('modules.paths.app_folder').'Exceptions'; + + return $path.$filePath.'/'.$this->getExceptionName().'.php'; + } + + protected function getTemplateContents(): string + { + $module = $this->laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub($this->getStubName(), [ + 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClassNameWithoutNamespace(), + ]))->render(); + } + + protected function getArguments(): array + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the action class.'], + ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], + ]; + } + + protected function getOptions(): array + { + return [ + ['render', '', InputOption::VALUE_NONE, 'Create the exception with an empty render method', null], + ['report', '', InputOption::VALUE_NONE, 'Create the exception with an empty report method', null], + ['force', 'f', InputOption::VALUE_NONE, 'su.'], + ]; + } + + protected function getExceptionName(): array|string + { + return Str::studly($this->argument('name')); + } + + private function getClassNameWithoutNamespace(): array|string + { + return class_basename($this->getExceptionName()); + } + + public function getDefaultNamespace(): string + { + return config('modules.paths.generator.exceptions.namespace', 'Exceptions'); + } + + protected function getStubName(): string + { + if ($this->option('render')) { + return $this->option('report') + ? '/exception-render-report.stub' + : '/exception-render.stub'; + } + + return $this->option('report') + ? '/exception-report.stub' + : '/exception.stub'; + } +} diff --git a/src/Commands/FactoryMakeCommand.php b/src/Commands/Make/FactoryMakeCommand.php similarity index 77% rename from src/Commands/FactoryMakeCommand.php rename to src/Commands/Make/FactoryMakeCommand.php index 20809f678..1542f7235 100644 --- a/src/Commands/FactoryMakeCommand.php +++ b/src/Commands/Make/FactoryMakeCommand.php @@ -1,6 +1,6 @@ getPath() . '/' . $this->getFileName(); + return $path.$factoryPath->getPath().'/'.$this->getFileName(); } /** @@ -77,7 +77,7 @@ protected function getDestinationFilePath() */ private function getFileName() { - return Str::studly($this->argument('name')) . 'Factory.php'; + return Str::studly($this->argument('name')).'Factory.php'; } /** @@ -90,27 +90,22 @@ private function getModelName() /** * Get default namespace. - * - * @return string */ public function getDefaultNamespace(): string { - $module = $this->laravel['modules']; - - return $module->config('paths.generator.factory.namespace') ?: $module->config('paths.generator.factory.path'); + return config('modules.paths.generator.factory.namespace') + ?? ltrim(config('modules.paths.generator.factory.path', 'Database/Factories'), config('modules.paths.app_folder', '')); } /** * Get model namespace. - * - * @return string */ public function getModelNamespace(): string { - $path = $this->laravel['modules']->config('paths.generator.model.path', 'Entities'); + $path = ltrim(config('modules.paths.generator.model.path', 'Entities'), config('modules.paths.app_folder', '')); $path = str_replace('/', '\\', $path); - return $this->laravel['modules']->config('namespace') . '\\' . $this->laravel['modules']->findOrFail($this->getModuleName()) . '\\' . $path; + return $this->laravel['modules']->config('namespace').'\\'.$this->laravel['modules']->findOrFail($this->getModuleName()).'\\'.$path; } } diff --git a/src/Commands/Make/GeneratorCommand.php b/src/Commands/Make/GeneratorCommand.php new file mode 100644 index 000000000..94e8e0d8b --- /dev/null +++ b/src/Commands/Make/GeneratorCommand.php @@ -0,0 +1,98 @@ +getDestinationFilePath()); + + if (! $this->laravel['files']->isDirectory($dir = dirname($path))) { + $this->laravel['files']->makeDirectory($dir, 0777, true); + } + + $contents = $this->getTemplateContents(); + + try { + $this->components->task("Generating file {$path}", function () use ($path, $contents) { + $overwriteFile = $this->hasOption('force') ? $this->option('force') : false; + (new FileGenerator($path, $contents))->withFileOverwrite($overwriteFile)->generate(); + }); + } catch (FileAlreadyExistException $e) { + $this->components->error("File : {$path} already exists."); + + return E_ERROR; + } + + return 0; + } + + /** + * Get class name. + * + * @return string + */ + public function getClass() + { + return class_basename($this->argument($this->argumentName)); + } + + /** + * Get default namespace. + */ + public function getDefaultNamespace(): string + { + return ''; + } + + /** + * Get class namespace. + * + * @param \Nwidart\Modules\Module $module + * @return string + */ + public function getClassNamespace($module) + { + $path_namespace = $this->path_namespace(str_replace($this->getClass(), '', $this->argument($this->argumentName))); + + return $this->module_namespace($module->getStudlyName(), $this->getDefaultNamespace().($path_namespace ? '\\'.$path_namespace : '')); + } + + public function module(?string $name = null): Module + { + return $this->laravel['modules']->findOrFail($name ?? $this->getModuleName()); + } +} diff --git a/src/Commands/Make/HelperMakeCommand.php b/src/Commands/Make/HelperMakeCommand.php new file mode 100644 index 000000000..b4f1bf072 --- /dev/null +++ b/src/Commands/Make/HelperMakeCommand.php @@ -0,0 +1,76 @@ +laravel['modules']->getModulePath($this->getModuleName()); + + $filePath = GenerateConfigReader::read('helpers')->getPath() ?? config('modules.paths.app_folder').'Helpers'; + + return $path.$filePath.'/'.$this->getHelperName().'.php'; + } + + protected function getTemplateContents(): string + { + $module = $this->laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub($this->getStubName(), [ + 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClassNameWithoutNamespace(), + ]))->render(); + } + + protected function getArguments(): array + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the helper class.'], + ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], + ]; + } + + protected function getOptions(): array + { + return [ + ['invokable', 'i', InputOption::VALUE_NONE, 'Generate an invokable class', null], + ['force', 'f', InputOption::VALUE_NONE, 'su.'], + ]; + } + + protected function getHelperName(): array|string + { + return Str::studly($this->argument('name')); + } + + private function getClassNameWithoutNamespace(): array|string + { + return class_basename($this->getHelperName()); + } + + public function getDefaultNamespace(): string + { + return config('modules.paths.generator.helpers.namespace', 'Helpers'); + } + + protected function getStubName(): string + { + return $this->option('invokable') === true ? '/helper-invoke.stub' : '/helper.stub'; + } +} diff --git a/src/Commands/Make/InterfaceMakeCommand.php b/src/Commands/Make/InterfaceMakeCommand.php new file mode 100644 index 000000000..050843fc0 --- /dev/null +++ b/src/Commands/Make/InterfaceMakeCommand.php @@ -0,0 +1,75 @@ +laravel['modules']->getModulePath($this->getModuleName()); + + $filePath = GenerateConfigReader::read('interfaces')->getPath() ?? config('modules.paths.app_folder').'Interfaces'; + + return $path.$filePath.'/'.$this->getInterfaceName().'.php'; + } + + protected function getTemplateContents(): string + { + $module = $this->laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub($this->getStubName(), [ + 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClassNameWithoutNamespace(), + ]))->render(); + } + + protected function getArguments(): array + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the action class.'], + ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], + ]; + } + + protected function getOptions(): array + { + return [ + ['force', 'f', InputOption::VALUE_NONE, 'su.'], + ]; + } + + protected function getInterfaceName(): array|string + { + return Str::studly($this->argument('name')); + } + + private function getClassNameWithoutNamespace(): array|string + { + return class_basename($this->getInterfaceName()); + } + + public function getDefaultNamespace(): string + { + return config('modules.paths.generator.interfaces.namespace', 'Interfaces'); + } + + protected function getStubName(): string + { + return '/interface.stub'; + } +} diff --git a/src/Commands/JobMakeCommand.php b/src/Commands/Make/JobMakeCommand.php similarity index 85% rename from src/Commands/JobMakeCommand.php rename to src/Commands/Make/JobMakeCommand.php index 434eb72e3..a6aa66e08 100644 --- a/src/Commands/JobMakeCommand.php +++ b/src/Commands/Make/JobMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']; - - return $module->config('paths.generator.jobs.namespace') ?: $module->config('paths.generator.jobs.path', 'Jobs'); + return config('modules.paths.generator.jobs.namespace') + ?? ltrim(config('modules.paths.generator.jobs.path', 'Jobs'), config('modules.paths.app_folder', '')); } /** @@ -72,7 +71,7 @@ protected function getTemplateContents() return (new Stub($this->getStubName(), [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -87,7 +86,7 @@ protected function getDestinationFilePath() $jobPath = GenerateConfigReader::read('jobs'); - return $path . $jobPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$jobPath->getPath().'/'.$this->getFileName().'.php'; } /** @@ -98,9 +97,6 @@ private function getFileName() return Str::studly($this->argument('name')); } - /** - * @return string - */ protected function getStubName(): string { if ($this->option('sync')) { diff --git a/src/Commands/ListenerMakeCommand.php b/src/Commands/Make/ListenerMakeCommand.php similarity index 86% rename from src/Commands/ListenerMakeCommand.php rename to src/Commands/Make/ListenerMakeCommand.php index 4002f4db3..72052892f 100644 --- a/src/Commands/ListenerMakeCommand.php +++ b/src/Commands/Make/ListenerMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']; - - return $module->config('paths.generator.listener.namespace') ?: $module->config('paths.generator.listener.path', 'Listeners'); + return config('modules.paths.generator.listener.namespace') + ?? ltrim(config('modules.paths.generator.listener.path', 'Listeners'), config('modules.paths.app_folder', '')); } protected function getEventName(Module $module) { - $namespace = $this->laravel['modules']->config('namespace') . "\\" . $module->getStudlyName(); + $namespace = $this->laravel['modules']->config('namespace').'\\'.$module->getStudlyName(); $eventPath = GenerateConfigReader::read('event'); - $eventName = $namespace . "\\" . $eventPath->getPath() . "\\" . $this->option('event'); + $eventName = $namespace.'\\'.$eventPath->getPath().'\\'.$this->option('event'); return str_replace('/', '\\', $eventName); } @@ -96,7 +95,7 @@ protected function getDestinationFilePath() $listenerPath = GenerateConfigReader::read('listener'); - return $path . $listenerPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$listenerPath->getPath().'/'.$this->getFileName().'.php'; } /** @@ -107,9 +106,6 @@ protected function getFileName() return Str::studly($this->argument('name')); } - /** - * @return string - */ protected function getStubName(): string { if ($this->option('queued')) { diff --git a/src/Commands/MailMakeCommand.php b/src/Commands/Make/MailMakeCommand.php similarity index 83% rename from src/Commands/MailMakeCommand.php rename to src/Commands/Make/MailMakeCommand.php index d10b1c033..e07f76d9b 100644 --- a/src/Commands/MailMakeCommand.php +++ b/src/Commands/Make/MailMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']; - - return $module->config('paths.generator.emails.namespace') ?: $module->config('paths.generator.emails.path', 'Emails'); + return config('modules.paths.generator.emails.namespace') + ?? ltrim(config('modules.paths.generator.emails.path', 'Emails'), config('modules.paths.app_folder', '')); } /** @@ -59,7 +58,7 @@ protected function getTemplateContents() return (new Stub('/mail.stub', [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -74,7 +73,7 @@ protected function getDestinationFilePath() $mailPath = GenerateConfigReader::read('emails'); - return $path . $mailPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$mailPath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/MiddlewareMakeCommand.php b/src/Commands/Make/MiddlewareMakeCommand.php similarity index 84% rename from src/Commands/MiddlewareMakeCommand.php rename to src/Commands/Make/MiddlewareMakeCommand.php index 7298fcc92..a31ece951 100644 --- a/src/Commands/MiddlewareMakeCommand.php +++ b/src/Commands/Make/MiddlewareMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']; - - return $module->config('paths.generator.filter.namespace') ?: $module->config('paths.generator.filter.path', 'Http/Middleware'); + return config('modules.paths.generator.filter.namespace') + ?? ltrim(config('modules.paths.generator.filter.path', 'Http/Middleware'), config('modules.paths.app_folder', '')); } /** @@ -62,7 +61,7 @@ protected function getTemplateContents() return (new Stub('/middleware.stub', [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -75,7 +74,7 @@ protected function getDestinationFilePath() $middlewarePath = GenerateConfigReader::read('filter'); - return $path . $middlewarePath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$middlewarePath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/MigrationMakeCommand.php b/src/Commands/Make/MigrationMakeCommand.php similarity index 95% rename from src/Commands/MigrationMakeCommand.php rename to src/Commands/Make/MigrationMakeCommand.php index f2bd9d693..7bbedfc9a 100644 --- a/src/Commands/MigrationMakeCommand.php +++ b/src/Commands/Make/MigrationMakeCommand.php @@ -1,6 +1,6 @@ getPath() . '/' . $this->getFileName() . '.php'; + return $path.$generatorPath->getPath().'/'.$this->getFileName().'.php'; } /** @@ -124,7 +124,7 @@ protected function getDestinationFilePath() */ private function getFileName() { - return date('Y_m_d_His_') . $this->getSchemaName(); + return date('Y_m_d_His_').$this->getSchemaName(); } /** diff --git a/src/Commands/ModelMakeCommand.php b/src/Commands/Make/ModelMakeCommand.php similarity index 75% rename from src/Commands/ModelMakeCommand.php rename to src/Commands/Make/ModelMakeCommand.php index 87134871d..4bca6906c 100644 --- a/src/Commands/ModelMakeCommand.php +++ b/src/Commands/Make/ModelMakeCommand.php @@ -1,6 +1,6 @@ handleOptionalMigrationOption(); $this->handleOptionalControllerOption(); $this->handleOptionalSeedOption(); + $this->handleOptionalFactoryOption(); $this->handleOptionalRequestOption(); return 0; @@ -52,6 +53,7 @@ public function handle(): int * Create a proper migration name: * ProductDetail: product_details * Product: products + * * @return string */ private function createMigrationName() @@ -60,8 +62,8 @@ private function createMigrationName() $string = ''; foreach ($pieces as $i => $piece) { - if ($i+1 < count($pieces)) { - $string .= strtolower($piece) . '_'; + if ($i + 1 < count($pieces)) { + $string .= strtolower($piece).'_'; } else { $string .= Str::plural(strtolower($piece)); } @@ -95,7 +97,8 @@ protected function getOptions() ['migration', 'm', InputOption::VALUE_NONE, 'Flag to create associated migrations', null], ['controller', 'c', InputOption::VALUE_NONE, 'Flag to create associated controllers', null], ['seed', 's', InputOption::VALUE_NONE, 'Create a new seeder for the model', null], - ['request', 'r', InputOption::VALUE_NONE, 'Create a new request for the model', null] + ['factory', 'f', InputOption::VALUE_NONE, 'Create a new factory for the model', null], + ['request', 'r', InputOption::VALUE_NONE, 'Create a new request for the model', null], ]; } @@ -105,7 +108,7 @@ protected function getOptions() private function handleOptionalMigrationOption() { if ($this->option('migration') === true) { - $migrationName = 'create_' . $this->createMigrationName() . '_table'; + $migrationName = 'create_'.$this->createMigrationName().'_table'; $this->call('module:make-migration', ['name' => $migrationName, 'module' => $this->argument('module')]); } } @@ -124,7 +127,7 @@ private function handleOptionalControllerOption() ])); } } - + /** * Create a seeder file for the model. * @@ -137,7 +140,22 @@ protected function handleOptionalSeedOption() $this->call('module:make-seed', array_filter([ 'name' => $seedName, - 'module' => $this->argument('module') + 'module' => $this->argument('module'), + ])); + } + } + + /** + * Create a seeder file for the model. + * + * @return void + */ + protected function handleOptionalFactoryOption() + { + if ($this->option('factory') === true) { + $this->call('module:make-factory', array_filter([ + 'name' => $this->getModelName(), + 'module' => $this->argument('module'), ])); } } @@ -154,7 +172,7 @@ protected function handleOptionalRequestOption() $this->call('module:make-request', array_filter([ 'name' => $requestName, - 'module' => $this->argument('module') + 'module' => $this->argument('module'), ])); } } @@ -167,14 +185,14 @@ protected function getTemplateContents() $module = $this->laravel['modules']->findOrFail($this->getModuleName()); return (new Stub('/model.stub', [ - 'NAME' => $this->getModelName(), - 'FILLABLE' => $this->getFillable(), - 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), - 'LOWER_NAME' => $module->getLowerName(), - 'MODULE' => $this->getModuleName(), - 'STUDLY_NAME' => $module->getStudlyName(), - 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), + 'NAME' => $this->getModelName(), + 'FILLABLE' => $this->getFillable(), + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClass(), + 'LOWER_NAME' => $module->getLowerName(), + 'MODULE' => $this->getModuleName(), + 'STUDLY_NAME' => $module->getStudlyName(), + 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), ]))->render(); } @@ -187,7 +205,7 @@ protected function getDestinationFilePath() $modelPath = GenerateConfigReader::read('model'); - return $path . $modelPath->getPath() . '/' . $this->getModelName() . '.php'; + return $path.$modelPath->getPath().'/'.$this->getModelName().'.php'; } /** @@ -205,7 +223,7 @@ private function getFillable() { $fillable = $this->option('fillable'); - if (!is_null($fillable)) { + if (! is_null($fillable)) { $arrays = explode(',', $fillable); return json_encode($arrays); @@ -216,13 +234,10 @@ private function getFillable() /** * Get default namespace. - * - * @return string */ public function getDefaultNamespace(): string { - $module = $this->laravel['modules']; - - return $module->config('paths.generator.model.namespace') ?: $module->config('paths.generator.model.path', 'Entities'); + return config('modules.paths.generator.model.namespace') + ?? ltrim(config('modules.paths.generator.model.path', 'Models'), config('modules.paths.app_folder', '')); } } diff --git a/src/Commands/ModuleMakeCommand.php b/src/Commands/Make/ModuleMakeCommand.php similarity index 77% rename from src/Commands/ModuleMakeCommand.php rename to src/Commands/Make/ModuleMakeCommand.php index 3ead04ae6..28b4e9b82 100644 --- a/src/Commands/ModuleMakeCommand.php +++ b/src/Commands/Make/ModuleMakeCommand.php @@ -1,8 +1,9 @@ setComponent($this->components) ->setForce($this->option('force')) ->setType($this->getModuleType()) - ->setActive(!$this->option('disabled')) + ->setActive(! $this->option('disabled')) + ->setVendor($this->option('author-vendor')) + ->setAuthor($this->option('author-name'), $this->option('author-email')) ->generate(); if ($code === E_ERROR) { @@ -50,6 +53,11 @@ public function handle(): int } } + // to discover new service providers + Process::path(base_path()) + ->command('composer dump-autoload') + ->run()->output(); + return $success ? 0 : E_ERROR; } @@ -73,14 +81,17 @@ protected function getOptions() ['web', null, InputOption::VALUE_NONE, 'Generate a web module.'], ['disabled', 'd', InputOption::VALUE_NONE, 'Do not enable the module at creation.'], ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when the module already exists.'], + ['author-name', null, InputOption::VALUE_OPTIONAL, 'Author name.'], + ['author-email', null, InputOption::VALUE_OPTIONAL, 'Author email.'], + ['author-vendor', null, InputOption::VALUE_OPTIONAL, 'Author vendor.'], ]; } /** - * Get module type . - * - * @return string - */ + * Get module type . + * + * @return string + */ private function getModuleType() { $isPlain = $this->option('plain'); diff --git a/src/Commands/NotificationMakeCommand.php b/src/Commands/Make/NotificationMakeCommand.php similarity index 83% rename from src/Commands/NotificationMakeCommand.php rename to src/Commands/Make/NotificationMakeCommand.php index 72cec53d1..28ccdeefa 100644 --- a/src/Commands/NotificationMakeCommand.php +++ b/src/Commands/Make/NotificationMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']; - - return $module->config('paths.generator.notifications.namespace') ?: $module->config('paths.generator.notifications.path', 'Notifications'); + return config('modules.paths.generator.notifications.namespace') + ?? ltrim(config('modules.paths.generator.notifications.path', 'Notifications'), config('modules.paths.app_folder', '')); } /** @@ -46,7 +45,7 @@ protected function getTemplateContents() return (new Stub('/notification.stub', [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -61,7 +60,7 @@ protected function getDestinationFilePath() $notificationPath = GenerateConfigReader::read('notifications'); - return $path . $notificationPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$notificationPath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/Make/ObserverMakeCommand.php b/src/Commands/Make/ObserverMakeCommand.php new file mode 100644 index 000000000..e1ae7a0af --- /dev/null +++ b/src/Commands/Make/ObserverMakeCommand.php @@ -0,0 +1,129 @@ +laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub('/observer.stub', [ + 'NAMESPACE' => $this->getClassNamespace($module), + 'NAME' => $this->getModelName(), + 'MODEL_NAMESPACE' => $this->getModelNamespace(), + 'NAME_VARIABLE' => $this->getModelVariable(), + ]))->render(); + } + + /** + * Get model namespace. + */ + public function getModelNamespace(): string + { + $path = $this->laravel['modules']->config('paths.generator.model.path', 'Entities'); + + $path = str_replace('/', '\\', $path); + + return $this->laravel['modules']->config('namespace').'\\'.$this->laravel['modules']->findOrFail($this->getModuleName()).'\\'.$path; + } + + /** + * @return mixed|string + */ + private function getModelName() + { + return Str::studly($this->argument('name')); + } + + /** + * @return mixed|string + */ + private function getModelVariable(): string + { + return '$'.Str::lower($this->argument('name')); + } + + /** + * @return mixed + */ + protected function getDestinationFilePath() + { + $path = $this->laravel['modules']->getModulePath($this->getModuleName()); + + $observerPath = GenerateConfigReader::read('observer'); + + return $path.$observerPath->getPath().'/'.$this->getFileName(); + } + + /** + * @return string + */ + private function getFileName() + { + return Str::studly($this->argument('name')).'Observer.php'; + } + + public function handle(): int + { + $this->components->info('Creating observer...'); + + parent::handle(); + + return 0; + } + + /** + * Get default namespace. + */ + public function getDefaultNamespace(): string + { + return config('modules.paths.generator.observer.namespace') + ?? ltrim(config('modules.paths.generator.observer.path', 'Observers'), config('modules.paths.app_folder', '')); + } +} diff --git a/src/Commands/PolicyMakeCommand.php b/src/Commands/Make/PolicyMakeCommand.php similarity index 83% rename from src/Commands/PolicyMakeCommand.php rename to src/Commands/Make/PolicyMakeCommand.php index 1ed55cb42..c4dfd6d78 100644 --- a/src/Commands/PolicyMakeCommand.php +++ b/src/Commands/Make/PolicyMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']; - - return $module->config('paths.generator.policies.namespace') ?: $module->config('paths.generator.policies.path', 'Policies'); + return config('modules.paths.generator.policies.namespace') + ?? ltrim(config('modules.paths.generator.policies.path', 'Policies'), config('modules.paths.app_folder', '')); } /** @@ -62,7 +61,7 @@ protected function getTemplateContents() return (new Stub('/policy.plain.stub', [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -75,7 +74,7 @@ protected function getDestinationFilePath() $policyPath = GenerateConfigReader::read('policies'); - return $path . $policyPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$policyPath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/ProviderMakeCommand.php b/src/Commands/Make/ProviderMakeCommand.php similarity index 63% rename from src/Commands/ProviderMakeCommand.php rename to src/Commands/Make/ProviderMakeCommand.php index ee2dc117e..98315e3d4 100644 --- a/src/Commands/ProviderMakeCommand.php +++ b/src/Commands/Make/ProviderMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']; - - return $module->config('paths.generator.provider.namespace') ?: $module->config('paths.generator.provider.path', 'Providers'); + return config('modules.paths.generator.provider.namespace') + ?? ltrim(config('modules.paths.generator.provider.path', 'Providers'), config('modules.paths.app_folder', '')); } /** @@ -77,19 +76,19 @@ protected function getTemplateContents() /** @var Module $module */ $module = $this->laravel['modules']->findOrFail($this->getModuleName()); - return (new Stub('/' . $stub . '.stub', [ - 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), - 'LOWER_NAME' => $module->getLowerName(), - 'MODULE' => $this->getModuleName(), - 'NAME' => $this->getFileName(), - 'STUDLY_NAME' => $module->getStudlyName(), - 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), - 'PATH_VIEWS' => GenerateConfigReader::read('views')->getPath(), - 'PATH_LANG' => GenerateConfigReader::read('lang')->getPath(), - 'PATH_CONFIG' => GenerateConfigReader::read('config')->getPath(), - 'MIGRATIONS_PATH' => GenerateConfigReader::read('migration')->getPath(), - 'FACTORIES_PATH' => GenerateConfigReader::read('factory')->getPath(), + return (new Stub('/'.$stub.'.stub', [ + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClass(), + 'LOWER_NAME' => $module->getLowerName(), + 'MODULE' => $this->getModuleName(), + 'NAME' => $this->getFileName(), + 'STUDLY_NAME' => $module->getStudlyName(), + 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), + 'PATH_VIEWS' => GenerateConfigReader::read('views')->getPath(), + 'PATH_LANG' => GenerateConfigReader::read('lang')->getPath(), + 'PATH_CONFIG' => GenerateConfigReader::read('config')->getPath(), + 'MIGRATIONS_PATH' => GenerateConfigReader::read('migration')->getPath(), + 'FACTORIES_PATH' => GenerateConfigReader::read('factory')->getPath(), ]))->render(); } @@ -102,7 +101,7 @@ protected function getDestinationFilePath() $generatorPath = GenerateConfigReader::read('provider'); - return $path . $generatorPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$generatorPath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/Make/RepositoryMakeCommand.php b/src/Commands/Make/RepositoryMakeCommand.php new file mode 100644 index 000000000..7f8d14591 --- /dev/null +++ b/src/Commands/Make/RepositoryMakeCommand.php @@ -0,0 +1,76 @@ +laravel['modules']->getModulePath($this->getModuleName()); + + $filePath = GenerateConfigReader::read('repository')->getPath() ?? config('modules.paths.app_folder').'Repositories'; + + return $path.$filePath.'/'.$this->getRepositoryName().'.php'; + } + + protected function getTemplateContents(): string + { + $module = $this->laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub($this->getStubName(), [ + 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClassNameWithoutNamespace(), + ]))->render(); + } + + protected function getArguments(): array + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the repository class.'], + ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], + ]; + } + + protected function getOptions(): array + { + return [ + ['invokable', 'i', InputOption::VALUE_NONE, 'Generate an invokable action class', null], + ['force', 'f', InputOption::VALUE_NONE, 'su.'], + ]; + } + + protected function getRepositoryName(): array|string + { + return Str::studly($this->argument('name')); + } + + private function getClassNameWithoutNamespace(): array|string + { + return class_basename($this->getRepositoryName()); + } + + public function getDefaultNamespace(): string + { + return config('modules.paths.generator.repository.namespace', 'Repositories'); + } + + protected function getStubName(): string + { + return $this->option('invokable') === true ? '/repository-invoke.stub' : '/repository.stub'; + } +} diff --git a/src/Commands/RequestMakeCommand.php b/src/Commands/Make/RequestMakeCommand.php similarity index 83% rename from src/Commands/RequestMakeCommand.php rename to src/Commands/Make/RequestMakeCommand.php index c20882650..3847e22f6 100644 --- a/src/Commands/RequestMakeCommand.php +++ b/src/Commands/Make/RequestMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']; - - return $module->config('paths.generator.request.namespace') ?: $module->config('paths.generator.request.path', 'Http/Requests'); + return config('modules.paths.generator.request.namespace') + ?? ltrim(config('modules.paths.generator.request.path', 'Http/Requests'), config('modules.paths.app_folder', '')); } /** @@ -62,7 +61,7 @@ protected function getTemplateContents() return (new Stub('/request.stub', [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -75,7 +74,7 @@ protected function getDestinationFilePath() $requestPath = GenerateConfigReader::read('request'); - return $path . $requestPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$requestPath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/ResourceMakeCommand.php b/src/Commands/Make/ResourceMakeCommand.php similarity index 84% rename from src/Commands/ResourceMakeCommand.php rename to src/Commands/Make/ResourceMakeCommand.php index daea669d9..2b98f26bd 100644 --- a/src/Commands/ResourceMakeCommand.php +++ b/src/Commands/Make/ResourceMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']; - - return $module->config('paths.generator.resource.namespace') ?: $module->config('paths.generator.resource.path', 'Transformers'); + return config('modules.paths.generator.resource.namespace') + ?? ltrim(config('modules.paths.generator.resource.path', 'Transformers'), config('modules.paths.app_folder', '')); } /** @@ -53,7 +54,7 @@ protected function getTemplateContents() return (new Stub($this->getStubName(), [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -66,7 +67,7 @@ protected function getDestinationFilePath() $resourcePath = GenerateConfigReader::read('resource'); - return $path . $resourcePath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$resourcePath->getPath().'/'.$this->getFileName().'.php'; } /** @@ -79,8 +80,6 @@ private function getFileName() /** * Determine if the command is generating a resource collection. - * - * @return bool */ protected function collection(): bool { @@ -88,9 +87,6 @@ protected function collection(): bool Str::endsWith($this->argument('name'), 'Collection'); } - /** - * @return string - */ protected function getStubName(): string { if ($this->collection()) { diff --git a/src/Commands/RouteProviderMakeCommand.php b/src/Commands/Make/RouteProviderMakeCommand.php similarity index 70% rename from src/Commands/RouteProviderMakeCommand.php rename to src/Commands/Make/RouteProviderMakeCommand.php index eef489320..cd97e019f 100644 --- a/src/Commands/RouteProviderMakeCommand.php +++ b/src/Commands/Make/RouteProviderMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']->findOrFail($this->getModuleName()); return (new Stub('/route-provider.stub', [ - 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getFileName(), - 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), - 'MODULE' => $this->getModuleName(), + 'NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getFileName(), + 'MODULE_NAMESPACE' => $this->laravel['modules']->config('namespace'), + 'MODULE' => $this->getModuleName(), 'CONTROLLER_NAMESPACE' => $this->getControllerNameSpace(), - 'WEB_ROUTES_PATH' => $this->getWebRoutesPath(), - 'API_ROUTES_PATH' => $this->getApiRoutesPath(), - 'LOWER_NAME' => $module->getLowerName(), + 'WEB_ROUTES_PATH' => $this->getWebRoutesPath(), + 'API_ROUTES_PATH' => $this->getApiRoutesPath(), + 'LOWER_NAME' => $module->getLowerName(), ]))->render(); } @@ -87,7 +87,7 @@ protected function getDestinationFilePath() $generatorPath = GenerateConfigReader::read('provider'); - return $path . $generatorPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$generatorPath->getPath().'/'.$this->getFileName().'.php'; } /** @@ -95,7 +95,7 @@ protected function getDestinationFilePath() */ protected function getWebRoutesPath() { - return '/' . $this->laravel['modules']->config('stubs.files.routes/web', 'Routes/web.php'); + return '/'.$this->laravel['modules']->config('stubs.files.routes/web', 'Routes/web.php'); } /** @@ -103,19 +103,15 @@ protected function getWebRoutesPath() */ protected function getApiRoutesPath() { - return '/' . $this->laravel['modules']->config('stubs.files.routes/api', 'Routes/api.php'); + return '/'.$this->laravel['modules']->config('stubs.files.routes/api', 'Routes/api.php'); } public function getDefaultNamespace(): string { - $module = $this->laravel['modules']; - - return $module->config('paths.generator.provider.namespace') ?: $module->config('paths.generator.provider.path', 'Providers'); + return config('modules.paths.generator.provider.namespace') + ?? ltrim(config('modules.paths.generator.provider.path', 'Providers'), config('modules.paths.app_folder', '')); } - /** - * @return string - */ private function getControllerNameSpace(): string { $module = $this->laravel['modules']; diff --git a/src/Commands/RuleMakeCommand.php b/src/Commands/Make/RuleMakeCommand.php similarity index 69% rename from src/Commands/RuleMakeCommand.php rename to src/Commands/Make/RuleMakeCommand.php index 64b2123af..9242e5f4e 100644 --- a/src/Commands/RuleMakeCommand.php +++ b/src/Commands/Make/RuleMakeCommand.php @@ -1,12 +1,13 @@ laravel['modules']; - - return $module->config('paths.generator.rules.namespace') ?: $module->config('paths.generator.rules.path', 'Rules'); + return config('modules.paths.generator.rules.namespace') + ?? ltrim(config('modules.paths.generator.rules.path', 'Rules'), config('modules.paths.app_folder', '')); } /** @@ -53,6 +53,18 @@ protected function getArguments() ]; } + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return [ + ['implicit', 'i', InputOption::VALUE_NONE, 'Generate an implicit rule'], + ]; + } + /** * @return mixed */ @@ -60,9 +72,13 @@ protected function getTemplateContents() { $module = $this->laravel['modules']->findOrFail($this->getModuleName()); - return (new Stub('/rule.stub', [ + $stub = $this->option('implicit') + ? '/rule.implicit.stub' + : '/rule.stub'; + + return (new Stub($stub, [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getFileName(), + 'CLASS' => $this->getFileName(), ]))->render(); } @@ -75,7 +91,7 @@ protected function getDestinationFilePath() $rulePath = GenerateConfigReader::read('rules'); - return $path . $rulePath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$rulePath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/Make/ScopeMakeCommand.php b/src/Commands/Make/ScopeMakeCommand.php new file mode 100644 index 000000000..eef79316c --- /dev/null +++ b/src/Commands/Make/ScopeMakeCommand.php @@ -0,0 +1,80 @@ +laravel['modules']->getModulePath($this->getModuleName()); + + $filePath = GenerateConfigReader::read('scopes')->getPath() ?? config('modules.paths.generator.model.path').'/Scopes'; + + return $path.$filePath.'/'.$this->getScopeName().'.php'; + } + + protected function getTemplateContents(): string + { + $module = $this->laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub($this->getStubName(), [ + 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClassNameWithoutNamespace(), + ]))->render(); + } + + protected function getArguments(): array + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the scope class.'], + ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], + ]; + } + + protected function getOptions(): array + { + return [ + ['force', 'f', InputOption::VALUE_NONE, 'su.'], + ]; + } + + protected function getScopeName(): array|string + { + return Str::studly($this->argument('name')); + } + + private function getClassNameWithoutNamespace(): array|string + { + return class_basename($this->getScopeName()); + } + + public function getDefaultNamespace(): string + { + $namespace = config('modules.paths.generator.model.path'); + + $parts = explode('/', $namespace); + $models = end($parts); + + return $models.'\Scopes'; + } + + protected function getStubName(): string + { + return '/scope.stub'; + } +} diff --git a/src/Commands/SeedMakeCommand.php b/src/Commands/Make/SeedMakeCommand.php similarity index 65% rename from src/Commands/SeedMakeCommand.php rename to src/Commands/Make/SeedMakeCommand.php index 659c9ad97..e598eae85 100644 --- a/src/Commands/SeedMakeCommand.php +++ b/src/Commands/Make/SeedMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']->findOrFail($this->getModuleName()); @@ -76,10 +65,7 @@ protected function getTemplateContents() ]))->render(); } - /** - * @return mixed - */ - protected function getDestinationFilePath() + protected function getDestinationFilePath(): mixed { $this->clearCache(); @@ -87,30 +73,31 @@ protected function getDestinationFilePath() $seederPath = GenerateConfigReader::read('seeder'); - return $path . $seederPath->getPath() . '/' . $this->getSeederName() . '.php'; + return $path.$seederPath->getPath().'/'.$this->getSeederName().'.php'; } /** - * Get seeder name. - * - * @return string + * Get the seeder name. */ - private function getSeederName() + private function getSeederName(): string { - $end = $this->option('master') ? 'DatabaseSeeder' : 'TableSeeder'; + $string = $this->argument('name'); + $string .= $this->option('master') ? 'Database' : ''; + $suffix = 'Seeder'; - return Str::studly($this->argument('name')) . $end; + if (strpos($string, $suffix) === false) { + $string .= $suffix; + } + + return Str::studly($string); } /** * Get default namespace. - * - * @return string */ public function getDefaultNamespace(): string { - $module = $this->laravel['modules']; - - return $module->config('paths.generator.seeder.namespace') ?: $module->config('paths.generator.seeder.path', 'Database/Seeders'); + return config('modules.paths.generator.seeder.namespace') + ?? ltrim(config('modules.paths.generator.seeder.path', 'Database/Seeders'), config('modules.paths.app_folder', '')); } } diff --git a/src/Commands/Make/ServiceMakeCommand.php b/src/Commands/Make/ServiceMakeCommand.php new file mode 100644 index 000000000..0f4a1cdb5 --- /dev/null +++ b/src/Commands/Make/ServiceMakeCommand.php @@ -0,0 +1,76 @@ +laravel['modules']->getModulePath($this->getModuleName()); + + $filePath = GenerateConfigReader::read('services')->getPath() ?? config('modules.paths.app_folder').'Services'; + + return $path.$filePath.'/'.$this->getServiceName().'.php'; + } + + protected function getTemplateContents(): string + { + $module = $this->laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub($this->getStubName(), [ + 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClassNameWithoutNamespace(), + ]))->render(); + } + + protected function getArguments(): array + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the service class.'], + ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], + ]; + } + + protected function getOptions(): array + { + return [ + ['invokable', 'i', InputOption::VALUE_NONE, 'Generate an invokable service class', null], + ['force', 'f', InputOption::VALUE_NONE, 'su.'], + ]; + } + + protected function getServiceName(): array|string + { + return Str::studly($this->argument('name')); + } + + private function getClassNameWithoutNamespace(): array|string + { + return class_basename($this->getServiceName()); + } + + public function getDefaultNamespace(): string + { + return config('modules.paths.generator.services.namespace', 'Services'); + } + + protected function getStubName(): string + { + return $this->option('invokable') === true ? '/service-invoke.stub' : '/service.stub'; + } +} diff --git a/src/Commands/TestMakeCommand.php b/src/Commands/Make/TestMakeCommand.php similarity index 76% rename from src/Commands/TestMakeCommand.php rename to src/Commands/Make/TestMakeCommand.php index 1093fb9d4..105861903 100644 --- a/src/Commands/TestMakeCommand.php +++ b/src/Commands/Make/TestMakeCommand.php @@ -1,6 +1,6 @@ laravel['modules']; - if ($this->option('feature')) { - return $module->config('paths.generator.test-feature.namespace') ?: $module->config('paths.generator.test-feature.path', 'Tests/Feature'); + return config('modules.paths.generator.test-feature.namespace') + ?? config('modules.paths.generator.test-feature.path', 'tests/Feature'); } - return $module->config('paths.generator.test.namespace') ?: $module->config('paths.generator.test.path', 'Tests/Unit'); + return config('modules.paths.generator.test-unit.namespace') + ?? config('modules.paths.generator.test-unit.path', 'tests/Unit'); } /** @@ -49,7 +51,7 @@ protected function getArguments() protected function getOptions() { return [ - ['feature', false, InputOption::VALUE_NONE, 'Create a feature test.'], + ['feature', null, InputOption::VALUE_NONE, 'Create a feature test.'], ]; } @@ -67,7 +69,7 @@ protected function getTemplateContents() return (new Stub($stub, [ 'NAMESPACE' => $this->getClassNamespace($module), - 'CLASS' => $this->getClass(), + 'CLASS' => $this->getClass(), ]))->render(); } @@ -81,10 +83,10 @@ protected function getDestinationFilePath() if ($this->option('feature')) { $testPath = GenerateConfigReader::read('test-feature'); } else { - $testPath = GenerateConfigReader::read('test'); + $testPath = GenerateConfigReader::read('test-unit'); } - return $path . $testPath->getPath() . '/' . $this->getFileName() . '.php'; + return $path.$testPath->getPath().'/'.$this->getFileName().'.php'; } /** diff --git a/src/Commands/Make/TraitMakeCommand.php b/src/Commands/Make/TraitMakeCommand.php new file mode 100644 index 000000000..7b0567d1a --- /dev/null +++ b/src/Commands/Make/TraitMakeCommand.php @@ -0,0 +1,75 @@ +laravel['modules']->getModulePath($this->getModuleName()); + + $filePath = GenerateConfigReader::read('traits')->getPath() ?? config('modules.paths.app_folder').'Traits'; + + return $path.$filePath.'/'.$this->getTraitName().'.php'; + } + + protected function getTemplateContents(): string + { + $module = $this->laravel['modules']->findOrFail($this->getModuleName()); + + return (new Stub($this->getStubName(), [ + 'CLASS_NAMESPACE' => $this->getClassNamespace($module), + 'CLASS' => $this->getClassNameWithoutNamespace(), + ]))->render(); + } + + protected function getArguments(): array + { + return [ + ['name', InputArgument::REQUIRED, 'The name of the trait class.'], + ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], + ]; + } + + protected function getOptions(): array + { + return [ + ['force', 'f', InputOption::VALUE_NONE, 'su.'], + ]; + } + + protected function getTraitName(): array|string + { + return Str::studly($this->argument('name')); + } + + private function getClassNameWithoutNamespace(): array|string + { + return class_basename($this->getTraitName()); + } + + public function getDefaultNamespace(): string + { + return config('modules.paths.generator.traits.namespace', 'Traits'); + } + + protected function getStubName(): string + { + return '/trait.stub'; + } +} diff --git a/src/Commands/Make/ViewMakeCommand.php b/src/Commands/Make/ViewMakeCommand.php new file mode 100644 index 000000000..47b929439 --- /dev/null +++ b/src/Commands/Make/ViewMakeCommand.php @@ -0,0 +1,47 @@ + Inspiring::quotes()->random()]))->render(); + } + + protected function getDestinationFilePath(): string + { + $path = $this->laravel['modules']->getModulePath($this->getModuleName()); + $factoryPath = GenerateConfigReader::read('views'); + + return $path.$factoryPath->getPath().'/'.$this->getFileName(); + } + + private function getFileName(): string + { + return Str::lower($this->argument('name')).'.blade.php'; + } +} diff --git a/src/Commands/MigrateCommand.php b/src/Commands/MigrateCommand.php deleted file mode 100644 index d93b850db..000000000 --- a/src/Commands/MigrateCommand.php +++ /dev/null @@ -1,113 +0,0 @@ -module = $this->laravel['modules']; - - $name = $this->argument('module'); - - if ($name) { - $module = $this->module->findOrFail($name); - - $this->migrate($module); - - return 0; - } - - foreach ($this->module->getOrdered($this->option('direction')) as $module) { - $this->line('Running for module: ' . $module->getName() . ''); - - $this->migrate($module); - } - - return 0; - } - - /** - * Run the migration from the specified module. - * - * @param Module $module - */ - protected function migrate(Module $module) - { - $path = str_replace(base_path(), '', (new Migrator($module, $this->getLaravel()))->getPath()); - - if ($this->option('subpath')) { - $path = $path . "/" . $this->option("subpath"); - } - - $this->call('migrate', [ - '--path' => $path, - '--database' => $this->option('database'), - '--pretend' => $this->option('pretend'), - '--force' => $this->option('force'), - ]); - - if ($this->option('seed')) { - $this->call('module:seed', ['module' => $module->getName(), '--force' => $this->option('force')]); - } - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'], - ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], - ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'], - ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], - ['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'], - ['subpath', null, InputOption::VALUE_OPTIONAL, 'Indicate a subpath to run your migrations from'], - ]; - } -} diff --git a/src/Commands/MigrateFreshCommand.php b/src/Commands/MigrateFreshCommand.php deleted file mode 100644 index 02863b674..000000000 --- a/src/Commands/MigrateFreshCommand.php +++ /dev/null @@ -1,91 +0,0 @@ -argument('module'); - - if ($module && !$this->getModuleName()) { - $this->error("Module [$module] does not exists."); - - return E_ERROR; - } - - $this->call('migrate:fresh'); - - $this->call('module:migrate', [ - 'module' => $this->getModuleName(), - '--database' => $this->option('database'), - '--force' => $this->option('force'), - '--seed' => $this->option('seed'), - ]); - - return 0; - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], - ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], - ['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'], - ]; - } - - public function getModuleName() - { - $module = $this->argument('module'); - - if (!$module) { - return null; - } - - $module = app('modules')->find($module); - - return $module ? $module->getStudlyName() : null; - } -} diff --git a/src/Commands/MigrateRefreshCommand.php b/src/Commands/MigrateRefreshCommand.php deleted file mode 100644 index c52365f9f..000000000 --- a/src/Commands/MigrateRefreshCommand.php +++ /dev/null @@ -1,100 +0,0 @@ -argument('module'); - - if ($module && !$this->getModuleName()) { - $this->error("Module [$module] does not exists."); - - return E_ERROR; - } - - $this->call('module:migrate-reset', [ - 'module' => $this->getModuleName(), - '--database' => $this->option('database'), - '--force' => $this->option('force'), - ]); - - $this->call('module:migrate', [ - 'module' => $this->getModuleName(), - '--database' => $this->option('database'), - '--force' => $this->option('force'), - ]); - - if ($this->option('seed')) { - $this->call('module:seed', [ - 'module' => $this->getModuleName(), - ]); - } - - return 0; - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], - ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], - ['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'], - ]; - } - - public function getModuleName() - { - $module = $this->argument('module'); - - if (!$module) { - return null; - } - - $module = app('modules')->find($module); - - return $module ? $module->getStudlyName() : null; - } -} diff --git a/src/Commands/MigrateRollbackCommand.php b/src/Commands/MigrateRollbackCommand.php deleted file mode 100644 index 920c93b21..000000000 --- a/src/Commands/MigrateRollbackCommand.php +++ /dev/null @@ -1,116 +0,0 @@ -module = $this->laravel['modules']; - - $name = $this->argument('module'); - - if (!empty($name)) { - $this->rollback($name); - - return 0; - } - - foreach ($this->module->getOrdered($this->option('direction')) as $module) { - $this->line('Running for module: ' . $module->getName() . ''); - - $this->rollback($module); - } - - return 0; - } - - /** - * Rollback migration from the specified module. - * - * @param $module - */ - public function rollback($module) - { - if (is_string($module)) { - $module = $this->module->findOrFail($module); - } - - $migrator = new Migrator($module, $this->getLaravel()); - - $database = $this->option('database'); - - if (!empty($database)) { - $migrator->setDatabase($database); - } - - $migrated = $migrator->rollback(); - - if (count($migrated)) { - foreach ($migrated as $migration) { - $this->line("Rollback: {$migration}"); - } - - return; - } - - $this->comment('Nothing to rollback.'); - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'desc'], - ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], - ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], - ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'], - ]; - } -} diff --git a/src/Commands/MigrateStatusCommand.php b/src/Commands/MigrateStatusCommand.php deleted file mode 100644 index 43c61c558..000000000 --- a/src/Commands/MigrateStatusCommand.php +++ /dev/null @@ -1,98 +0,0 @@ -module = $this->laravel['modules']; - - $name = $this->argument('module'); - - if ($name) { - $module = $this->module->findOrFail($name); - - $this->migrateStatus($module); - - return 0; - } - - foreach ($this->module->getOrdered($this->option('direction')) as $module) { - $this->line('Running for module: ' . $module->getName() . ''); - $this->migrateStatus($module); - } - - return 0; - } - - /** - * Run the migration from the specified module. - * - * @param Module $module - */ - protected function migrateStatus(Module $module) - { - $path = str_replace(base_path(), '', (new Migrator($module, $this->getLaravel()))->getPath()); - - $this->call('migrate:status', [ - '--path' => $path, - '--database' => $this->option('database'), - ]); - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], - ]; - } - - /** - * Get the console command options. - * - * @return array - */ - protected function getOptions() - { - return [ - ['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'], - ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], - ]; - } -} diff --git a/src/Commands/ModuleClearCompiledCommand.php b/src/Commands/ModuleClearCompiledCommand.php new file mode 100644 index 000000000..c02cb0bf4 --- /dev/null +++ b/src/Commands/ModuleClearCompiledCommand.php @@ -0,0 +1,32 @@ +manifestPath)) { + @unlink($manifest->manifestPath); + } + + $this->components->info('Compiled module files removed successfully.'); + } +} diff --git a/src/Commands/ModuleDeleteCommand.php b/src/Commands/ModuleDeleteCommand.php deleted file mode 100644 index 10864dcde..000000000 --- a/src/Commands/ModuleDeleteCommand.php +++ /dev/null @@ -1,28 +0,0 @@ -laravel['modules']->delete($this->argument('module')); - - $this->components->info("Module {$this->argument('module')} has been deleted."); - - return 0; - } - - protected function getArguments() - { - return [ - ['module', InputArgument::REQUIRED, 'The name of module to delete.'], - ]; - } -} diff --git a/src/Commands/ModuleDiscoverCommand.php b/src/Commands/ModuleDiscoverCommand.php new file mode 100644 index 000000000..f83f071cb --- /dev/null +++ b/src/Commands/ModuleDiscoverCommand.php @@ -0,0 +1,36 @@ +components->info('Discovering modules'); + + $manifest->build(); + + collect($manifest->providersArray()) + ->map(fn ($provider) => preg_match('/Modules\\\\(.*?)\\\\/', $provider, $matches) ? $matches[1] : null) + ->unique() + ->each(fn ($description) => $this->components->task($description)) + ->whenNotEmpty(fn () => $this->newLine()); + } +} diff --git a/src/Commands/Publish/PublishCommand.php b/src/Commands/Publish/PublishCommand.php new file mode 100644 index 000000000..584b1e100 --- /dev/null +++ b/src/Commands/Publish/PublishCommand.php @@ -0,0 +1,41 @@ +getModuleModel($name); + + $this->components->task("Publishing Assets {$module->getName()} Module", function () use ($module) { + with(new AssetPublisher($module)) + ->setRepository($this->laravel['modules']) + ->setConsole($this) + ->publish(); + }); + + } + + public function getInfo(): ?string + { + return 'Publishing module asset files ...'; + } +} diff --git a/src/Commands/Publish/PublishConfigurationCommand.php b/src/Commands/Publish/PublishConfigurationCommand.php new file mode 100644 index 000000000..4ec517a29 --- /dev/null +++ b/src/Commands/Publish/PublishConfigurationCommand.php @@ -0,0 +1,58 @@ +call('vendor:publish', [ + '--provider' => $this->getServiceProviderForModule($name), + '--force' => $this->option('force'), + '--tag' => ['config'], + ]); + } + + public function getInfo(): ?string + { + return 'Publishing module config files ...'; + } + + /** + * @param string $module + */ + private function getServiceProviderForModule($module): string + { + $namespace = $this->laravel['config']->get('modules.namespace'); + $studlyName = Str::studly($module); + $provider = $this->laravel['config']->get('modules.paths.generator.provider.path'); + $provider = str_replace('/', '\\', $provider); + + return "$namespace\\$studlyName\\$provider\\{$studlyName}ServiceProvider"; + } + + protected function getOptions(): array + { + return [ + ['--force', '-f', InputOption::VALUE_NONE, 'Force the publishing of config files'], + ]; + } +} diff --git a/src/Commands/Publish/PublishMigrationCommand.php b/src/Commands/Publish/PublishMigrationCommand.php new file mode 100644 index 000000000..159e33d4f --- /dev/null +++ b/src/Commands/Publish/PublishMigrationCommand.php @@ -0,0 +1,41 @@ +getModuleModel($name); + + $this->components->task("Publishing Migration {$module->getName()} Module", function () use ($module) { + with(new MigrationPublisher(new Migrator($module, $this->getLaravel()))) + ->setRepository($this->laravel['modules']) + ->setConsole($this) + ->publish(); + }); + } + + public function getInfo(): ?string + { + return 'Publishing module migrations ...'; + } +} diff --git a/src/Commands/Publish/PublishTranslationCommand.php b/src/Commands/Publish/PublishTranslationCommand.php new file mode 100644 index 000000000..a018764f7 --- /dev/null +++ b/src/Commands/Publish/PublishTranslationCommand.php @@ -0,0 +1,40 @@ +getModuleModel($name); + + $this->components->task("Publishing Translations {$module->getName()} Module", function () use ($module) { + with(new LangPublisher($module)) + ->setRepository($this->laravel['modules']) + ->setConsole($this) + ->publish(); + }); + } + + public function getInfo(): ?string + { + return 'Publishing module translations ...'; + } +} diff --git a/src/Commands/PublishCommand.php b/src/Commands/PublishCommand.php deleted file mode 100644 index c4944c8a2..000000000 --- a/src/Commands/PublishCommand.php +++ /dev/null @@ -1,86 +0,0 @@ -components->info('Publishing module assets...'); - - if ($name = $this->argument('module')) { - $this->publish($name); - - return 0; - } - - $this->publishAll(); - - return 0; - } - - /** - * Publish assets from all modules. - */ - public function publishAll() - { - foreach ($this->laravel['modules']->allEnabled() as $module) { - $this->publish($module); - } - } - - /** - * Publish assets from the specified module. - * - * @param string $name - */ - public function publish($name) - { - if ($name instanceof Module) { - $module = $name; - } else { - $module = $this->laravel['modules']->findOrFail($name); - } - - with(new AssetPublisher($module)) - ->setRepository($this->laravel['modules']) - ->setConsole($this) - ->publish(); - - $this->components->task($module->getStudlyName(), fn()=>true); - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], - ]; - } -} diff --git a/src/Commands/PublishConfigurationCommand.php b/src/Commands/PublishConfigurationCommand.php deleted file mode 100644 index 6a681569b..000000000 --- a/src/Commands/PublishConfigurationCommand.php +++ /dev/null @@ -1,91 +0,0 @@ -components->info('publishing module config files...'); - - if ($module = $this->argument('module')) { - $this->publishConfiguration($module); - - return 0; - } - - foreach ($this->laravel['modules']->allEnabled() as $module) { - $this->publishConfiguration($module->getName()); - } - - return 0; - } - - /** - * @param string $module - * @return string - */ - private function getServiceProviderForModule($module) - { - $namespace = $this->laravel['config']->get('modules.namespace'); - $studlyName = Str::studly($module); - - return "$namespace\\$studlyName\\Providers\\{$studlyName}ServiceProvider"; - } - - /** - * @param string $module - */ - private function publishConfiguration($module) - { - $this->call('vendor:publish', [ - '--provider' => $this->getServiceProviderForModule($module), - '--force' => $this->option('force'), - '--tag' => ['config'], - ]); - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'The name of module being used.'], - ]; - } - - /** - * @return array - */ - protected function getOptions() - { - return [ - ['--force', '-f', InputOption::VALUE_NONE, 'Force the publishing of config files'], - ]; - } -} diff --git a/src/Commands/PublishMigrationCommand.php b/src/Commands/PublishMigrationCommand.php deleted file mode 100644 index 3b8472c36..000000000 --- a/src/Commands/PublishMigrationCommand.php +++ /dev/null @@ -1,72 +0,0 @@ -components->info('publishing module migrations...'); - - if ($name = $this->argument('module')) { - $module = $this->laravel['modules']->findOrFail($name); - - $this->publish($module); - - return 0; - } - - foreach ($this->laravel['modules']->allEnabled() as $module) { - $this->publish($module); - } - - return 0; - } - - /** - * Publish migration for the specified module. - * - * @param \Nwidart\Modules\Module $module - */ - public function publish($module) - { - with(new MigrationPublisher(new Migrator($module, $this->getLaravel()))) - ->setRepository($this->laravel['modules']) - ->setConsole($this) - ->publish(); - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'The name of module being used.'], - ]; - } -} diff --git a/src/Commands/PublishTranslationCommand.php b/src/Commands/PublishTranslationCommand.php deleted file mode 100644 index 616fc92f0..000000000 --- a/src/Commands/PublishTranslationCommand.php +++ /dev/null @@ -1,86 +0,0 @@ -components->info('Publishing module translations...'); - - if ($name = $this->argument('module')) { - $this->publish($name); - - return 0; - } - - $this->publishAll(); - - return 0; - } - - /** - * Publish assets from all modules. - */ - public function publishAll() - { - foreach ($this->laravel['modules']->allEnabled() as $module) { - $this->publish($module); - } - } - - /** - * Publish assets from the specified module. - * - * @param string $name - */ - public function publish($name) - { - if ($name instanceof Module) { - $module = $name; - } else { - $module = $this->laravel['modules']->findOrFail($name); - } - - with(new LangPublisher($module)) - ->setRepository($this->laravel['modules']) - ->setConsole($this) - ->publish(); - - $this->line("Published: {$module->getStudlyName()}"); - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], - ]; - } -} diff --git a/src/Commands/SetupCommand.php b/src/Commands/SetupCommand.php index 470869221..53eb9897e 100644 --- a/src/Commands/SetupCommand.php +++ b/src/Commands/SetupCommand.php @@ -56,15 +56,10 @@ public function generateAssetsFolder() /** * Generate the specified directory by given $dir. - * - * @param $dir - * @param $success - * @param $error - * @return int */ protected function generateDirectory($dir, $success, $error): int { - if (!$this->laravel['files']->isDirectory($dir)) { + if (! $this->laravel['files']->isDirectory($dir)) { $this->laravel['files']->makeDirectory($dir, 0755, true, true); $this->components->info($success); diff --git a/src/Commands/UnUseCommand.php b/src/Commands/UnUseCommand.php deleted file mode 100644 index 185fe755e..000000000 --- a/src/Commands/UnUseCommand.php +++ /dev/null @@ -1,34 +0,0 @@ -laravel['modules']->forgetUsed(); - - $this->components->info('Previous module used successfully forgotten.'); - - return 0; - } -} diff --git a/src/Commands/UpdateCommand.php b/src/Commands/UpdateCommand.php deleted file mode 100644 index 7ecc312af..000000000 --- a/src/Commands/UpdateCommand.php +++ /dev/null @@ -1,85 +0,0 @@ -components->info('Updating module ...'); - - if ($name = $this->argument('module')) { - $this->updateModule($name); - - return 0; - } - - $this->updateAllModule(); - - return 0; - } - - - protected function updateAllModule() - { - /** @var \Nwidart\Modules\Module $module */ - $modules = $this->laravel['modules']->getOrdered(); - - foreach ($modules as $module) { - $this->updateModule($module); - } - - } - - protected function updateModule($name) - { - - if ($name instanceof Module) { - $module = $name; - }else { - $module = $this->laravel['modules']->findOrFail($name); - } - - $this->components->task("Updating {$module->getName()} module", function () use ($module) { - $this->laravel['modules']->update($module); - }); - $this->laravel['modules']->update($name); - - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::OPTIONAL, 'The name of module will be updated.'], - ]; - } -} diff --git a/src/Commands/UseCommand.php b/src/Commands/UseCommand.php deleted file mode 100644 index 930129464..000000000 --- a/src/Commands/UseCommand.php +++ /dev/null @@ -1,56 +0,0 @@ -argument('module')); - - if (!$this->laravel['modules']->has($module)) { - $this->error("Module [{$module}] does not exists."); - - return E_ERROR; - } - - $this->laravel['modules']->setUsed($module); - - $this->info("Module [{$module}] used successfully."); - - return 0; - } - - /** - * Get the console command arguments. - * - * @return array - */ - protected function getArguments() - { - return [ - ['module', InputArgument::REQUIRED, 'The name of module will be used.'], - ]; - } -} diff --git a/src/Commands/stubs/action-invoke.stub b/src/Commands/stubs/action-invoke.stub new file mode 100644 index 000000000..d0a85c7af --- /dev/null +++ b/src/Commands/stubs/action-invoke.stub @@ -0,0 +1,11 @@ + $attributes + */ + public function get(Model $model, string $key, mixed $value, array $attributes): mixed + { + return $value; + } + + /** + * Prepare the given value for storage. + * + * @param array $attributes + */ + public function set(Model $model, string $key, mixed $value, array $attributes): mixed + { + return $value; + } +} diff --git a/src/Commands/stubs/channel.stub b/src/Commands/stubs/channel.stub new file mode 100644 index 000000000..f68b0b0c8 --- /dev/null +++ b/src/Commands/stubs/channel.stub @@ -0,0 +1,24 @@ +json([]); } /** * Store a newly created resource in storage. - * @param Request $request - * @return Response */ public function store(Request $request) { // + + return response()->json([]); } /** * Show the specified resource. - * @param int $id - * @return Response */ public function show($id) { // + + return response()->json([]); } /** * Update the specified resource in storage. - * @param Request $request - * @param int $id - * @return Response */ public function update(Request $request, $id) { // + + return response()->json([]); } /** * Remove the specified resource from storage. - * @param int $id - * @return Response */ public function destroy($id) { // + + return response()->json([]); } } diff --git a/src/Commands/stubs/controller.invokable.stub b/src/Commands/stubs/controller.invokable.stub new file mode 100644 index 000000000..516117ac0 --- /dev/null +++ b/src/Commands/stubs/controller.invokable.stub @@ -0,0 +1,17 @@ +json([]); + } +} diff --git a/src/Commands/stubs/controller.stub b/src/Commands/stubs/controller.stub index 30fcff098..610fbd341 100644 --- a/src/Commands/stubs/controller.stub +++ b/src/Commands/stubs/controller.stub @@ -2,15 +2,13 @@ namespace $CLASS_NAMESPACE$; -use Illuminate\Contracts\Support\Renderable; +use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use Illuminate\Routing\Controller; class $CLASS$ extends Controller { /** * Display a listing of the resource. - * @return Renderable */ public function index() { @@ -19,7 +17,6 @@ class $CLASS$ extends Controller /** * Show the form for creating a new resource. - * @return Renderable */ public function create() { @@ -28,8 +25,6 @@ class $CLASS$ extends Controller /** * Store a newly created resource in storage. - * @param Request $request - * @return Renderable */ public function store(Request $request) { @@ -38,8 +33,6 @@ class $CLASS$ extends Controller /** * Show the specified resource. - * @param int $id - * @return Renderable */ public function show($id) { @@ -48,8 +41,6 @@ class $CLASS$ extends Controller /** * Show the form for editing the specified resource. - * @param int $id - * @return Renderable */ public function edit($id) { @@ -58,9 +49,6 @@ class $CLASS$ extends Controller /** * Update the specified resource in storage. - * @param Request $request - * @param int $id - * @return Renderable */ public function update(Request $request, $id) { @@ -69,8 +57,6 @@ class $CLASS$ extends Controller /** * Remove the specified resource from storage. - * @param int $id - * @return Renderable */ public function destroy($id) { diff --git a/src/Commands/stubs/enum.stub b/src/Commands/stubs/enum.stub new file mode 100644 index 000000000..4cbbcbe50 --- /dev/null +++ b/src/Commands/stubs/enum.stub @@ -0,0 +1,8 @@ +> + */ + protected $listen = []; + + /** + * Indicates if events should be discovered. + * + * @var bool + */ + protected static $shouldDiscoverEvents = true; + + /** + * Configure the proper event listeners for email verification. + */ + protected function configureEmailVerification(): void + { + // + } +} diff --git a/src/Commands/stubs/event.stub b/src/Commands/stubs/event.stub index ad1cb6966..9a4f2bd5b 100644 --- a/src/Commands/stubs/event.stub +++ b/src/Commands/stubs/event.stub @@ -2,16 +2,20 @@ namespace $NAMESPACE$; +use Illuminate\Broadcasting\Channel; +use Illuminate\Broadcasting\InteractsWithSockets; +use Illuminate\Broadcasting\PresenceChannel; +use Illuminate\Broadcasting\PrivateChannel; +use Illuminate\Contracts\Broadcasting\ShouldBroadcast; +use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; class $CLASS$ { - use SerializesModels; + use Dispatchable, InteractsWithSockets, SerializesModels; /** * Create a new event instance. - * - * @return void */ public function __construct() { @@ -20,11 +24,11 @@ class $CLASS$ /** * Get the channels the event should be broadcast on. - * - * @return array */ - public function broadcastOn() + public function broadcastOn(): array { - return []; + return [ + new PrivateChannel('channel-name'), + ]; } } diff --git a/src/Commands/stubs/exception-render-report.stub b/src/Commands/stubs/exception-render-report.stub new file mode 100644 index 000000000..29fe5dafa --- /dev/null +++ b/src/Commands/stubs/exception-render-report.stub @@ -0,0 +1,26 @@ +get('/'); diff --git a/src/Commands/stubs/helper-invoke.stub b/src/Commands/stubs/helper-invoke.stub new file mode 100644 index 000000000..d0a85c7af --- /dev/null +++ b/src/Commands/stubs/helper-invoke.stub @@ -0,0 +1,11 @@ +view('view.name'); } diff --git a/src/Commands/stubs/middleware.stub b/src/Commands/stubs/middleware.stub index 954583ed4..bdd192dfc 100644 --- a/src/Commands/stubs/middleware.stub +++ b/src/Commands/stubs/middleware.stub @@ -9,10 +9,6 @@ class $CLASS$ { /** * Handle an incoming request. - * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed */ public function handle(Request $request, Closure $next) { diff --git a/src/Commands/stubs/migration/add.stub b/src/Commands/stubs/migration/add.stub index 4d1e064ad..788cdee2a 100644 --- a/src/Commands/stubs/migration/add.stub +++ b/src/Commands/stubs/migration/add.stub @@ -1,32 +1,28 @@ id(); -$FIELDS$ + $FIELDS$ $table->timestamps(); }); } /** * Reverse the migrations. - * - * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('$TABLE$'); } diff --git a/src/Commands/stubs/migration/delete.stub b/src/Commands/stubs/migration/delete.stub index 4d1e064ad..788cdee2a 100644 --- a/src/Commands/stubs/migration/delete.stub +++ b/src/Commands/stubs/migration/delete.stub @@ -1,32 +1,28 @@ bigIncrements('id'); -$FIELDS$ + $table->id(); + $FIELDS$ $table->timestamps(); }); } diff --git a/src/Commands/stubs/migration/plain.stub b/src/Commands/stubs/migration/plain.stub index e46b052fc..88fa2f36b 100644 --- a/src/Commands/stubs/migration/plain.stub +++ b/src/Commands/stubs/migration/plain.stub @@ -1,27 +1,23 @@ line('The introduction to the notification.') - ->action('Notification Action', 'https://laravel.com') - ->line('Thank you for using our application!'); + ->line('The introduction to the notification.') + ->action('Notification Action', 'https://laravel.com') + ->line('Thank you for using our application!'); } /** * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array */ - public function toArray($notifiable) + public function toArray($notifiable): array { - return [ - // - ]; + return []; } } diff --git a/src/Commands/stubs/observer.stub b/src/Commands/stubs/observer.stub new file mode 100644 index 000000000..ca498635f --- /dev/null +++ b/src/Commands/stubs/observer.stub @@ -0,0 +1,48 @@ +mapApiRoutes(); @@ -42,28 +31,19 @@ class $CLASS$ extends ServiceProvider * Define the "web" routes for the application. * * These routes all receive session state, CSRF protection, etc. - * - * @return void */ - protected function mapWebRoutes() + protected function mapWebRoutes(): void { - Route::middleware('web') - ->namespace($this->moduleNamespace) - ->group(module_path('$MODULE$', '$WEB_ROUTES_PATH$')); + Route::middleware('web')->group(module_path('$MODULE$', '$WEB_ROUTES_PATH$')); } /** * Define the "api" routes for the application. * * These routes are typically stateless. - * - * @return void */ - protected function mapApiRoutes() + protected function mapApiRoutes(): void { - Route::prefix('api') - ->middleware('api') - ->namespace($this->moduleNamespace) - ->group(module_path('$MODULE$', '$API_ROUTES_PATH$')); + Route::middleware('api')->prefix('api')->name('api.')->group(module_path('$MODULE$', '$API_ROUTES_PATH$')); } } diff --git a/src/Commands/stubs/routes/api.stub b/src/Commands/stubs/routes/api.stub index 78681d7ab..c99a9bbbb 100755 --- a/src/Commands/stubs/routes/api.stub +++ b/src/Commands/stubs/routes/api.stub @@ -1,18 +1,19 @@ get('/$LOWER_NAME$', function (Request $request) { - return $request->user(); -}); \ No newline at end of file +Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () { + Route::apiResource('$LOWER_NAME$', $STUDLY_NAME$Controller::class)->names('$LOWER_NAME$'); +}); diff --git a/src/Commands/stubs/routes/web.stub b/src/Commands/stubs/routes/web.stub index ab7e7f7c3..c00f766d9 100755 --- a/src/Commands/stubs/routes/web.stub +++ b/src/Commands/stubs/routes/web.stub @@ -1,5 +1,8 @@ group(function() { - Route::get('/', '$STUDLY_NAME$Controller@index'); +Route::group([], function () { + Route::resource('$LOWER_NAME$', $STUDLY_NAME$Controller::class)->names('$LOWER_NAME$'); }); diff --git a/src/Commands/stubs/rule.implicit.stub b/src/Commands/stubs/rule.implicit.stub new file mode 100644 index 000000000..edc029c29 --- /dev/null +++ b/src/Commands/stubs/rule.implicit.stub @@ -0,0 +1,22 @@ + '$STUDLY_NAME$' + 'name' => '$STUDLY_NAME$', ]; diff --git a/src/Commands/stubs/scaffold/provider.stub b/src/Commands/stubs/scaffold/provider.stub index c299d2126..7199be96a 100644 --- a/src/Commands/stubs/scaffold/provider.stub +++ b/src/Commands/stubs/scaffold/provider.stub @@ -2,28 +2,25 @@ namespace $NAMESPACE$; +use Illuminate\Support\Facades\Blade; use Illuminate\Support\ServiceProvider; -use Illuminate\Database\Eloquent\Factories\Factory; +use Nwidart\Modules\Traits\PathNamespace; class $CLASS$ extends ServiceProvider { - /** - * @var string $moduleName - */ - protected $moduleName = '$MODULE$'; + use PathNamespace; - /** - * @var string $moduleNameLower - */ - protected $moduleNameLower = '$LOWER_NAME$'; + protected string $moduleName = '$MODULE$'; + + protected string $moduleNameLower = '$LOWER_NAME$'; /** * Boot the application events. - * - * @return void */ - public function boot() + public function boot(): void { + $this->registerCommands(); + $this->registerCommandSchedules(); $this->registerTranslations(); $this->registerConfig(); $this->registerViews(); @@ -32,55 +29,38 @@ class $CLASS$ extends ServiceProvider /** * Register the service provider. - * - * @return void */ - public function register() + public function register(): void { + $this->app->register(EventServiceProvider::class); $this->app->register(RouteServiceProvider::class); } /** - * Register config. - * - * @return void + * Register commands in the format of Command::class */ - protected function registerConfig() + protected function registerCommands(): void { - $this->publishes([ - module_path($this->moduleName, '$PATH_CONFIG$/config.php') => config_path($this->moduleNameLower . '.php'), - ], 'config'); - $this->mergeConfigFrom( - module_path($this->moduleName, '$PATH_CONFIG$/config.php'), $this->moduleNameLower - ); + // $this->commands([]); } /** - * Register views. - * - * @return void + * Register command Schedules. */ - public function registerViews() + protected function registerCommandSchedules(): void { - $viewPath = resource_path('views/modules/' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, '$PATH_VIEWS$'); - - $this->publishes([ - $sourcePath => $viewPath - ], ['views', $this->moduleNameLower . '-module-views']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); } /** * Register translations. - * - * @return void */ - public function registerTranslations() + public function registerTranslations(): void { - $langPath = resource_path('lang/modules/' . $this->moduleNameLower); + $langPath = resource_path('lang/modules/'.$this->moduleNameLower); if (is_dir($langPath)) { $this->loadTranslationsFrom($langPath, $this->moduleNameLower); @@ -91,24 +71,53 @@ class $CLASS$ extends ServiceProvider } } + /** + * Register config. + */ + protected function registerConfig(): void + { + $this->publishes([module_path($this->moduleName, '$PATH_CONFIG$/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $this->mergeConfigFrom(module_path($this->moduleName, '$PATH_CONFIG$/config.php'), $this->moduleNameLower); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $sourcePath = module_path($this->moduleName, '$PATH_VIEWS$'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + + $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + } + /** * Get the services provided by the provider. * - * @return array + * @return array */ - public function provides() + public function provides(): array { return []; } + /** + * @return array + */ private function getPublishableViewPaths(): array { $paths = []; - foreach (\Config::get('view.paths') as $path) { - if (is_dir($path . '/modules/' . $this->moduleNameLower)) { - $paths[] = $path . '/modules/' . $this->moduleNameLower; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->moduleNameLower)) { + $paths[] = $path.'/modules/'.$this->moduleNameLower; } } + return $paths; } } diff --git a/src/Commands/stubs/scope.stub b/src/Commands/stubs/scope.stub new file mode 100644 index 000000000..0543ad05b --- /dev/null +++ b/src/Commands/stubs/scope.stub @@ -0,0 +1,18 @@ +call("OthersTableSeeder"); + // $this->call([]); } } diff --git a/src/Commands/stubs/service-invoke.stub b/src/Commands/stubs/service-invoke.stub new file mode 100644 index 000000000..d0a85c7af --- /dev/null +++ b/src/Commands/stubs/service-invoke.stub @@ -0,0 +1,11 @@ + + + diff --git a/src/Commands/stubs/views/index.stub b/src/Commands/stubs/views/index.stub index 04b928889..1a535d44b 100644 --- a/src/Commands/stubs/views/index.stub +++ b/src/Commands/stubs/views/index.stub @@ -3,7 +3,5 @@ @section('content')

Hello World

-

- This view is loaded from module: {!! config('$LOWER_NAME$.name') !!} -

+

Module: {!! config('$LOWER_NAME$.name') !!}

@endsection diff --git a/src/Commands/stubs/views/master.stub b/src/Commands/stubs/views/master.stub index 89d8b7653..8fa6ac498 100644 --- a/src/Commands/stubs/views/master.stub +++ b/src/Commands/stubs/views/master.stub @@ -1,19 +1,29 @@ - - - - - - Module $STUDLY_NAME$ + - {{-- Laravel Vite - CSS File --}} - {{-- {{ module_vite('build-$LOWER_NAME$', 'Resources/assets/sass/app.scss') }} --}} + + + + + - - - @yield('content') + $STUDLY_NAME$ Module - {{ config('app.name', 'Laravel') }} - {{-- Laravel Vite - JS File --}} - {{-- {{ module_vite('build-$LOWER_NAME$', 'Resources/assets/js/app.js') }} --}} - - + + + + + + + + + {{-- Vite CSS --}} + {{-- {{ module_vite('build-$LOWER_NAME$', 'resources/assets/sass/app.scss') }} --}} + + + + @yield('content') + + {{-- Vite JS --}} + {{-- {{ module_vite('build-$LOWER_NAME$', 'resources/assets/js/app.js') }} --}} + diff --git a/src/Commands/stubs/vite.stub b/src/Commands/stubs/vite.stub index 4bc21f85c..314ef8101 100644 --- a/src/Commands/stubs/vite.stub +++ b/src/Commands/stubs/vite.stub @@ -1,6 +1,3 @@ -const dotenvExpand = require('dotenv-expand'); -dotenvExpand(require('dotenv').config({ path: '../../.env'/*, debug: true*/})); - import { defineConfig } from 'vite'; import laravel from 'laravel-vite-plugin'; @@ -15,10 +12,15 @@ export default defineConfig({ publicDirectory: '../../public', buildDirectory: 'build-$LOWER_NAME$', input: [ - __dirname + '/Resources/assets/sass/app.scss', - __dirname + '/Resources/assets/js/app.js' + __dirname + '/resources/assets/sass/app.scss', + __dirname + '/resources/assets/js/app.js' ], refresh: true, }), ], }); + +//export const paths = [ +// 'Modules/$STUDLY_NAME$/resources/assets/sass/app.scss', +// 'Modules/$STUDLY_NAME$/resources/assets/js/app.js', +//]; \ No newline at end of file diff --git a/src/Constants/ModuleEvent.php b/src/Constants/ModuleEvent.php new file mode 100644 index 000000000..d19c8d365 --- /dev/null +++ b/src/Constants/ModuleEvent.php @@ -0,0 +1,30 @@ +app->runningUnitTests()) { + return self::$modules; + } + $paths = $this->getScanPaths(); $modules = []; @@ -150,65 +156,28 @@ public function scan() is_array($manifests) || $manifests = []; foreach ($manifests as $manifest) { - $name = Json::make($manifest)->get('name'); + $json = Json::make($manifest); + $name = $json->get('name'); - $modules[$name] = $this->createModule($this->app, $name, dirname($manifest)); + $modules[strtolower($name)] = $this->createModule($this->app, $name, dirname($manifest)); } } - return $modules; + self::$modules = $modules; + + return self::$modules; } /** * Get all modules. - * - * @return array */ public function all(): array { - if (!$this->config('cache.enabled')) { - return $this->scan(); - } - - return $this->formatCached($this->getCached()); - } - - /** - * Format the cached data as array of modules. - * - * @param array $cached - * - * @return array - */ - protected function formatCached($cached) - { - $modules = []; - - foreach ($cached as $name => $module) { - $path = $module['path']; - - $modules[$name] = $this->createModule($this->app, $name, $path); - } - - return $modules; - } - - /** - * Get cached modules. - * - * @return array - */ - public function getCached() - { - return $this->cache->store($this->config->get('modules.cache.driver'))->remember($this->config('cache.key'), $this->config('cache.lifetime'), function () { - return $this->toCollection()->toArray(); - }); + return $this->scan(); } /** * Get all modules as collection instance. - * - * @return Collection */ public function toCollection(): Collection { @@ -217,10 +186,6 @@ public function toCollection(): Collection /** * Get modules by status. - * - * @param $status - * - * @return array */ public function getByStatus($status): array { @@ -238,20 +203,14 @@ public function getByStatus($status): array /** * Determine whether the given module exist. - * - * @param $name - * - * @return bool */ public function has($name): bool { - return array_key_exists($name, $this->all()); + return array_key_exists(strtolower($name), $this->all()); } /** * Get list of enabled modules. - * - * @return array */ public function allEnabled(): array { @@ -260,8 +219,6 @@ public function allEnabled(): array /** * Get list of disabled modules. - * - * @return array */ public function allDisabled(): array { @@ -270,8 +227,6 @@ public function allDisabled(): array /** * Get count from all modules. - * - * @return int */ public function count(): int { @@ -281,9 +236,7 @@ public function count(): int /** * Get all ordered modules. * - * @param string $direction - * - * @return array + * @param string $direction */ public function getOrdered($direction = 'asc'): array { @@ -305,7 +258,7 @@ public function getOrdered($direction = 'asc'): array } /** - * @inheritDoc + * {@inheritDoc} */ public function getPath(): string { @@ -313,7 +266,7 @@ public function getPath(): string } /** - * @inheritDoc + * {@inheritDoc} */ public function register(): void { @@ -323,7 +276,7 @@ public function register(): void } /** - * @inheritDoc + * {@inheritDoc} */ public function boot(): void { @@ -333,23 +286,16 @@ public function boot(): void } /** - * @inheritDoc + * {@inheritDoc} */ public function find(string $name) { - foreach ($this->all() as $module) { - if ($module->getLowerName() === strtolower($name)) { - return $module; - } - } - - return; + return $this->all()[strtolower($name)] ?? null; } /** * Find a specific module, if there return that, otherwise throw exception. * - * @param $name * * @return Module * @@ -368,10 +314,6 @@ public function findOrFail(string $name) /** * Get all modules as laravel collection instance. - * - * @param $status - * - * @return Collection */ public function collections($status = 1): Collection { @@ -381,39 +323,36 @@ public function collections($status = 1): Collection /** * Get module path for a specific module. * - * @param $module * * @return string */ public function getModulePath($module) { try { - return $this->findOrFail($module)->getPath() . '/'; + return $this->findOrFail($module)->getPath().'/'; } catch (ModuleNotFoundException $e) { - return $this->getPath() . '/' . Str::studly($module) . '/'; + return $this->getPath().'/'.Str::studly($module).'/'; } } /** - * @inheritDoc + * {@inheritDoc} */ public function assetPath(string $module): string { - return $this->config('paths.assets') . '/' . $module; + return $this->config('paths.assets').'/'.$module; } /** - * @inheritDoc + * {@inheritDoc} */ public function config(string $key, $default = null) { - return $this->config->get('modules.' . $key, $default); + return $this->config->get('modules.'.$key, $default); } /** * Get storage path for module used. - * - * @return string */ public function getUsedStoragePath(): string { @@ -423,7 +362,7 @@ public function getUsedStoragePath(): string } $path = storage_path('app/modules/modules.used'); - if (!$this->getFiles()->exists($path)) { + if (! $this->getFiles()->exists($path)) { $this->getFiles()->put($path, ''); } @@ -433,7 +372,6 @@ public function getUsedStoragePath(): string /** * Set module used for cli session. * - * @param $name * * @throws ModuleNotFoundException */ @@ -442,6 +380,8 @@ public function setUsed($name) $module = $this->findOrFail($name); $this->getFiles()->put($this->getUsedStoragePath(), $module); + + $module->fireEvent(ModuleEvent::USED); } /** @@ -456,7 +396,7 @@ public function forgetUsed() /** * Get module used for cli session. - * @return string + * * @throws \Nwidart\Modules\Exceptions\ModuleNotFoundException */ public function getUsedNow(): string @@ -466,8 +406,6 @@ public function getUsedNow(): string /** * Get laravel filesystem instance. - * - * @return Filesystem */ public function getFiles(): Filesystem { @@ -476,8 +414,6 @@ public function getFiles(): Filesystem /** * Get module assets path. - * - * @return string */ public function getAssetsPath(): string { @@ -486,8 +422,9 @@ public function getAssetsPath(): string /** * Get asset url from a specific module. - * @param string $asset - * @return string + * + * @param string $asset + * * @throws InvalidAssetPath */ public function asset($asset): string @@ -495,17 +432,17 @@ public function asset($asset): string if (Str::contains($asset, ':') === false) { throw InvalidAssetPath::missingModuleName($asset); } - list($name, $url) = explode(':', $asset); + [$name, $url] = explode(':', $asset); - $baseUrl = str_replace(public_path() . DIRECTORY_SEPARATOR, '', $this->getAssetsPath()); + $baseUrl = str_replace(public_path().DIRECTORY_SEPARATOR, '', $this->getAssetsPath()); - $url = $this->url->asset($baseUrl . "/{$name}/" . $url); + $url = $this->url->asset($baseUrl."/{$name}/".$url); return str_replace(['http://', 'https://'], '//', $url); } /** - * @inheritDoc + * {@inheritDoc} */ public function isEnabled(string $name): bool { @@ -513,17 +450,19 @@ public function isEnabled(string $name): bool } /** - * @inheritDoc + * {@inheritDoc} */ public function isDisabled(string $name): bool { - return !$this->isEnabled($name); + return ! $this->isEnabled($name); } /** * Enabling a specific module. - * @param string $name + * + * @param string $name * @return void + * * @throws \Nwidart\Modules\Exceptions\ModuleNotFoundException */ public function enable($name) @@ -533,8 +472,10 @@ public function enable($name) /** * Disabling a specific module. - * @param string $name + * + * @param string $name * @return void + * * @throws \Nwidart\Modules\Exceptions\ModuleNotFoundException */ public function disable($name) @@ -543,7 +484,7 @@ public function disable($name) } /** - * @inheritDoc + * {@inheritDoc} */ public function delete(string $name): bool { @@ -553,7 +494,7 @@ public function delete(string $name): bool /** * Update dependencies for the specified module. * - * @param string $module + * @param string $module */ public function update($module) { @@ -563,11 +504,10 @@ public function update($module) /** * Install the specified module. * - * @param string $name - * @param string $version - * @param string $type - * @param bool $subtree - * + * @param string $name + * @param string $version + * @param string $type + * @param bool $subtree * @return \Symfony\Component\Process\Process */ public function install($name, $version = 'dev-master', $type = 'composer', $subtree = false) @@ -598,8 +538,7 @@ public function getStubPath() /** * Set stub path. * - * @param string $stubPath - * + * @param string $stubPath * @return $this */ public function setStubPath($stubPath) @@ -608,4 +547,11 @@ public function setStubPath($stubPath) return $this; } + + public function resetModules(): static + { + self::$modules = []; + + return $this; + } } diff --git a/src/Generators/FileGenerator.php b/src/Generators/FileGenerator.php index 6b90d4ddf..4c935617a 100644 --- a/src/Generators/FileGenerator.php +++ b/src/Generators/FileGenerator.php @@ -27,6 +27,7 @@ class FileGenerator extends Generator * @var \Illuminate\Filesystem\Filesystem|null */ protected $filesystem; + /** * @var bool */ @@ -35,9 +36,7 @@ class FileGenerator extends Generator /** * The constructor. * - * @param $path - * @param $contents - * @param null $filesystem + * @param null $filesystem */ public function __construct($path, $contents, $filesystem = null) { @@ -59,8 +58,7 @@ public function getContents() /** * Set contents. * - * @param mixed $contents - * + * @param mixed $contents * @return $this */ public function setContents($contents) @@ -83,7 +81,6 @@ public function getFilesystem() /** * Set filesystem. * - * @param Filesystem $filesystem * * @return $this */ @@ -107,8 +104,7 @@ public function getPath() /** * Set path. * - * @param mixed $path - * + * @param mixed $path * @return $this */ public function setPath($path) @@ -131,7 +127,7 @@ public function withFileOverwrite(bool $overwrite): FileGenerator public function generate() { $path = $this->getPath(); - if (!$this->filesystem->exists($path)) { + if (! $this->filesystem->exists($path)) { return $this->filesystem->put($path, $this->getContents()); } if ($this->overwriteFile === true) { diff --git a/src/Generators/ModuleGenerator.php b/src/Generators/ModuleGenerator.php index bff04d542..8d4c70979 100644 --- a/src/Generators/ModuleGenerator.php +++ b/src/Generators/ModuleGenerator.php @@ -4,101 +4,95 @@ use Illuminate\Config\Repository as Config; use Illuminate\Console\Command as Console; +use Illuminate\Console\View\Components\Factory; use Illuminate\Filesystem\Filesystem; +use Illuminate\Support\Facades\Event; use Illuminate\Support\Str; +use Nwidart\Modules\Constants\ModuleEvent; use Nwidart\Modules\Contracts\ActivatorInterface; use Nwidart\Modules\FileRepository; +use Nwidart\Modules\Module; use Nwidart\Modules\Support\Config\GenerateConfigReader; use Nwidart\Modules\Support\Stub; +use Nwidart\Modules\Traits\PathNamespace; class ModuleGenerator extends Generator { + use PathNamespace; + /** * The module name will created. - * - * @var string */ - protected $name; + protected ?string $name = null; /** * The laravel config instance. - * - * @var Config */ - protected $config; + protected ?Config $config = null; /** * The laravel filesystem instance. - * - * @var Filesystem */ - protected $filesystem; + protected ?Filesystem $filesystem = null; /** * The laravel console instance. - * - * @var Console */ - protected $console; + protected ?Console $console = null; /** * The laravel component Factory instance. - * - * @var \Illuminate\Console\View\Components\Factory */ - protected $component; - + protected ?Factory $component = null; /** * The activator instance - * - * @var ActivatorInterface */ - protected $activator; + protected ?ActivatorInterface $activator = null; /** * The module instance. - * - * @var \Nwidart\Modules\Module */ - protected $module; + /*?Module*/ + protected mixed $module = null; /** * Force status. - * - * @var bool */ - protected $force = false; + protected bool $force = false; /** * set default module type. - * - * @var string */ - protected $type = 'web'; + protected string $type = 'web'; /** * Enables the module. - * - * @var bool */ - protected $isActive = false; + protected bool $isActive = false; + + /** + * Module author + */ + protected array $author = [ + 'name', 'email', + ]; + + /** + * Vendor name + */ + protected ?string $vendor = null; /** * The constructor. - * @param $name - * @param FileRepository $module - * @param Config $config - * @param Filesystem $filesystem - * @param Console $console */ public function __construct( $name, - FileRepository $module = null, - Config $config = null, - Filesystem $filesystem = null, - Console $console = null, - ActivatorInterface $activator = null + ?FileRepository $module = null, + ?Config $config = null, + ?Filesystem $filesystem = null, + ?Console $console = null, + ?ActivatorInterface $activator = null ) { $this->name = $name; $this->config = $config; @@ -110,12 +104,8 @@ public function __construct( /** * Set type. - * - * @param string $type - * - * @return $this */ - public function setType($type) + public function setType(string $type): self { $this->type = $type; @@ -124,12 +114,8 @@ public function setType($type) /** * Set active flag. - * - * @param bool $active - * - * @return $this */ - public function setActive(bool $active) + public function setActive(bool $active): self { $this->isActive = $active; @@ -137,33 +123,25 @@ public function setActive(bool $active) } /** - * Get the name of module will created. By default in studly case. - * - * @return string + * Get the name of module that will be created (in StudlyCase). */ - public function getName() + public function getName(): string { return Str::studly($this->name); } /** * Get the laravel config instance. - * - * @return Config */ - public function getConfig() + public function getConfig(): Config { return $this->config; } /** * Set the laravel config instance. - * - * @param Config $config - * - * @return $this */ - public function setConfig($config) + public function setConfig(Config $config): self { $this->config = $config; @@ -172,12 +150,8 @@ public function setConfig($config) /** * Set the modules activator - * - * @param ActivatorInterface $activator - * - * @return $this */ - public function setActivator(ActivatorInterface $activator) + public function setActivator(ActivatorInterface $activator): self { $this->activator = $activator; @@ -186,22 +160,16 @@ public function setActivator(ActivatorInterface $activator) /** * Get the laravel filesystem instance. - * - * @return Filesystem */ - public function getFilesystem() + public function getFilesystem(): Filesystem { return $this->filesystem; } /** * Set the laravel filesystem instance. - * - * @param Filesystem $filesystem - * - * @return $this */ - public function setFilesystem($filesystem) + public function setFilesystem(Filesystem $filesystem): self { $this->filesystem = $filesystem; @@ -210,97 +178,93 @@ public function setFilesystem($filesystem) /** * Get the laravel console instance. - * - * @return Console */ - public function getConsole() + public function getConsole(): Console { return $this->console; } /** * Set the laravel console instance. - * - * @param Console $console - * - * @return $this */ - public function setConsole($console) + public function setConsole(Console $console): self { $this->console = $console; return $this; } - /** - * @return \Illuminate\Console\View\Components\Factory - */ public function getComponent(): \Illuminate\Console\View\Components\Factory { return $this->component; } - /** - * @param \Illuminate\Console\View\Components\Factory $component - */ public function setComponent(\Illuminate\Console\View\Components\Factory $component): self { $this->component = $component; + return $this; } /** * Get the module instance. - * - * @return \Nwidart\Modules\Module */ - public function getModule() + public function getModule(): Module { return $this->module; } /** * Set the module instance. - * - * @param mixed $module - * - * @return $this */ - public function setModule($module) + public function setModule(mixed $module): self { $this->module = $module; return $this; } + /** + * Setting the author from the command + */ + public function setAuthor(?string $name = null, ?string $email = null): self + { + $this->author['name'] = $name; + $this->author['email'] = $email; + + return $this; + } + + /** + * Installing vendor from the command + */ + public function setVendor(?string $vendor = null): self + { + $this->vendor = $vendor; + + return $this; + } + /** * Get the list of folders will created. - * - * @return array */ - public function getFolders() + public function getFolders(): array { return $this->module->config('paths.generator'); } /** * Get the list of files will created. - * - * @return array */ - public function getFiles() + public function getFiles(): array { return $this->module->config('stubs.files'); } /** * Set force status. - * - * @param bool|int $force - * - * @return $this */ - public function setForce($force) + public function setForce(bool|int $force): self { $this->force = $force; @@ -323,6 +287,9 @@ public function generate(): int return E_ERROR; } } + + Event::dispatch(sprintf('modules.%s.%s', strtolower($name), ModuleEvent::CREATING)); + $this->component->info("Creating module: [$name]"); $this->generateFolders(); @@ -344,6 +311,8 @@ public function generate(): int $this->component->info("Module [{$name}] created successfully."); + $this->fireEvent(ModuleEvent::CREATED); + return 0; } @@ -359,9 +328,9 @@ public function generateFolders() continue; } - $path = $this->module->getModulePath($this->getName()) . '/' . $folder->getPath(); + $path = $this->module->getModulePath($this->getName()).'/'.$folder->getPath(); - $this->filesystem->makeDirectory($path, 0755, true); + $this->filesystem->ensureDirectoryExists($path, 0755, true); if (config('modules.stubs.gitkeep')) { $this->generateGitKeep($path); } @@ -370,12 +339,10 @@ public function generateFolders() /** * Generate git keep to the specified path. - * - * @param string $path */ - public function generateGitKeep($path) + public function generateGitKeep(string $path) { - $this->filesystem->put($path . '/.gitkeep', ''); + $this->filesystem->put($path.'/.gitkeep', ''); } /** @@ -384,10 +351,10 @@ public function generateGitKeep($path) public function generateFiles() { foreach ($this->getFiles() as $stub => $file) { - $path = $this->module->getModulePath($this->getName()) . $file; + $path = $this->module->getModulePath($this->getName()).$file; - $this->component->task("Generating file {$path}",function () use ($stub, $path) { - if (!$this->filesystem->isDirectory($dir = dirname($path))) { + $this->component->task("Generating file {$path}", function () use ($stub, $path) { + if (! $this->filesystem->isDirectory($dir = dirname($path))) { $this->filesystem->makeDirectory($dir, 0775, true); } @@ -409,37 +376,77 @@ public function generateResources() ]); } - if (GenerateConfigReader::read('provider')->generate() === true) { + $providerGenerator = GenerateConfigReader::read('provider'); + if ($providerGenerator->generate() === true) { $this->console->call('module:make-provider', [ - 'name' => $this->getName() . 'ServiceProvider', + 'name' => $this->getName().'ServiceProvider', 'module' => $this->getName(), '--master' => true, ]); + } else { + // delete register ServiceProvider on module.json + $path = $this->module->getModulePath($this->getName()).DIRECTORY_SEPARATOR.'module.json'; + $module_file = $this->filesystem->get($path); + $this->filesystem->put( + $path, + preg_replace('/"providers": \[.*?\],/s', '"providers": [ ],', $module_file) + ); + } + + $eventGeneratorConfig = GenerateConfigReader::read('event-provider'); + if ( + (is_null($eventGeneratorConfig->getPath()) && $providerGenerator->generate()) + || (! is_null($eventGeneratorConfig->getPath()) && $eventGeneratorConfig->generate()) + ) { + $this->console->call('module:make-event-provider', [ + 'module' => $this->getName(), + ]); + } else { + if ($providerGenerator->generate()) { + // comment register EventServiceProvider + $this->filesystem->replaceInFile( + '$this->app->register(Event', + '// $this->app->register(Event', + $this->module->getModulePath($this->getName()).DIRECTORY_SEPARATOR.$providerGenerator->getPath().DIRECTORY_SEPARATOR.sprintf('%sServiceProvider.php', $this->getName()) + ); + } + } + + $routeGeneratorConfig = GenerateConfigReader::read('route-provider'); + if ( + (is_null($routeGeneratorConfig->getPath()) && $providerGenerator->generate()) + || (! is_null($routeGeneratorConfig->getPath()) && $routeGeneratorConfig->generate()) + ) { $this->console->call('module:route-provider', [ 'module' => $this->getName(), ]); + } else { + if ($providerGenerator->generate()) { + // comment register RouteServiceProvider + $this->filesystem->replaceInFile( + '$this->app->register(Route', + '// $this->app->register(Route', + $this->module->getModulePath($this->getName()).DIRECTORY_SEPARATOR.$providerGenerator->getPath().DIRECTORY_SEPARATOR.sprintf('%sServiceProvider.php', $this->getName()) + ); + } } if (GenerateConfigReader::read('controller')->generate() === true) { - $options = $this->type=='api' ? ['--api'=>true] : []; + $options = $this->type == 'api' ? ['--api' => true] : []; $this->console->call('module:make-controller', [ - 'controller' => $this->getName() . 'Controller', + 'controller' => $this->getName().'Controller', 'module' => $this->getName(), - ]+$options); + ] + $options); } } /** * Get the contents of the specified stub file by given stub name. - * - * @param $stub - * - * @return string */ - protected function getStubContents($stub) + protected function getStubContents($stub): string { return (new Stub( - '/' . $stub . '.stub', + '/'.$stub.'.stub', $this->getReplacement($stub) ) )->render(); @@ -455,16 +462,16 @@ public function getReplacements() /** * Get array replacement for the specified stub. - * - * @param $stub - * - * @return array */ - protected function getReplacement($stub) + protected function getReplacement($stub): array { $replacements = $this->module->config('stubs.replacements'); - if (!isset($replacements[$stub])) { + if (! isset($replacements['composer']['APP_FOLDER_NAME'])) { + $replacements['composer'][] = 'APP_FOLDER_NAME'; + } + + if (! isset($replacements[$stub])) { return []; } @@ -478,7 +485,7 @@ protected function getReplacement($stub) } } foreach ($keys as $key) { - if (method_exists($this, $method = 'get' . ucfirst(Str::studly(strtolower($key))) . 'Replacement')) { + if (method_exists($this, $method = 'get'.ucfirst(Str::studly(strtolower($key))).'Replacement')) { $replaces[$key] = $this->$method(); } else { $replaces[$key] = null; @@ -493,10 +500,10 @@ protected function getReplacement($stub) */ private function generateModuleJsonFile() { - $path = $this->module->getModulePath($this->getName()) . 'module.json'; + $path = $this->module->getModulePath($this->getName()).'module.json'; - $this->component->task("Generating file $path",function () use ($path) { - if (!$this->filesystem->isDirectory($dir = dirname($path))) { + $this->component->task("Generating file $path", function () use ($path) { + if (! $this->filesystem->isDirectory($dir = dirname($path))) { $this->filesystem->makeDirectory($dir, 0775, true); } @@ -510,13 +517,13 @@ private function generateModuleJsonFile() */ private function cleanModuleJsonFile() { - $path = $this->module->getModulePath($this->getName()) . 'module.json'; + $path = $this->module->getModulePath($this->getName()).'module.json'; $content = $this->filesystem->get($path); $namespace = $this->getModuleNamespaceReplacement(); $studlyName = $this->getStudlyNameReplacement(); - $provider = '"' . $namespace . '\\\\' . $studlyName . '\\\\Providers\\\\' . $studlyName . 'ServiceProvider"'; + $provider = '"'.$namespace.'\\\\'.$studlyName.'\\\\Providers\\\\'.$studlyName.'ServiceProvider"'; $content = str_replace($provider, '', $content); @@ -525,66 +532,84 @@ private function cleanModuleJsonFile() /** * Get the module name in lower case. - * - * @return string */ - protected function getLowerNameReplacement() + protected function getLowerNameReplacement(): string { return strtolower($this->getName()); } /** * Get the module name in studly case. - * - * @return string */ - protected function getStudlyNameReplacement() + protected function getStudlyNameReplacement(): string { return $this->getName(); } /** * Get replacement for $VENDOR$. - * - * @return string */ - protected function getVendorReplacement() + protected function getVendorReplacement(): string { - return $this->module->config('composer.vendor'); + return $this->vendor ?: $this->module->config('composer.vendor'); } /** * Get replacement for $MODULE_NAMESPACE$. - * - * @return string */ - protected function getModuleNamespaceReplacement() + protected function getModuleNamespaceReplacement(): string + { + return str_replace('\\', '\\\\', $this->module->config('namespace') ?? $this->path_namespace($this->module->config('paths.modules'))); + } + + /** + * Get replacement for $CONTROLLER_NAMESPACE$. + */ + private function getControllerNamespaceReplacement(): string { - return str_replace('\\', '\\\\', $this->module->config('namespace')); + if ($this->module->config('paths.generator.controller.namespace')) { + return $this->module->config('paths.generator.controller.namespace'); + } else { + return $this->path_namespace(ltrim($this->module->config('paths.generator.controller.path', 'app/Http/Controllers'), config('modules.paths.app_folder'))); + } } /** * Get replacement for $AUTHOR_NAME$. - * - * @return string */ - protected function getAuthorNameReplacement() + protected function getAuthorNameReplacement(): string { - return $this->module->config('composer.author.name'); + return $this->author['name'] ?: $this->module->config('composer.author.name'); } /** * Get replacement for $AUTHOR_EMAIL$. - * - * @return string */ - protected function getAuthorEmailReplacement() + protected function getAuthorEmailReplacement(): string + { + return $this->author['email'] ?: $this->module->config('composer.author.email'); + } + + /** + * Get replacement for $APP_FOLDER_NAME$. + */ + protected function getAppFolderNameReplacement(): string { - return $this->module->config('composer.author.email'); + return $this->module->config('paths.app_folder'); } protected function getProviderNamespaceReplacement(): string { return str_replace('\\', '\\\\', GenerateConfigReader::read('provider')->getNamespace()); } + + /** + * fire the module event. + */ + protected function fireEvent(string $event): void + { + $module = $this->module->find($this->name); + + $module->fireEvent($event); + } } diff --git a/src/Json.php b/src/Json.php index 1aa0f1120..357eff2e7 100644 --- a/src/Json.php +++ b/src/Json.php @@ -31,10 +31,9 @@ class Json /** * The constructor. * - * @param mixed $path - * @param \Illuminate\Filesystem\Filesystem $filesystem + * @param mixed $path */ - public function __construct($path, Filesystem $filesystem = null) + public function __construct($path, ?Filesystem $filesystem = null) { $this->path = (string) $path; $this->filesystem = $filesystem ?: new Filesystem(); @@ -54,7 +53,6 @@ public function getFilesystem() /** * Set filesystem. * - * @param Filesystem $filesystem * * @return $this */ @@ -78,8 +76,7 @@ public function getPath() /** * Set path. * - * @param mixed $path - * + * @param mixed $path * @return $this */ public function setPath($path) @@ -92,12 +89,10 @@ public function setPath($path) /** * Make new instance. * - * @param string $path - * @param \Illuminate\Filesystem\Filesystem $filesystem - * + * @param string $path * @return static */ - public static function make($path, Filesystem $filesystem = null) + public static function make($path, ?Filesystem $filesystem = null) { return new static($path, $filesystem); } @@ -116,15 +111,16 @@ public function getContents() * Decode contents as array. * * @return array + * * @throws InvalidJsonException */ public function decodeContents() { - $attributes = json_decode($this->getContents(), 1); + $attributes = $this->filesystem->json($this->getPath()); // any JSON parsing errors should throw an exception if (json_last_error() > 0) { - throw new InvalidJsonException('Error processing file: ' . $this->getPath() . '. Error: ' . json_last_error_msg()); + throw new InvalidJsonException('Error processing file: '.$this->getPath().'. Error: '.json_last_error_msg()); } return $attributes; @@ -133,28 +129,23 @@ public function decodeContents() /** * Get file contents as array, either from the cache or from * the json content file if the cache is disabled. + * * @return array + * * @throws \Exception */ public function getAttributes() { - if (config('modules.cache.enabled') === false) { - return $this->decodeContents(); - } - - return app('cache')->store(config('modules.cache.driver'))->remember($this->getPath(), config('modules.cache.lifetime'), function () { - return $this->decodeContents(); - }); + return $this->attributes ?? $this->decodeContents(); } /** * Convert the given array data to pretty json. * - * @param array $data * * @return string */ - public function toJsonPretty(array $data = null) + public function toJsonPretty(?array $data = null) { return json_encode($data ?: $this->attributes, JSON_PRETTY_PRINT); } @@ -162,7 +153,6 @@ public function toJsonPretty(array $data = null) /** * Update json contents from array data. * - * @param array $data * * @return bool */ @@ -176,9 +166,8 @@ public function update(array $data) /** * Set a specific key & value. * - * @param string $key - * @param mixed $value - * + * @param string $key + * @param mixed $value * @return $this */ public function set($key, $value) @@ -201,8 +190,7 @@ public function save() /** * Handle magic method __get. * - * @param string $key - * + * @param string $key * @return mixed */ public function __get($key) @@ -213,9 +201,7 @@ public function __get($key) /** * Get the specified attribute from json file. * - * @param $key - * @param null $default - * + * @param null $default * @return mixed */ public function get($key, $default = null) @@ -226,9 +212,8 @@ public function get($key, $default = null) /** * Handle call to __call method. * - * @param string $method - * @param array $arguments - * + * @param string $method + * @param array $arguments * @return mixed */ public function __call($method, $arguments = []) diff --git a/src/Laravel/Module.php b/src/Laravel/Module.php index d545f977e..019c81be3 100644 --- a/src/Laravel/Module.php +++ b/src/Laravel/Module.php @@ -17,11 +17,11 @@ public function getCachedServicesPath(): string { // This checks if we are running on a Laravel Vapor managed instance // and sets the path to a writable one (services path is not on a writable storage in Vapor). - if (!is_null(env('VAPOR_MAINTENANCE_MODE', null))) { - return Str::replaceLast('config.php', $this->getSnakeName() . '_module.php', $this->app->getCachedConfigPath()); + if (! is_null(env('VAPOR_MAINTENANCE_MODE', null))) { + return Str::replaceLast('config.php', $this->getSnakeName().'_module.php', $this->app->getCachedConfigPath()); } - return Str::replaceLast('services.php', $this->getSnakeName() . '_module.php', $this->app->getCachedServicesPath()); + return Str::replaceLast('services.php', $this->getSnakeName().'_module.php', $this->app->getCachedServicesPath()); } /** diff --git a/src/LaravelModulesServiceProvider.php b/src/LaravelModulesServiceProvider.php index c1b788456..1fd804373 100644 --- a/src/LaravelModulesServiceProvider.php +++ b/src/LaravelModulesServiceProvider.php @@ -2,9 +2,17 @@ namespace Nwidart\Modules; +use Composer\InstalledVersions; +use Illuminate\Database\Migrations\Migrator; +use Illuminate\Filesystem\Filesystem; +use Illuminate\Foundation\Console\AboutCommand; +use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Event; +use Nwidart\Modules\Constants\ModuleEvent; use Nwidart\Modules\Contracts\RepositoryInterface; use Nwidart\Modules\Exceptions\InvalidActivatorClass; use Nwidart\Modules\Support\Stub; +use Symfony\Component\Console\Output\NullOutput; class LaravelModulesServiceProvider extends ModulesServiceProvider { @@ -14,7 +22,23 @@ class LaravelModulesServiceProvider extends ModulesServiceProvider public function boot() { $this->registerNamespaces(); + + $this->app->singleton( + ModuleManifest::class, + fn () => new ModuleManifest( + new Filesystem(), + app(Contracts\RepositoryInterface::class)->getScanPaths(), + $this->getCachedModulePath() + ) + ); + $this->registerModules(); + + $this->registerEvents(); + + AboutCommand::add('Laravel-Modules', [ + 'Version' => fn () => InstalledVersions::getPrettyVersion('nwidart/laravel-modules'), + ]); } /** @@ -26,7 +50,9 @@ public function register() $this->setupStubPath(); $this->registerProviders(); - $this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'modules'); + $this->registerMigrations(); + + $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'modules'); } /** @@ -34,7 +60,7 @@ public function register() */ public function setupStubPath() { - $path = $this->app['config']->get('modules.stubs.path') ?? __DIR__ . '/Commands/stubs'; + $path = $this->app['config']->get('modules.stubs.path') ?? __DIR__.'/Commands/stubs'; Stub::setBasePath($path); $this->app->booted(function ($app) { @@ -58,7 +84,7 @@ protected function registerServices() }); $this->app->singleton(Contracts\ActivatorInterface::class, function ($app) { $activator = $app['config']->get('modules.activator'); - $class = $app['config']->get('modules.activators.' . $activator)['class']; + $class = $app['config']->get('modules.activators.'.$activator)['class']; if ($class === null) { throw InvalidActivatorClass::missingConfig(); @@ -68,4 +94,38 @@ protected function registerServices() }); $this->app->alias(Contracts\RepositoryInterface::class, 'modules'); } + + protected function registerMigrations(): void + { + if (! $this->app['config']->get('modules.auto-discover.migrations', true)) { + return; + } + + $this->app->resolving(Migrator::class, function (Migrator $migrator) { + $path = implode(DIRECTORY_SEPARATOR, [ + $this->app['config']->get('modules.paths.modules'), + '*', + '[Dd]atabase', + 'migrations', + ]); + + collect(glob($path, GLOB_ONLYDIR)) + ->each(function (string $path) use ($migrator) { + $migrator->path($path); + }); + }); + } + + private function registerEvents(): void + { + Event::listen( + [ + 'modules.*.'.ModuleEvent::DELETED, + 'modules.*.'.ModuleEvent::CREATED, + 'modules.*.'.ModuleEvent::DISABLED, + 'modules.*.'.ModuleEvent::ENABLED, + ], + fn () => Artisan::call('module:clear-compiled', outputBuffer: new NullOutput) + ); + } } diff --git a/src/Lumen/Module.php b/src/Lumen/Module.php index a25013606..0e477aeb6 100644 --- a/src/Lumen/Module.php +++ b/src/Lumen/Module.php @@ -12,7 +12,7 @@ class Module extends BaseModule */ public function getCachedServicesPath(): string { - return Str::replaceLast('services.php', $this->getSnakeName() . '_module.php', $this->app->basePath('storage/app/') . 'services.php'); + return Str::replaceLast('services.php', $this->getSnakeName().'_module.php', $this->app->basePath('storage/app/').'services.php'); } /** diff --git a/src/LumenModulesServiceProvider.php b/src/LumenModulesServiceProvider.php index 462a48092..aedb0b217 100644 --- a/src/LumenModulesServiceProvider.php +++ b/src/LumenModulesServiceProvider.php @@ -30,7 +30,7 @@ public function register() */ public function setupStubPath() { - Stub::setBasePath(__DIR__ . '/Commands/stubs'); + Stub::setBasePath(__DIR__.'/Commands/stubs'); if (app('modules')->config('stubs.enabled') === true) { Stub::setBasePath(app('modules')->config('stubs.path')); @@ -49,7 +49,7 @@ protected function registerServices() }); $this->app->singleton(Contracts\ActivatorInterface::class, function ($app) { $activator = $app['config']->get('modules.activator'); - $class = $app['config']->get('modules.activators.' . $activator)['class']; + $class = $app['config']->get('modules.activators.'.$activator)['class']; return new $class($app); }); diff --git a/src/Migrations/Migrator.php b/src/Migrations/Migrator.php index 75901a19d..5467b1128 100644 --- a/src/Migrations/Migrator.php +++ b/src/Migrations/Migrator.php @@ -12,6 +12,7 @@ class Migrator { /** * Module instance. + * * @var Module */ protected $module; @@ -23,6 +24,15 @@ class Migrator */ protected $laravel; + /** + * Optional subpath for specific migration file. + * + * @var string|null + * + * @example subpath 2000_01_01_000000_create_example_table.php + */ + protected $subpath = ''; + /** * The database connection to be used * @@ -32,19 +42,19 @@ class Migrator /** * Create new instance. - * @param Module $module - * @param Application $application + * + * @param string|null $subpath */ - public function __construct(Module $module, Application $application) + public function __construct(Module $module, Application $application, $subpath = null) { $this->module = $module; $this->laravel = $application; + $this->subpath = $subpath; } /** * Set the database connection to be used * - * @param $database * * @return $this */ @@ -83,12 +93,16 @@ public function getPath() /** * Get migration files. * - * @param boolean $reverse + * @param bool $reverse * @return array */ public function getMigrations($reverse = false) { - $files = $this->laravel['files']->glob($this->getPath() . '/*_*.php'); + if (! empty($this->subpath)) { + $files = $this->laravel['files']->glob($this->getPath().'/'.$this->subpath); + } else { + $files = $this->laravel['files']->glob($this->getPath().'/*_*.php'); + } // Once we have the array of files in the directory we will just remove the // extension and take the basename of the file which is all we need when @@ -172,7 +186,7 @@ public function reset() /** * Run down schema from the given migration name. * - * @param string $migration + * @param string $migration */ public function down($migration) { @@ -182,7 +196,7 @@ public function down($migration) /** * Run up schema from the given migration name. * - * @param string $migration + * @param string $migration */ public function up($migration) { @@ -192,8 +206,7 @@ public function up($migration) /** * Resolve a migration instance from a file. * - * @param string $file - * + * @param string $file * @return object */ public function resolve($file) @@ -202,8 +215,8 @@ public function resolve($file) $class = Str::studly($name); - if (!class_exists($class) && file_exists($this->getPath() . '/' . $file . '.php')) { - return include $this->getPath() . '/' . $file . '.php'; + if (! class_exists($class) && file_exists($this->getPath().'/'.$file.'.php')) { + return include $this->getPath().'/'.$file.'.php'; } return new $class(); @@ -211,14 +224,12 @@ public function resolve($file) /** * Require in all the migration files in a given path. - * - * @param array $files */ public function requireFiles(array $files) { $path = $this->getPath(); foreach ($files as $file) { - $this->laravel['files']->requireOnce($path . '/' . $file . '.php'); + $this->laravel['files']->requireOnce($path.'/'.$file.'.php'); } } @@ -229,14 +240,13 @@ public function requireFiles(array $files) */ public function table() { - return $this->laravel['db']->connection($this->database ?: null)->table(config('database.migrations')); + return $this->laravel['db']->connection($this->database ?: null)->table(config('database.migrations.table')); } /** * Find migration data from database by given migration name. * - * @param string $migration - * + * @param string $migration * @return object */ public function find($migration) @@ -247,8 +257,7 @@ public function find($migration) /** * Save new migration to database. * - * @param string $migration - * + * @param string $migration * @return mixed */ public function log($migration) @@ -272,7 +281,7 @@ public function getNextBatchNumber() /** * Get the last migration batch number. * - * @param array|null $migrations + * @param array|null $migrations * @return int */ public function getLastBatchNumber($migrations = null) @@ -289,8 +298,7 @@ public function getLastBatchNumber($migrations = null) /** * Get the last migration batch. * - * @param array $migrations - * + * @param array $migrations * @return Collection */ public function getLast($migrations) diff --git a/src/Module.php b/src/Module.php index a3148141c..e2338360e 100644 --- a/src/Module.php +++ b/src/Module.php @@ -9,6 +9,7 @@ use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; use Illuminate\Translation\Translator; +use Nwidart\Modules\Constants\ModuleEvent; use Nwidart\Modules\Contracts\ActivatorInterface; abstract class Module @@ -24,8 +25,6 @@ abstract class Module /** * The module name. - * - * @var */ protected $name; @@ -40,18 +39,22 @@ abstract class Module * @var array of cached Json objects, keyed by filename */ protected $moduleJson = []; + /** * @var CacheManager */ private $cache; + /** * @var Filesystem */ private $files; + /** * @var Translator */ private $translator; + /** * @var ActivatorInterface */ @@ -59,9 +62,6 @@ abstract class Module /** * The constructor. - * @param Container $app - * @param $name - * @param $path */ public function __construct(Container $app, string $name, $path) { @@ -74,10 +74,35 @@ public function __construct(Container $app, string $name, $path) $this->app = $app; } + /** + * Returns an array of assets + */ + public static function getAssets(): array + { + $paths = []; + + if (file_exists(public_path('build/manifest.json'))) { + $files = json_decode(file_get_contents(public_path('build/manifest.json')), true); + + if (is_array($files)) { + foreach ($files as $file) { + // Ignore files which aren't entrypoints. + if (empty($file['isEntry'])) { + continue; + } + + if (isset($file['src'])) { + $paths[] = $file['src']; + } + } + } + } + + return $paths; + } + /** * Get name. - * - * @return string */ public function getName(): string { @@ -86,8 +111,6 @@ public function getName(): string /** * Get name in lower case. - * - * @return string */ public function getLowerName(): string { @@ -96,8 +119,6 @@ public function getLowerName(): string /** * Get name in studly case. - * - * @return string */ public function getStudlyName(): string { @@ -106,8 +127,6 @@ public function getStudlyName(): string /** * Get name in snake case. - * - * @return string */ public function getSnakeName(): string { @@ -116,8 +135,6 @@ public function getSnakeName(): string /** * Get description. - * - * @return string */ public function getDescription(): string { @@ -126,8 +143,6 @@ public function getDescription(): string /** * Get priority. - * - * @return string */ public function getPriority(): string { @@ -136,19 +151,26 @@ public function getPriority(): string /** * Get path. - * - * @return string */ public function getPath(): string { return $this->path; } + /** + * Get app path. + */ + public function getAppPath(): string + { + $app_path = rtrim($this->getExtraPath(config('modules.paths.app_folder', '')), '/'); + + return is_dir($app_path) ? $app_path : $this->getPath(); + } + /** * Set path. * - * @param string $path - * + * @param string $path * @return $this */ public function setPath($path): Module @@ -171,19 +193,17 @@ public function boot(): void $this->registerFiles(); } - $this->fireEvent('boot'); + $this->fireEvent(ModuleEvent::BOOT); } /** * Register module's translation. - * - * @return void */ protected function registerTranslation(): void { $lowerName = $this->getLowerName(); - $langPath = $this->getPath() . '/Resources/lang'; + $langPath = $this->getPath().'/Resources/lang'; if (is_dir($langPath)) { $this->loadTranslationsFrom($langPath, $lowerName); @@ -193,9 +213,7 @@ protected function registerTranslation(): void /** * Get json contents from the cache, setting as needed. * - * @param string $file - * - * @return Json + * @param string $file */ public function json($file = null): Json { @@ -204,16 +222,14 @@ public function json($file = null): Json } return Arr::get($this->moduleJson, $file, function () use ($file) { - return $this->moduleJson[$file] = new Json($this->getPath() . '/' . $file, $this->files); + return $this->moduleJson[$file] = new Json($this->getPath().'/'.$file, $this->files); }); } /** * Get a specific data from json file by given the key. * - * @param string $key - * @param null $default - * + * @param null $default * @return mixed */ public function get(string $key, $default = null) @@ -224,9 +240,7 @@ public function get(string $key, $default = null) /** * Get a specific data from composer.json file by given the key. * - * @param $key - * @param null $default - * + * @param null $default * @return mixed */ public function getComposerAttr($key, $default = null) @@ -247,18 +261,17 @@ public function register(): void $this->registerFiles(); } - $this->fireEvent('register'); + $this->fireEvent(ModuleEvent::REGISTER); } /** - * Register the module event. - * - * @param string $event + * fire the module event. */ - protected function fireEvent($event): void + public function fireEvent(string $event): void { - $this->app['events']->dispatch(sprintf('modules.%s.' . $event, $this->getLowerName()), [$this]); + $this->app['events']->dispatch(sprintf('modules.%s.%s', $this->getLowerName(), $event), [$this]); } + /** * Register the aliases from this module. */ @@ -271,8 +284,6 @@ abstract public function registerProviders(): void; /** * Get the path to the cached *_module.php file. - * - * @return string */ abstract public function getCachedServicesPath(): string; @@ -282,7 +293,7 @@ abstract public function getCachedServicesPath(): string; protected function registerFiles(): void { foreach ($this->get('files', []) as $file) { - include $this->path . '/' . $file; + include $this->path.'/'.$file; } } @@ -298,10 +309,6 @@ public function __toString() /** * Determine whether the given status same with the current module status. - * - * @param bool $status - * - * @return bool */ public function isStatus(bool $status): bool { @@ -310,8 +317,6 @@ public function isStatus(bool $status): bool /** * Determine whether the current module activated. - * - * @return bool */ public function isEnabled(): bool { @@ -320,20 +325,14 @@ public function isEnabled(): bool /** * Determine whether the current module not disabled. - * - * @return bool */ public function isDisabled(): bool { - return !$this->isEnabled(); + return ! $this->isEnabled(); } /** * Set active state for current module. - * - * @param bool $active - * - * @return void */ public function setActive(bool $active): void { @@ -345,12 +344,12 @@ public function setActive(bool $active): void */ public function disable(): void { - $this->fireEvent('disabling'); + $this->fireEvent(ModuleEvent::DISABLING); $this->activator->disable($this); $this->flushCache(); - $this->fireEvent('disabled'); + $this->fireEvent(ModuleEvent::DISABLED); } /** @@ -358,48 +357,46 @@ public function disable(): void */ public function enable(): void { - $this->fireEvent('enabling'); + $this->fireEvent(ModuleEvent::ENABLING); $this->activator->enable($this); $this->flushCache(); - $this->fireEvent('enabled'); + $this->fireEvent(ModuleEvent::ENABLED); } /** * Delete the current module. - * - * @return bool */ public function delete(): bool { + $this->fireEvent(ModuleEvent::DELETING); + $this->activator->delete($this); - return $this->json()->getFilesystem()->deleteDirectory($this->getPath()); + $result = $this->json()->getFilesystem()->deleteDirectory($this->getPath()); + + $this->fireEvent(ModuleEvent::DELETED); + + return $result; } /** * Get extra path. - * - * @param string $path - * - * @return string */ public function getExtraPath(string $path): string { - return $this->getPath() . '/' . $path; + return $this->getPath().'/'.$path; } /** * Check if can load files of module on boot method. - * - * @return bool */ protected function isLoadFilesOnBoot(): bool { return config('modules.register.files', 'register') === 'boot' && // force register method if option == boot && app is AsgardCms - !class_exists('\Modules\Core\Foundation\AsgardCms'); + ! class_exists('\Modules\Core\Foundation\AsgardCms'); } private function flushCache(): void @@ -411,10 +408,6 @@ private function flushCache(): void /** * Register a translation file namespace. - * - * @param string $path - * @param string $namespace - * @return void */ private function loadTranslationsFrom(string $path, string $namespace): void { diff --git a/src/ModuleManifest.php b/src/ModuleManifest.php new file mode 100644 index 000000000..76555bcac --- /dev/null +++ b/src/ModuleManifest.php @@ -0,0 +1,163 @@ +files = $files; + $this->paths = collect($paths); + $this->manifestPath = $manifestPath; + } + + /** + * Get all of the service provider class names for all packages. + * + * @return array + */ + public function providers() + { + return $this->config('providers'); + } + + /** + * Get all of the service provider class names for all packages. + * + * @return array + */ + public function providersArray() + { + return $this->getManifest()['providers'] ?? []; + } + + /** + * Get all of the aliases for all packages. + * + * @return array + */ + public function aliases() + { + return $this->config('aliases'); + } + + /** + * Get all of the values for all packages for the given configuration name. + * + * @param string $key + * @return array + */ + public function config($key) + { + return collect($this->getManifest())->flatMap(function ($configuration) use ($key) { + return (array) ($configuration[$key] ?? []); + })->filter()->all(); + } + + /** + * Get the current package manifest. + * + * @return array + */ + protected function getManifest() + { + if (! is_null($this->manifest)) { + return $this->manifest; + } + + if (! is_file($this->manifestPath)) { + $this->build(); + } + + return $this->manifest = is_file($this->manifestPath) ? + $this->files->getRequire($this->manifestPath) : []; + } + + /** + * Build the manifest and write it to disk. + * + * @return void + */ + public function build() + { + $providers = $this->paths + ->flatMap(function ($path) { + $manifests = $this->files->glob("{$path}/module.json"); + is_array($manifests) || $manifests = []; + + return collect($manifests) + ->map(function ($manifest) { + return $this->files->json($manifest); + }); + }) + ->sortBy(fn ($module) => $module['priority'] ?? 0) + ->pluck('providers') + ->flatten() + ->filter() + ->toArray(); + + $this->write( + [ + 'providers' => $providers, + 'eager' => $providers, + 'deferred' => [], + ] + ); + } + + /** + * Write the given manifest array to disk. + * + * @return void + * + * @throws \Exception + */ + protected function write(array $manifest) + { + if (! is_writable($dirname = dirname($this->manifestPath))) { + throw new Exception("The {$dirname} directory must be present and writable."); + } + $this->files->replace( + $this->manifestPath, + 'app->register(BootstrapServiceProvider::class); + // $this->app->register(\Nwidart\Modules\Providers\BootstrapServiceProvider::class); + + $providers = app()->make(ModuleManifest::class)->providersArray(); + + (new ProviderRepository($this->app, new Filesystem(), $this->getCachedModulePath())) + ->load($providers); + } /** @@ -36,8 +40,8 @@ protected function registerModules() */ protected function registerNamespaces() { - $configPath = __DIR__ . '/../config/config.php'; - $stubsPath = dirname(__DIR__) . '/src/Commands/stubs'; + $configPath = __DIR__.'/../config/config.php'; + $stubsPath = dirname(__DIR__).'/src/Commands/stubs'; $this->publishes([ $configPath => config_path('modules.php'), @@ -46,6 +50,10 @@ protected function registerNamespaces() $this->publishes([ $stubsPath => base_path('stubs/nwidart-stubs'), ], 'stubs'); + + $this->publishes([ + __DIR__.'/../scripts/vite-module-loader.js' => base_path('vite-module-loader.js'), + ], 'vite'); } /** @@ -71,4 +79,9 @@ protected function registerProviders() $this->app->register(ConsoleServiceProvider::class); $this->app->register(ContractsServiceProvider::class); } + + protected function getCachedModulePath() + { + return Str::replaceLast('services.php', 'modules.php', $this->app->getCachedServicesPath()); + } } diff --git a/src/Process/Installer.php b/src/Process/Installer.php index d973bc742..be992bdb9 100644 --- a/src/Process/Installer.php +++ b/src/Process/Installer.php @@ -25,6 +25,7 @@ class Installer /** * The module repository instance. + * * @var \Nwidart\Modules\Contracts\RepositoryInterface */ protected $repository; @@ -49,10 +50,12 @@ class Installer * @var int */ protected $timeout = 3360; + /** * @var null|string */ private $type; + /** * @var bool */ @@ -61,10 +64,10 @@ class Installer /** * The constructor. * - * @param string $name - * @param string $version - * @param string $type - * @param bool $tree + * @param string $name + * @param string $version + * @param string $type + * @param bool $tree */ public function __construct($name, $version = null, $type = null, $tree = false) { @@ -77,8 +80,7 @@ public function __construct($name, $version = null, $type = null, $tree = false) /** * Set destination path. * - * @param string $path - * + * @param string $path * @return $this */ public function setPath($path) @@ -90,7 +92,7 @@ public function setPath($path) /** * Set the module repository instance. - * @param \Nwidart\Modules\Contracts\RepositoryInterface $repository + * * @return $this */ public function setRepository(RepositoryInterface $repository) @@ -103,7 +105,6 @@ public function setRepository(RepositoryInterface $repository) /** * Set console command instance. * - * @param \Illuminate\Console\Command $console * * @return $this */ @@ -117,8 +118,7 @@ public function setConsole(Command $console) /** * Set process timeout. * - * @param int $timeout - * + * @param int $timeout * @return $this */ public function setTimeout($timeout) @@ -250,10 +250,10 @@ public function getModuleName() public function getPackageName() { if (is_null($this->version)) { - return $this->name . ':dev-master'; + return $this->name.':dev-master'; } - return $this->name . ':' . $this->version; + return $this->name.':'.$this->version; } /** diff --git a/src/Process/Runner.php b/src/Process/Runner.php index bbe5c8f00..489ce677a 100644 --- a/src/Process/Runner.php +++ b/src/Process/Runner.php @@ -9,6 +9,7 @@ class Runner implements RunableInterface { /** * The module instance. + * * @var RepositoryInterface */ protected $module; @@ -21,7 +22,7 @@ public function __construct(RepositoryInterface $module) /** * Run the given command. * - * @param string $command + * @param string $command */ public function run($command) { diff --git a/src/Process/Updater.php b/src/Process/Updater.php index 7bfdda9df..e80b79f08 100644 --- a/src/Process/Updater.php +++ b/src/Process/Updater.php @@ -9,7 +9,7 @@ class Updater extends Runner /** * Update the dependencies for the specified module by given the module name. * - * @param string $module + * @param string $module */ public function update($module) { @@ -32,9 +32,6 @@ private function isComposerSilenced() return config('modules.composer.composer-output') === false ? ' --quiet' : ''; } - /** - * @param Module $module - */ private function installRequires(Module $module) { $packages = $module->getComposerAttr('require', []); @@ -44,14 +41,11 @@ private function installRequires(Module $module) $concatenatedPackages .= "\"{$name}:{$version}\" "; } - if (!empty($concatenatedPackages)) { + if (! empty($concatenatedPackages)) { $this->run("composer require {$concatenatedPackages}{$this->isComposerSilenced()}"); } } - /** - * @param Module $module - */ private function installDevRequires(Module $module) { $devPackages = $module->getComposerAttr('require-dev', []); @@ -61,14 +55,11 @@ private function installDevRequires(Module $module) $concatenatedPackages .= "\"{$name}:{$version}\" "; } - if (!empty($concatenatedPackages)) { + if (! empty($concatenatedPackages)) { $this->run("composer require --dev {$concatenatedPackages}{$this->isComposerSilenced()}"); } } - /** - * @param Module $module - */ private function copyScriptsToMainComposerJson(Module $module) { $scripts = $module->getComposerAttr('scripts', []); diff --git a/src/Providers/BootstrapServiceProvider.php b/src/Providers/BootstrapServiceProvider.php index 82dc07d07..849ffdabf 100644 --- a/src/Providers/BootstrapServiceProvider.php +++ b/src/Providers/BootstrapServiceProvider.php @@ -4,6 +4,7 @@ use Illuminate\Support\ServiceProvider; use Nwidart\Modules\Contracts\RepositoryInterface; +use Nwidart\Modules\Laravel\LaravelFileRepository; class BootstrapServiceProvider extends ServiceProvider { @@ -12,7 +13,7 @@ class BootstrapServiceProvider extends ServiceProvider */ public function boot(): void { - $this->app[RepositoryInterface::class]->boot(); + $this->getRepositoryInterface()->boot(); } /** @@ -20,6 +21,14 @@ public function boot(): void */ public function register(): void { - $this->app[RepositoryInterface::class]->register(); + $this->getRepositoryInterface()->register(); + } + + /** + * @return LaravelFileRepository + */ + public function getRepositoryInterface() + { + return $this->app[RepositoryInterface::class]; } } diff --git a/src/Providers/ConsoleServiceProvider.php b/src/Providers/ConsoleServiceProvider.php index 76ead208e..eb39dbec9 100644 --- a/src/Providers/ConsoleServiceProvider.php +++ b/src/Providers/ConsoleServiceProvider.php @@ -2,71 +2,103 @@ namespace Nwidart\Modules\Providers; +use Illuminate\Support\Collection; use Illuminate\Support\ServiceProvider; use Nwidart\Modules\Commands; class ConsoleServiceProvider extends ServiceProvider { - /** - * The available commands - * @var array - */ - protected $commands = [ - Commands\CommandMakeCommand::class, - Commands\ControllerMakeCommand::class, - Commands\DisableCommand::class, - Commands\DumpCommand::class, - Commands\EnableCommand::class, - Commands\EventMakeCommand::class, - Commands\JobMakeCommand::class, - Commands\ListenerMakeCommand::class, - Commands\MailMakeCommand::class, - Commands\MiddlewareMakeCommand::class, - Commands\NotificationMakeCommand::class, - Commands\ProviderMakeCommand::class, - Commands\RouteProviderMakeCommand::class, - Commands\InstallCommand::class, - Commands\ListCommand::class, - Commands\ModuleDeleteCommand::class, - Commands\ModuleMakeCommand::class, - Commands\FactoryMakeCommand::class, - Commands\PolicyMakeCommand::class, - Commands\RequestMakeCommand::class, - Commands\RuleMakeCommand::class, - Commands\MigrateCommand::class, - Commands\MigrateRefreshCommand::class, - Commands\MigrateResetCommand::class, - Commands\MigrateFreshCommand::class, - Commands\MigrateRollbackCommand::class, - Commands\MigrateStatusCommand::class, - Commands\MigrationMakeCommand::class, - Commands\ModelMakeCommand::class, - Commands\ModelShowCommand::class, - Commands\PublishCommand::class, - Commands\PublishConfigurationCommand::class, - Commands\PublishMigrationCommand::class, - Commands\PublishTranslationCommand::class, - Commands\SeedCommand::class, - Commands\SeedMakeCommand::class, - Commands\SetupCommand::class, - Commands\UnUseCommand::class, - Commands\UpdateCommand::class, - Commands\UseCommand::class, - Commands\ResourceMakeCommand::class, - Commands\TestMakeCommand::class, - Commands\LaravelModulesV6Migrator::class, - Commands\ComponentClassMakeCommand::class, - Commands\ComponentViewMakeCommand::class, - Commands\CheckLangCommand::class, - ]; - public function register(): void { - $this->commands(config('modules.commands', $this->commands)); + $this->commands(config('modules.commands', self::defaultCommands()->toArray())); } public function provides(): array { - return $this->commands; + return self::defaultCommands()->toArray(); + } + + /** + * Get the package default commands. + */ + public static function defaultCommands(): Collection + { + return collect([ + // Actions Commands + Commands\Actions\CheckLangCommand::class, + Commands\Actions\DisableCommand::class, + Commands\Actions\DumpCommand::class, + Commands\Actions\EnableCommand::class, + Commands\Actions\InstallCommand::class, + Commands\Actions\ListCommand::class, + Commands\Actions\ModelPruneCommand::class, + Commands\Actions\ModelShowCommand::class, + Commands\Actions\ModuleDeleteCommand::class, + Commands\Actions\UnUseCommand::class, + Commands\Actions\UpdateCommand::class, + Commands\Actions\UseCommand::class, + + // Database Commands + Commands\Database\MigrateCommand::class, + Commands\Database\MigrateRefreshCommand::class, + Commands\Database\MigrateResetCommand::class, + Commands\Database\MigrateRollbackCommand::class, + Commands\Database\MigrateStatusCommand::class, + Commands\Database\SeedCommand::class, + + // Make Commands + Commands\Make\ActionMakeCommand::class, + Commands\Make\CastMakeCommand::class, + Commands\Make\ChannelMakeCommand::class, + Commands\Make\ClassMakeCommand::class, + Commands\Make\CommandMakeCommand::class, + Commands\Make\ComponentClassMakeCommand::class, + Commands\Make\ComponentViewMakeCommand::class, + Commands\Make\ControllerMakeCommand::class, + Commands\Make\EventMakeCommand::class, + Commands\Make\EventProviderMakeCommand::class, + Commands\Make\EnumMakeCommand::class, + Commands\Make\ExceptionMakeCommand::class, + Commands\Make\FactoryMakeCommand::class, + Commands\Make\InterfaceMakeCommand::class, + Commands\Make\HelperMakeCommand::class, + Commands\Make\JobMakeCommand::class, + Commands\Make\ListenerMakeCommand::class, + Commands\Make\MailMakeCommand::class, + Commands\Make\MiddlewareMakeCommand::class, + Commands\Make\MigrationMakeCommand::class, + Commands\Make\ModelMakeCommand::class, + Commands\Make\ModuleMakeCommand::class, + Commands\Make\NotificationMakeCommand::class, + Commands\Make\ObserverMakeCommand::class, + Commands\Make\PolicyMakeCommand::class, + Commands\Make\ProviderMakeCommand::class, + Commands\Make\RepositoryMakeCommand::class, + Commands\Make\RequestMakeCommand::class, + Commands\Make\ResourceMakeCommand::class, + Commands\Make\RouteProviderMakeCommand::class, + Commands\Make\RuleMakeCommand::class, + Commands\Make\ScopeMakeCommand::class, + Commands\Make\SeedMakeCommand::class, + Commands\Make\ServiceMakeCommand::class, + Commands\Make\TraitMakeCommand::class, + Commands\Make\TestMakeCommand::class, + Commands\Make\ViewMakeCommand::class, + + //Publish Commands + Commands\Publish\PublishCommand::class, + Commands\Publish\PublishConfigurationCommand::class, + Commands\Publish\PublishMigrationCommand::class, + Commands\Publish\PublishTranslationCommand::class, + + // Other Commands + Commands\ComposerUpdateCommand::class, + Commands\LaravelModulesV6Migrator::class, + Commands\ModuleDiscoverCommand::class, + Commands\ModuleClearCompiledCommand::class, + Commands\SetupCommand::class, + + Commands\Database\MigrateFreshCommand::class, + ]); } } diff --git a/src/Publishing/MigrationPublisher.php b/src/Publishing/MigrationPublisher.php index 8dd2a2576..7d03e3b2c 100644 --- a/src/Publishing/MigrationPublisher.php +++ b/src/Publishing/MigrationPublisher.php @@ -13,7 +13,6 @@ class MigrationPublisher extends AssetPublisher /** * MigrationPublisher constructor. - * @param Migrator $migrator */ public function __construct(Migrator $migrator) { diff --git a/src/Publishing/Publisher.php b/src/Publishing/Publisher.php index 3d1488a04..e8416faee 100644 --- a/src/Publishing/Publisher.php +++ b/src/Publishing/Publisher.php @@ -18,6 +18,7 @@ abstract class Publisher implements PublisherInterface /** * The modules repository instance. + * * @var RepositoryInterface */ protected $repository; @@ -52,8 +53,6 @@ abstract class Publisher implements PublisherInterface /** * The constructor. - * - * @param Module $module */ public function __construct(Module $module) { @@ -96,7 +95,7 @@ public function getModule() /** * Set modules repository instance. - * @param RepositoryInterface $repository + * * @return $this */ public function setRepository(RepositoryInterface $repository) @@ -119,7 +118,6 @@ public function getRepository() /** * Set console instance. * - * @param \Illuminate\Console\Command $console * * @return $this */ @@ -169,26 +167,26 @@ abstract public function getSourcePath(); */ public function publish() { - if (!$this->console instanceof Command) { + if (! $this->console instanceof Command) { $message = "The 'console' property must instance of \\Illuminate\\Console\\Command."; throw new \RuntimeException($message); } - if (!$this->getFilesystem()->isDirectory($sourcePath = $this->getSourcePath())) { + if (! $this->getFilesystem()->isDirectory($sourcePath = $this->getSourcePath())) { return; } - if (!$this->getFilesystem()->isDirectory($destinationPath = $this->getDestinationPath())) { + if (! $this->getFilesystem()->isDirectory($destinationPath = $this->getDestinationPath())) { $this->getFilesystem()->makeDirectory($destinationPath, 0775, true); } if ($this->getFilesystem()->copyDirectory($sourcePath, $destinationPath)) { if ($this->showMessage === true) { - $this->console->components->task($this->module->getStudlyName(), fn() => true); + $this->console->components->task($this->module->getStudlyName(), fn () => true); } } else { - $this->console->components->task($this->module->getStudlyName(), fn() => false); + $this->console->components->task($this->module->getStudlyName(), fn () => false); $this->console->components->error($this->error); } } diff --git a/src/Support/Config/GeneratorPath.php b/src/Support/Config/GeneratorPath.php index ad78970db..70df7998f 100644 --- a/src/Support/Config/GeneratorPath.php +++ b/src/Support/Config/GeneratorPath.php @@ -2,10 +2,16 @@ namespace Nwidart\Modules\Support\Config; +use Nwidart\Modules\Traits\PathNamespace; + class GeneratorPath { + use PathNamespace; + private $path; + private $generate; + private $namespace; public function __construct($config) @@ -13,13 +19,14 @@ public function __construct($config) if (is_array($config)) { $this->path = $config['path']; $this->generate = $config['generate']; - $this->namespace = $config['namespace'] ?? $this->convertPathToNamespace($config['path']); + $this->namespace = $config['namespace'] ?? $this->path_namespace(ltrim($config['path'], config('modules.paths.app_folder', ''))); return; } + $this->path = $config; $this->generate = (bool) $config; - $this->namespace = $config; + $this->namespace = $this->path_namespace(ltrim($config, config('modules.paths.app_folder', ''))); } public function getPath() @@ -34,11 +41,6 @@ public function generate(): bool public function getNamespace() { - return $this->namespace; - } - - private function convertPathToNamespace($path) - { - return str_replace('/', '\\', $path); + return $this->studly_namespace($this->namespace); } } diff --git a/src/Support/Migrations/NameParser.php b/src/Support/Migrations/NameParser.php index 4069b815d..3e4d7003f 100644 --- a/src/Support/Migrations/NameParser.php +++ b/src/Support/Migrations/NameParser.php @@ -47,7 +47,7 @@ class NameParser /** * The constructor. * - * @param string $name + * @param string $name */ public function __construct($name) { @@ -152,7 +152,6 @@ public function getData() /** * Determine whether the given type is same with the current schema action or type. * - * @param $type * * @return bool */ diff --git a/src/Support/Migrations/SchemaParser.php b/src/Support/Migrations/SchemaParser.php index 1ef45ae5b..924ecdfbb 100644 --- a/src/Support/Migrations/SchemaParser.php +++ b/src/Support/Migrations/SchemaParser.php @@ -37,7 +37,7 @@ class SchemaParser implements Arrayable /** * Create new instance. * - * @param string|null $schema + * @param string|null $schema */ public function __construct($schema = null) { @@ -47,8 +47,7 @@ public function __construct($schema = null) /** * Parse a string to array of formatted schema. * - * @param string $schema - * + * @param string $schema * @return array */ public function parse($schema) @@ -138,15 +137,14 @@ public function down() /** * Create field. * - * @param string $column - * @param array $attributes - * @param string $type - * + * @param string $column + * @param array $attributes + * @param string $type * @return string */ public function createField($column, $attributes, $type = 'add') { - $results = "\t\t\t" . '$table'; + $results = "\t\t\t".'$table'; foreach ($attributes as $key => $field) { if (in_array($column, $this->relationshipKeys)) { @@ -156,24 +154,23 @@ public function createField($column, $attributes, $type = 'add') } } - return $results . ';' . PHP_EOL; + return $results.';'.PHP_EOL; } /** * Add relation column. * - * @param int $key - * @param string $field - * @param string $column - * + * @param int $key + * @param string $field + * @param string $column * @return string */ protected function addRelationColumn($key, $field, $column) { if ($key === 0) { - $relatedColumn = Str::snake(class_basename($field)) . '_id'; + $relatedColumn = Str::snake(class_basename($field)).'_id'; - return "->integer('{$relatedColumn}')->unsigned();" . PHP_EOL . "\t\t\t" . "\$table->foreign('{$relatedColumn}')"; + return "->integer('{$relatedColumn}')->unsigned();".PHP_EOL."\t\t\t"."\$table->foreign('{$relatedColumn}')"; } if ($key === 1) { return "->references('{$field}')"; @@ -182,61 +179,58 @@ protected function addRelationColumn($key, $field, $column) return "->on('{$field}')"; } if (Str::contains($field, '(')) { - return '->' . $field; + return '->'.$field; } - return '->' . $field . '()'; + return '->'.$field.'()'; } /** * Format field to script. * - * @param int $key - * @param string $field - * @param string $column - * + * @param int $key + * @param string $field + * @param string $column * @return string */ protected function addColumn($key, $field, $column) { if ($this->hasCustomAttribute($column)) { - return '->' . $field; + return '->'.$field; } if ($key == 0) { - return '->' . $field . "('" . $column . "')"; + return '->'.$field."('".$column."')"; } if (Str::contains($field, '(')) { - return '->' . $field; + return '->'.$field; } - return '->' . $field . '()'; + return '->'.$field.'()'; } /** * Format field to script. * - * @param int $key - * @param string $field - * @param string $column - * + * @param int $key + * @param string $field + * @param string $column * @return string */ protected function removeColumn($key, $field, $column) { if ($this->hasCustomAttribute($column)) { - return '->' . $field; + return '->'.$field; } - return '->dropColumn(' . "'" . $column . "')"; + return '->dropColumn('."'".$column."')"; } /** * Get column name from schema. * - * @param string $schema - * + * @param string $schema * @return string */ public function getColumn($schema) @@ -247,14 +241,13 @@ public function getColumn($schema) /** * Get column attributes. * - * @param string $column - * @param string $schema - * + * @param string $column + * @param string $schema * @return array */ public function getAttributes($column, $schema) { - $fields = str_replace($column . ':', '', $schema); + $fields = str_replace($column.':', '', $schema); return $this->hasCustomAttribute($column) ? $this->getCustomAttribute($column) : explode(':', $fields); } @@ -262,8 +255,7 @@ public function getAttributes($column, $schema) /** * Determine whether the given column is exist in customAttributes array. * - * @param string $column - * + * @param string $column * @return bool */ public function hasCustomAttribute($column) @@ -274,8 +266,7 @@ public function hasCustomAttribute($column) /** * Get custom attributes value. * - * @param string $column - * + * @param string $column * @return array */ public function getCustomAttribute($column) diff --git a/src/Support/Stub.php b/src/Support/Stub.php index 3de15b089..ca6dfc18a 100644 --- a/src/Support/Stub.php +++ b/src/Support/Stub.php @@ -28,8 +28,7 @@ class Stub /** * The contructor. * - * @param string $path - * @param array $replaces + * @param string $path */ public function __construct($path, array $replaces = []) { @@ -40,9 +39,7 @@ public function __construct($path, array $replaces = []) /** * Create new self instance. * - * @param string $path - * @param array $replaces - * + * @param string $path * @return self */ public static function create($path, array $replaces = []) @@ -53,8 +50,7 @@ public static function create($path, array $replaces = []) /** * Set stub path. * - * @param string $path - * + * @param string $path * @return self */ public function setPath($path) @@ -71,15 +67,15 @@ public function setPath($path) */ public function getPath() { - $path = static::getBasePath() . $this->path; + $path = static::getBasePath().$this->path; - return file_exists($path) ? $path : __DIR__ . '/../Commands/stubs' . $this->path; + return file_exists($path) ? $path : __DIR__.'/../Commands/stubs'.$this->path; } /** * Set base path. * - * @param string $path + * @param string $path */ public static function setBasePath($path) { @@ -106,7 +102,7 @@ public function getContents() $contents = file_get_contents($this->getPath()); foreach ($this->replaces as $search => $replace) { - $contents = str_replace('$' . strtoupper($search) . '$', $replace, $contents); + $contents = str_replace('$'.strtoupper($search).'$', $replace, $contents); } return $contents; @@ -125,20 +121,18 @@ public function render() /** * Save stub to specific path. * - * @param string $path - * @param string $filename - * + * @param string $path + * @param string $filename * @return bool */ public function saveTo($path, $filename) { - return file_put_contents($path . '/' . $filename, $this->getContents()); + return file_put_contents($path.'/'.$filename, $this->getContents()); } /** * Set replacements array. * - * @param array $replaces * * @return $this */ diff --git a/src/Traits/CanClearModulesCache.php b/src/Traits/CanClearModulesCache.php index 52c9db5a4..b6ea2e499 100644 --- a/src/Traits/CanClearModulesCache.php +++ b/src/Traits/CanClearModulesCache.php @@ -12,5 +12,7 @@ public function clearCache() if (config('modules.cache.enabled') === true) { app('cache')->forget(config('modules.cache.key')); } + + $this->laravel['modules']->resetModules(); } } diff --git a/src/Traits/MigrationLoaderTrait.php b/src/Traits/MigrationLoaderTrait.php index bde0dd1e6..ae274ca34 100644 --- a/src/Traits/MigrationLoaderTrait.php +++ b/src/Traits/MigrationLoaderTrait.php @@ -7,13 +7,13 @@ trait MigrationLoaderTrait /** * Include all migrations files from the specified module. * - * @param string $module + * @param string $module */ protected function loadMigrationFiles($module) { - $path = $this->laravel['modules']->getModulePath($module) . $this->getMigrationGeneratorPath(); + $path = $this->laravel['modules']->getModulePath($module).$this->getMigrationGeneratorPath(); - $files = $this->laravel['files']->glob($path . '/*_*.php'); + $files = $this->laravel['files']->glob($path.'/*_*.php'); foreach ($files as $file) { $this->laravel['files']->requireOnce($file); diff --git a/src/Traits/ModuleCommandTrait.php b/src/Traits/ModuleCommandTrait.php index 969834a4a..65e31d83b 100644 --- a/src/Traits/ModuleCommandTrait.php +++ b/src/Traits/ModuleCommandTrait.php @@ -4,12 +4,7 @@ trait ModuleCommandTrait { - /** - * Get the module name. - * - * @return string - */ - public function getModuleName() + public function getModuleName(): string { $module = $this->argument('module') ?: app('modules')->getUsedNow(); diff --git a/src/Traits/PathNamespace.php b/src/Traits/PathNamespace.php new file mode 100644 index 000000000..537aafe28 --- /dev/null +++ b/src/Traits/PathNamespace.php @@ -0,0 +1,75 @@ +clean_path($path, $ds)))->map(fn ($path) => Str::studly($path))->implode($ds); + } + + /** + * Get a well-formatted StudlyCase namespace. + */ + public function studly_namespace(string $namespace, $ds = '\\'): string + { + return $this->studly_path($namespace, $ds); + } + + /** + * Get a well-formatted namespace from a given path. + */ + public function path_namespace(string $path): string + { + return Str::of($this->studly_path($path))->replace('/', '\\')->trim('\\'); + } + + /** + * Get a well-formatted StudlyCase namespace for a module, with an optional additional path. + */ + public function module_namespace(string $module, ?string $path = null): string + { + $module_namespace = config('modules.namespace', $this->path_namespace(config('modules.paths.modules'))).'\\'.($module); + $module_namespace .= strlen($path) ? '\\'.$this->path_namespace($path) : ''; + + return $this->studly_namespace($module_namespace); + } + + /** + * Clean path + */ + public function clean_path(string $path, $ds = '/'): string + { + return Str::of($path)->explode($ds)->reject(empty($path))->implode($ds); + } + + /** + * Get the app path basename. + */ + public function app_path(?string $path = null): string + { + $config_path = config('modules.paths.app_folder'); + + // Get modules config app path or use Laravel default app path. + $app_path = strlen($config_path) ? $config_path : 'app/'; + + if ($path) { + // Replace duplicate custom|default app paths + $replaces = array_unique([$this->clean_path($app_path).'/', 'app/']); + do { + $path = Str::of($path)->replaceStart($app_path, '')->replaceStart('app/', ''); + } while (Str::of($path)->startsWith($replaces)); + + // Append additional path + $app_path .= strlen($path) ? '/'.$path : ''; + } + + return $this->clean_path($app_path); + } +} diff --git a/src/helpers.php b/src/helpers.php index 166d9d036..8d39f267e 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -8,7 +8,7 @@ function module_path($name, $path = '') { $module = app('modules')->find($name); - return $module->getPath() . ($path ? DIRECTORY_SEPARATOR . $path : $path); + return $module->getPath().($path ? DIRECTORY_SEPARATOR.$path : $path); } } @@ -16,12 +16,12 @@ function module_path($name, $path = '') /** * Get the configuration path. * - * @param string $path + * @param string $path * @return string */ function config_path($path = '') { - return app()->basePath() . '/config' . ($path ? DIRECTORY_SEPARATOR . $path : $path); + return app()->basePath().'/config'.($path ? DIRECTORY_SEPARATOR.$path : $path); } } @@ -34,7 +34,7 @@ function config_path($path = '') */ function public_path($path = '') { - return app()->make('path.public') . ($path ? DIRECTORY_SEPARATOR . ltrim($path, DIRECTORY_SEPARATOR) : $path); + return app()->make('path.public').($path ? DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR) : $path); } } diff --git a/tests/Activators/FileActivatorTest.php b/tests/Activators/FileActivatorTest.php index a7a1affb5..1ac75197d 100644 --- a/tests/Activators/FileActivatorTest.php +++ b/tests/Activators/FileActivatorTest.php @@ -28,7 +28,7 @@ class FileActivatorTest extends BaseTestCase public function setUp(): void { parent::setUp(); - $this->module = new TestModule($this->app, 'Recipe', __DIR__ . '/stubs/valid/Recipe'); + $this->module = new TestModule($this->app, 'Recipe', __DIR__.'/stubs/valid/Recipe'); $this->finder = $this->app['files']; $this->activator = new FileActivator($this->app); } @@ -39,8 +39,7 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_creates_valid_json_file_after_enabling() + public function test_it_creates_valid_json_file_after_enabling() { $this->activator->enable($this->module); $this->assertMatchesSnapshot($this->finder->get($this->activator->getStatusesFilePath())); @@ -49,8 +48,7 @@ public function it_creates_valid_json_file_after_enabling() $this->assertMatchesSnapshot($this->finder->get($this->activator->getStatusesFilePath())); } - /** @test */ - public function it_creates_valid_json_file_after_disabling() + public function test_it_creates_valid_json_file_after_disabling() { $this->activator->disable($this->module); $this->assertMatchesSnapshot($this->finder->get($this->activator->getStatusesFilePath())); @@ -59,8 +57,7 @@ public function it_creates_valid_json_file_after_disabling() $this->assertMatchesSnapshot($this->finder->get($this->activator->getStatusesFilePath())); } - /** @test */ - public function it_can_check_module_enabled_status() + public function test_it_can_check_module_enabled_status() { $this->activator->enable($this->module); $this->assertTrue($this->activator->hasStatus($this->module, true)); @@ -69,8 +66,7 @@ public function it_can_check_module_enabled_status() $this->assertTrue($this->activator->hasStatus($this->module, true)); } - /** @test */ - public function it_can_check_module_disabled_status() + public function test_it_can_check_module_disabled_status() { $this->activator->disable($this->module); $this->assertTrue($this->activator->hasStatus($this->module, false)); @@ -79,8 +75,7 @@ public function it_can_check_module_disabled_status() $this->assertTrue($this->activator->hasStatus($this->module, false)); } - /** @test */ - public function it_can_check_status_of_module_that_hasnt_been_enabled_or_disabled() + public function test_it_can_check_status_of_module_that_hasnt_been_enabled_or_disabled() { $this->assertTrue($this->activator->hasStatus($this->module, false)); } diff --git a/tests/Activators/__snapshots__/FileActivatorTest__test_it_creates_valid_json_file_after_disabling__1.txt b/tests/Activators/__snapshots__/FileActivatorTest__test_it_creates_valid_json_file_after_disabling__1.txt new file mode 100644 index 000000000..df07c139d --- /dev/null +++ b/tests/Activators/__snapshots__/FileActivatorTest__test_it_creates_valid_json_file_after_disabling__1.txt @@ -0,0 +1,3 @@ +{ + "Recipe": false +} \ No newline at end of file diff --git a/tests/Activators/__snapshots__/FileActivatorTest__test_it_creates_valid_json_file_after_disabling__2.txt b/tests/Activators/__snapshots__/FileActivatorTest__test_it_creates_valid_json_file_after_disabling__2.txt new file mode 100644 index 000000000..df07c139d --- /dev/null +++ b/tests/Activators/__snapshots__/FileActivatorTest__test_it_creates_valid_json_file_after_disabling__2.txt @@ -0,0 +1,3 @@ +{ + "Recipe": false +} \ No newline at end of file diff --git a/tests/Activators/__snapshots__/FileActivatorTest__test_it_creates_valid_json_file_after_enabling__1.txt b/tests/Activators/__snapshots__/FileActivatorTest__test_it_creates_valid_json_file_after_enabling__1.txt new file mode 100644 index 000000000..57b480388 --- /dev/null +++ b/tests/Activators/__snapshots__/FileActivatorTest__test_it_creates_valid_json_file_after_enabling__1.txt @@ -0,0 +1,3 @@ +{ + "Recipe": true +} \ No newline at end of file diff --git a/tests/Activators/__snapshots__/FileActivatorTest__test_it_creates_valid_json_file_after_enabling__2.txt b/tests/Activators/__snapshots__/FileActivatorTest__test_it_creates_valid_json_file_after_enabling__2.txt new file mode 100644 index 000000000..57b480388 --- /dev/null +++ b/tests/Activators/__snapshots__/FileActivatorTest__test_it_creates_valid_json_file_after_enabling__2.txt @@ -0,0 +1,3 @@ +{ + "Recipe": true +} \ No newline at end of file diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index 8c4ca94fc..7d69a8c51 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -2,8 +2,8 @@ namespace Nwidart\Modules\Tests; -use Nwidart\Modules\Commands; use Nwidart\Modules\LaravelModulesServiceProvider; +use Nwidart\Modules\Providers\ConsoleServiceProvider; use Orchestra\Testbench\TestCase as OrchestraTestCase; abstract class BaseTestCase extends OrchestraTestCase @@ -39,6 +39,13 @@ protected function getPackageProviders($app) */ protected function getEnvironmentSetUp($app) { + $module_config = require __DIR__.'/../config/config.php'; + + // enable all generators + array_walk($module_config['paths']['generator'], function (&$item) { + $item['generate'] = true; + }); + $app['config']->set('app.asset_url', null); $app['config']->set('database.default', 'sqlite'); $app['config']->set('database.connections.sqlite', [ @@ -51,87 +58,32 @@ protected function getEnvironmentSetUp($app) 'modules' => base_path('modules'), 'assets' => public_path('modules'), 'migration' => base_path('database/migrations'), - 'generator' => [ - 'assets' => ['path' => 'Assets', 'generate' => true], - 'config' => ['path' => 'Config', 'generate' => true], - 'command' => ['path' => 'Console', 'generate' => true], - 'event' => ['path' => 'Events', 'generate' => true], - 'listener' => ['path' => 'Listeners', 'generate' => true], - 'migration' => ['path' => 'Database/Migrations', 'generate' => true], - 'factory' => ['path' => 'Database/factories', 'generate' => true], - 'model' => ['path' => 'Entities', 'generate' => true], - 'repository' => ['path' => 'Repositories', 'generate' => true], - 'seeder' => ['path' => 'Database/Seeders', 'generate' => true], - 'controller' => ['path' => 'Http/Controllers', 'generate' => true], - 'filter' => ['path' => 'Http/Middleware', 'generate' => true], - 'request' => ['path' => 'Http/Requests', 'generate' => true], - 'provider' => ['path' => 'Providers', 'generate' => true], - 'lang' => ['path' => 'Resources/lang', 'generate' => true], - 'views' => ['path' => 'Resources/views', 'generate' => true], - 'policies' => ['path' => 'Policies', 'generate' => true], - 'rules' => ['path' => 'Rules', 'generate' => true], - 'test-feature' => ['path' => 'Tests/Feature', 'generate' => true], - 'test' => ['path' => 'Tests/Unit', 'generate' => true], - 'jobs' => ['path' => 'Jobs', 'generate' => true], - 'emails' => ['path' => 'Emails', 'generate' => true], - 'notifications' => ['path' => 'Notifications', 'generate' => true], - 'resource' => ['path' => 'Transformers', 'generate' => true], - 'component-view' => ['path' => 'Resources/views/components', 'generate' => true], - 'component-class' => ['path' => 'View/Component', 'generate' => true], - ], + 'app_folder' => $module_config['paths']['app_folder'], + 'generator' => $module_config['paths']['generator'], ]); $app['config']->set('modules.composer-output', true); - $app['config']->set('modules.commands', [ - Commands\CommandMakeCommand::class, - Commands\ControllerMakeCommand::class, - Commands\DisableCommand::class, - Commands\DumpCommand::class, - Commands\EnableCommand::class, - Commands\EventMakeCommand::class, - Commands\JobMakeCommand::class, - Commands\ListenerMakeCommand::class, - Commands\MailMakeCommand::class, - Commands\MiddlewareMakeCommand::class, - Commands\NotificationMakeCommand::class, - Commands\ProviderMakeCommand::class, - Commands\RouteProviderMakeCommand::class, - Commands\InstallCommand::class, - Commands\ListCommand::class, - Commands\ModuleDeleteCommand::class, - Commands\ModuleMakeCommand::class, - Commands\FactoryMakeCommand::class, - Commands\PolicyMakeCommand::class, - Commands\RequestMakeCommand::class, - Commands\RuleMakeCommand::class, - Commands\MigrateCommand::class, - Commands\MigrateRefreshCommand::class, - Commands\MigrateResetCommand::class, - Commands\MigrateRollbackCommand::class, - Commands\MigrateStatusCommand::class, - Commands\MigrationMakeCommand::class, - Commands\ModelMakeCommand::class, - Commands\PublishCommand::class, - Commands\PublishConfigurationCommand::class, - Commands\PublishMigrationCommand::class, - Commands\PublishTranslationCommand::class, - Commands\SeedCommand::class, - Commands\SeedMakeCommand::class, - Commands\SetupCommand::class, - Commands\UnUseCommand::class, - Commands\UpdateCommand::class, - Commands\UseCommand::class, - Commands\ResourceMakeCommand::class, - Commands\TestMakeCommand::class, - Commands\LaravelModulesV6Migrator::class, - Commands\ComponentClassMakeCommand::class, - Commands\ComponentViewMakeCommand::class, - ]); + $app['config']->set('modules.commands', ConsoleServiceProvider::defaultCommands()->toArray()); } protected function setUpDatabase() { $this->resetDatabase(); } + + protected function createModule(string $moduleName = 'Blog'): int + { + return $this->artisan('module:make', ['name' => [$moduleName]]); + } + + protected function getModuleAppPath(string $moduleName = 'Blog'): string + { + return base_path("modules/$moduleName/").rtrim(config('modules.paths.app_folder'), '/'); + } + + protected function getModuleBasePath(string $moduleName = 'Blog'): string + { + return base_path("modules/$moduleName"); + } } diff --git a/tests/CollectionTest.php b/tests/CollectionTest.php index 1e2889210..5b6f755b4 100644 --- a/tests/CollectionTest.php +++ b/tests/CollectionTest.php @@ -1,17 +1,16 @@ app, 'module-one', $moduleOnePath), new Module($this->app, 'module-two', $moduleTwoPath), @@ -25,12 +24,11 @@ public function toArraySetsPathAttribute() $this->assertEquals($moduleTwoPath, $collectionArray[1]['path']); } - /** @test */ - public function getItemsReturnsTheCollectionItems() + public function test_getItemsReturnsTheCollectionItems() { $modules = [ - new Module($this->app, 'module-one', __DIR__ . '/stubs/valid/Recipe'), - new Module($this->app, 'module-two', __DIR__ . '/stubs/valid/Requirement'), + new Module($this->app, 'module-one', __DIR__.'/stubs/valid/Recipe'), + new Module($this->app, 'module-two', __DIR__.'/stubs/valid/Requirement'), ]; $collection = new Collection($modules); $items = $collection->getItems(); diff --git a/tests/Commands/Actions/ClearCompiledCommandTest.php b/tests/Commands/Actions/ClearCompiledCommandTest.php new file mode 100644 index 000000000..1f141cd2a --- /dev/null +++ b/tests/Commands/Actions/ClearCompiledCommandTest.php @@ -0,0 +1,82 @@ +finder = $this->app['files']; + $this->manifestPath = app()->make(ModuleManifest::class)->manifestPath; + $this->repository = $this->app[RepositoryInterface::class]; + } + + public function tearDown(): void + { + $this->artisan('module:delete', ['--all' => true, '--force' => true]); + parent::tearDown(); + } + + public function test_manifest_file_clear_when_call_command() + { + $this->createModule(); + $code = $this->artisan('module:clear-compiled'); + + $this->assertFileDoesNotExist($this->manifestPath); + $this->assertSame(0, $code); + } + + public function test_manifest_file_clear_when_create_module() + { + $this->assertFileExists($this->manifestPath); + + $this->createModule('Foo'); + + $this->assertFileDoesNotExist($this->manifestPath); + } + + public function test_manifest_file_clear_when_delete_module() + { + $this->assertFileExists($this->manifestPath); + + $this->createModule('Foo'); + + $this->artisan('module:delete', ['module' => 'Foo', '--force' => true]); + + $this->assertFileDoesNotExist($this->manifestPath); + } + + public function test_manifest_file_clear_when_disable_module() + { + $this->assertFileExists($this->manifestPath); + + $this->createModule('Foo'); + + $this->artisan('module:disable', ['module' => 'Foo']); + + $this->assertFileDoesNotExist($this->manifestPath); + } + + public function test_manifest_file_clear_when_enable_module() + { + $this->assertFileExists($this->manifestPath); + + $this->createModule('Foo'); + + $this->artisan('module:enable', ['module' => 'Foo']); + + $this->assertFileDoesNotExist($this->manifestPath); + } +} diff --git a/tests/Commands/Actions/DisableCommandTest.php b/tests/Commands/Actions/DisableCommandTest.php new file mode 100644 index 000000000..de196696b --- /dev/null +++ b/tests/Commands/Actions/DisableCommandTest.php @@ -0,0 +1,71 @@ +createModule('Blog'); + $this->createModule('Taxonomy'); + $this->repository = $this->app[RepositoryInterface::class]; + } + + public function tearDown(): void + { + $this->repository->delete('Blog'); + $this->repository->delete('Taxonomy'); + parent::tearDown(); + } + + public function test_it_disables_a_module() + { + /** @var Module $blogModule */ + $blogModule = $this->repository->find('Blog'); + $blogModule->disable(); + + $code = $this->artisan('module:disable', ['module' => ['Blog']]); + + $this->assertTrue($blogModule->isDisabled()); + $this->assertSame(0, $code); + } + + public function test_it_disables_array_of_modules() + { + /** @var Module $blogModule */ + $blogModule = $this->repository->find('Blog'); + $blogModule->enable(); + + /** @var Module $taxonomyModule */ + $taxonomyModule = $this->repository->find('Taxonomy'); + $taxonomyModule->enable(); + + $code = $this->artisan('module:disable', ['module' => ['Blog', 'Taxonomy']]); + + $this->assertTrue($blogModule->isDisabled() && $taxonomyModule->isDisabled()); + $this->assertSame(0, $code); + } + + public function test_it_disables_all_modules() + { + /** @var Module $blogModule */ + $blogModule = $this->repository->find('Blog'); + $blogModule->enable(); + + /** @var Module $taxonomyModule */ + $taxonomyModule = $this->repository->find('Taxonomy'); + $taxonomyModule->enable(); + + $code = $this->artisan('module:disable', ['--all' => true]); + + $this->assertTrue($blogModule->isDisabled() && $taxonomyModule->isDisabled()); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/Actions/EnableCommandTest.php b/tests/Commands/Actions/EnableCommandTest.php new file mode 100644 index 000000000..836bbcc27 --- /dev/null +++ b/tests/Commands/Actions/EnableCommandTest.php @@ -0,0 +1,71 @@ +createModule('Blog'); + $this->createModule('Taxonomy'); + $this->repository = $this->app[RepositoryInterface::class]; + } + + public function tearDown(): void + { + $this->repository->delete('Blog'); + $this->repository->delete('Taxonomy'); + parent::tearDown(); + } + + public function test_it_enables_a_module() + { + /** @var Module $blogModule */ + $blogModule = $this->repository->find('Blog'); + $blogModule->disable(); + + $code = $this->artisan('module:enable', ['module' => 'Blog']); + + $this->assertTrue($blogModule->isEnabled()); + $this->assertSame(0, $code); + } + + public function test_it_enables_array_of_modules() + { + /** @var Module $blogModule */ + $blogModule = $this->repository->find('Blog'); + $blogModule->disable(); + + /** @var Module $taxonomyModule */ + $taxonomyModule = $this->repository->find('Taxonomy'); + $taxonomyModule->disable(); + + $code = $this->artisan('module:enable', ['module' => ['Blog', 'Taxonomy']]); + + $this->assertTrue($blogModule->isEnabled() && $taxonomyModule->isEnabled()); + $this->assertSame(0, $code); + } + + public function test_it_enables_all_modules() + { + /** @var Module $blogModule */ + $blogModule = $this->repository->find('Blog'); + $blogModule->disable(); + + /** @var Module $taxonomyModule */ + $taxonomyModule = $this->repository->find('Taxonomy'); + $taxonomyModule->disable(); + + $code = $this->artisan('module:enable', ['--all' => true]); + + $this->assertTrue($blogModule->isEnabled() && $taxonomyModule->isEnabled()); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/ListCommandTest.php b/tests/Commands/Actions/ListCommandTest.php similarity index 68% rename from tests/Commands/ListCommandTest.php rename to tests/Commands/Actions/ListCommandTest.php index 90d058708..66a61c1bd 100644 --- a/tests/Commands/ListCommandTest.php +++ b/tests/Commands/Actions/ListCommandTest.php @@ -2,16 +2,11 @@ namespace Nwidart\Modules\Commands; -use Illuminate\Filesystem\Filesystem; use Nwidart\Modules\Contracts\RepositoryInterface; use Nwidart\Modules\Tests\BaseTestCase; class ListCommandTest extends BaseTestCase { - /** - * @var Filesystem - */ - private $finder; /** * @var string */ @@ -20,9 +15,8 @@ class ListCommandTest extends BaseTestCase public function setUp(): void { parent::setUp(); - $this->modulePath = base_path('modules/Blog'); - $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -31,8 +25,7 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_can_list_modules() + public function test_it_can_list_modules() { $code = $this->artisan('module:list'); diff --git a/tests/Commands/Actions/ModuleDeleteCommandTest.php b/tests/Commands/Actions/ModuleDeleteCommandTest.php new file mode 100644 index 000000000..59bca661b --- /dev/null +++ b/tests/Commands/Actions/ModuleDeleteCommandTest.php @@ -0,0 +1,142 @@ +finder = $this->app['files']; + $this->activator = new FileActivator($this->app); + } + + public function tearDown(): void + { + $this->artisan('module:delete', ['--all' => true, '--force' => true]); + + $this->activator->reset(); + parent::tearDown(); + } + + public function test_it_can_delete_a_module_from_disk(): void + { + $this->artisan('module:make', ['name' => ['WrongModule']]); + $this->assertDirectoryExists(base_path('modules/WrongModule')); + + $code = $this->artisan('module:delete', ['module' => 'WrongModule', '--force' => true]); + $this->assertFileDoesNotExist(base_path('modules/WrongModule')); + $this->assertSame(0, $code); + } + + public function test_it_can_delete_array_module_from_disk(): void + { + $modules = [ + 'Foo', + 'Bar', + 'Zoo', + ]; + + foreach ($modules as $module) { + $this->createModule($module); + $this->assertDirectoryExists($this->getModuleBasePath($module)); + } + + $code = $this->artisan('module:delete', ['module' => ['Foo', 'Bar'], '--force' => true]); + $this->assertSame(0, $code); + $this->assertFileDoesNotExist($this->getModuleBasePath('Foo')); + $this->assertFileDoesNotExist($this->getModuleBasePath('Bar')); + $this->assertDirectoryExists($this->getModuleBasePath('Zoo')); + + $this->app[RepositoryInterface::class]->delete('Zoo'); + } + + public function test_it_can_delete_all_module_from_disk(): void + { + $modules = [ + 'Foo', + 'Bar', + 'Zoo', + ]; + + foreach ($modules as $module) { + $this->createModule($module); + $this->assertDirectoryExists($this->getModuleBasePath($module)); + } + + $code = $this->artisan('module:delete', ['--all' => true, '--force' => true]); + $this->assertSame(0, $code); + $this->assertFileDoesNotExist($this->getModuleBasePath('Foo')); + $this->assertFileDoesNotExist($this->getModuleBasePath('Bar')); + $this->assertFileDoesNotExist($this->getModuleBasePath('Zoo')); + } + + public function test_it_deletes_modules_from_status_file(): void + { + $this->artisan('module:make', ['name' => ['WrongModule']]); + $this->assertMatchesSnapshot($this->finder->get($this->activator->getStatusesFilePath())); + + $code = $this->artisan('module:delete', ['module' => 'WrongModule', '--force' => true]); + $this->assertMatchesSnapshot($this->finder->get($this->activator->getStatusesFilePath())); + $this->assertSame(0, $code); + } + + public function test_it_fires_events_when_module_deleted() + { + $module_name = 'Blog'; + + $this->createModule($module_name); + + Event::fake(); + + $code = $this->artisan('module:delete', ['module' => [$module_name], '--force' => true]); + + $this->assertSame(0, $code); + + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::DELETING, strtolower($module_name))); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::DELETED, strtolower($module_name))); + } + + public function test_it_fires_events_when_multi_module_deleted() + { + $modules = [ + 'Foo', + 'Bar', + 'Zoo', + ]; + + foreach ($modules as $module) { + $this->createModule($module); + } + + Event::fake(); + + $code = $this->artisan('module:delete', ['--all' => true, '--force' => true]); + + $this->assertSame(0, $code); + + foreach ($modules as $module) { + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::DELETING, strtolower($module))); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::DELETED, strtolower($module))); + } + } +} diff --git a/tests/Commands/Actions/ModuleDiscoverCommandTest.php b/tests/Commands/Actions/ModuleDiscoverCommandTest.php new file mode 100644 index 000000000..f0f0a4a7e --- /dev/null +++ b/tests/Commands/Actions/ModuleDiscoverCommandTest.php @@ -0,0 +1,84 @@ +finder = $this->app['files']; + $this->manifestPath = app()->make(ModuleManifest::class)->manifestPath; + $this->repository = $this->app[RepositoryInterface::class]; + } + + public function tearDown(): void + { + $this->artisan('module:delete', ['--all' => true, '--force' => true]); + parent::tearDown(); + } + + public function test_run_command_without_error() + { + $this->createModule(); + + $code = $this->artisan('module:discover'); + + $this->assertSame(0, $code); + } + + public function test_manifest_file_contain_new_module_provider() + { + $this->createModule('Foo'); + + $path = base_path('modules/Foo').'/module.json'; + $provider = json_decode($this->finder->get($path))->providers[0]; + + $code = $this->artisan('module:discover'); + $this->assertSame(0, $code); + + $manifest = require $this->manifestPath; + + $this->assertContains($provider, $manifest['providers'], 'provider not found in manifest file'); + $this->assertContains($provider, $manifest['eager'], 'provider not found in manifest file'); + } + + public function test_manifest_file_contain_multi_module_provider() + { + $modules = [ + 'Foo', + 'Bar', + 'Baz', + ]; + + foreach ($modules as $module) { + $this->createModule($module); + } + + $code = $this->artisan('module:discover'); + $this->assertSame(0, $code); + + $manifest = require $this->manifestPath; + + foreach ($modules as $module) { + $path = module_path($module).'/module.json'; + $provider = json_decode($this->finder->get($path))->providers[0]; + + $this->assertContains($provider, $manifest['providers'], 'provider not found in manifest file'); + $this->assertContains($provider, $manifest['eager'], 'provider not found in manifest file'); + } + } + + +} diff --git a/tests/Commands/__snapshots__/ModuleDeleteCommandTest__it_deletes_modules_from_status_file__1.txt b/tests/Commands/Actions/__snapshots__/ModuleDeleteCommandTest__test_it_deletes_modules_from_status_file__1.txt similarity index 100% rename from tests/Commands/__snapshots__/ModuleDeleteCommandTest__it_deletes_modules_from_status_file__1.txt rename to tests/Commands/Actions/__snapshots__/ModuleDeleteCommandTest__test_it_deletes_modules_from_status_file__1.txt diff --git a/tests/Commands/__snapshots__/ModuleDeleteCommandTest__it_deletes_modules_from_status_file__2.txt b/tests/Commands/Actions/__snapshots__/ModuleDeleteCommandTest__test_it_deletes_modules_from_status_file__2.txt similarity index 100% rename from tests/Commands/__snapshots__/ModuleDeleteCommandTest__it_deletes_modules_from_status_file__2.txt rename to tests/Commands/Actions/__snapshots__/ModuleDeleteCommandTest__test_it_deletes_modules_from_status_file__2.txt diff --git a/tests/Commands/EnableCommandTest.php b/tests/Commands/EnableCommandTest.php deleted file mode 100644 index 7d6e39354..000000000 --- a/tests/Commands/EnableCommandTest.php +++ /dev/null @@ -1,54 +0,0 @@ -artisan('module:make', ['name' => ['Blog']]); - $this->artisan('module:make', ['name' => ['Taxonomy']]); - } - - public function tearDown(): void - { - $this->app[RepositoryInterface::class]->delete('Blog'); - $this->app[RepositoryInterface::class]->delete('Taxonomy'); - parent::tearDown(); - } - - /** @test */ - public function it_enables_a_module() - { - /** @var Module $blogModule */ - $blogModule = $this->app[RepositoryInterface::class]->find('Blog'); - $blogModule->disable(); - - $code = $this->artisan('module:enable', ['module' => 'Blog']); - - $this->assertTrue($blogModule->isEnabled()); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_enables_all_modules() - { - /** @var Module $blogModule */ - $blogModule = $this->app[RepositoryInterface::class]->find('Blog'); - $blogModule->disable(); - - /** @var Module $taxonomyModule */ - $taxonomyModule = $this->app[RepositoryInterface::class]->find('Taxonomy'); - $taxonomyModule->disable(); - - $code = $this->artisan('module:enable'); - - $this->assertTrue($blogModule->isEnabled() && $taxonomyModule->isEnabled()); - $this->assertSame(0, $code); - } -} diff --git a/tests/Commands/Make/ActionMakeCommandTest.php b/tests/Commands/Make/ActionMakeCommandTest.php new file mode 100644 index 000000000..0631781a7 --- /dev/null +++ b/tests/Commands/Make/ActionMakeCommandTest.php @@ -0,0 +1,90 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_a_new_action_class() + { + $code = $this->artisan('module:make-action', ['name' => 'MyAction', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Actions/MyAction.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_action_class_can_override_with_force_option() + { + $this->artisan('module:make-action', ['name' => 'MyAction', 'module' => 'Blog']); + $code = $this->artisan('module:make-action', ['name' => 'MyAction', 'module' => 'Blog', '--force' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Actions/MyAction.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_action_class_can_use_invoke_option() + { + $code = $this->artisan('module:make-action', ['name' => 'MyAction', 'module' => 'Blog', '--invokable' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Actions/MyAction.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-action', ['name' => 'MyAction', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Actions/MyAction.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_action_in_sub_namespace_in_correct_folder() + { + $code = $this->artisan('module:make-action', ['name' => 'Api\\MyAction', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Actions/Api/MyAction.php')); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_action_in_sub_namespace_with_correct_generated_file() + { + $code = $this->artisan('module:make-action', ['name' => 'Api\\MyAction', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Actions/Api/MyAction.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/Make/CastMakeCommandTest.php b/tests/Commands/Make/CastMakeCommandTest.php new file mode 100644 index 000000000..4c41ee2ee --- /dev/null +++ b/tests/Commands/Make/CastMakeCommandTest.php @@ -0,0 +1,82 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_a_new_cast_class() + { + $code = $this->artisan('module:make-cast', ['name' => 'MyCast', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Casts/MyCast.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_cast_class_can_override_with_force_option() + { + $this->artisan('module:make-cast', ['name' => 'MyCast', 'module' => 'Blog']); + $code = $this->artisan('module:make-cast', ['name' => 'MyCast', 'module' => 'Blog', '--force' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Casts/MyCast.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-cast', ['name' => 'MyCast', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Casts/MyCast.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_cast_in_sub_namespace_in_correct_folder() + { + $code = $this->artisan('module:make-cast', ['name' => 'Api\\MyCast', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Casts/Api/MyCast.php')); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_cast_in_sub_namespace_with_correct_generated_file() + { + $code = $this->artisan('module:make-cast', ['name' => 'Api\\MyCast', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Casts/Api/MyCast.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/Make/ChannelMakeCommandTest.php b/tests/Commands/Make/ChannelMakeCommandTest.php new file mode 100644 index 000000000..c622f764d --- /dev/null +++ b/tests/Commands/Make/ChannelMakeCommandTest.php @@ -0,0 +1,78 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_the_channel_class() + { + $code = $this->artisan('module:make-channel', ['name' => 'WelcomeChannel', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Broadcasting/WelcomeChannel.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-channel', ['name' => 'WelcomeChannel', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Broadcasting/WelcomeChannel.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_can_change_the_default_namespace() + { + $this->app['config']->set('modules.paths.generator.channels.path', 'SuperChannel'); + + $code = $this->artisan('module:make-channel', ['name' => 'WelcomeChannel', 'module' => 'Blog']); + + $file = $this->finder->get($this->getModuleBasePath().'/SuperChannel/WelcomeChannel.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_can_change_the_default_namespace_specific() + { + $this->app['config']->set('modules.paths.generator.channels.namespace', 'SuperChannel'); + + $code = $this->artisan('module:make-channel', ['name' => 'WelcomeChannel', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Broadcasting/WelcomeChannel.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/Make/ClassMakeCommandTest.php b/tests/Commands/Make/ClassMakeCommandTest.php new file mode 100644 index 000000000..63ef4eb7e --- /dev/null +++ b/tests/Commands/Make/ClassMakeCommandTest.php @@ -0,0 +1,106 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_a_new_class() + { + $code = $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Classes/Demo.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_class_can_override_with_force_option() + { + $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog']); + $code = $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog', '--force' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Classes/Demo.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_class_can_use_invoke_option() + { + $code = $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog', '--invokable' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Classes/Demo.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_class_can_use_suffix_option() + { + $code = $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog', '--suffix' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Classes/DemoClass.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_class_use_type_option() + { + $code = $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog', '--type' => 'contract']); + + $this->assertTrue(is_file($this->modulePath.'/Contracts/Demo.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-class', ['name' => 'Demo', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Classes/Demo.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_class_in_sub_namespace_in_correct_folder() + { + $code = $this->artisan('module:make-class', ['name' => 'Api\\Demo', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Classes/Api/Demo.php')); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_class_in_sub_namespace_with_correct_generated_file() + { + $code = $this->artisan('module:make-class', ['name' => 'Api\\Demo', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Classes/Api/Demo.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/CommandMakeCommandTest.php b/tests/Commands/Make/CommandMakeCommandTest.php similarity index 64% rename from tests/Commands/CommandMakeCommandTest.php rename to tests/Commands/Make/CommandMakeCommandTest.php index 6a4031b6b..b2e6612c2 100644 --- a/tests/Commands/CommandMakeCommandTest.php +++ b/tests/Commands/Make/CommandMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -32,61 +34,56 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_a_new_console_command_class() + public function test_it_generates_a_new_console_command_class() { $code = $this->artisan('module:make-command', ['name' => 'MyAwesomeCommand', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Console/MyAwesomeCommand.php')); + $this->assertTrue(is_file($this->modulePath.'/Console/MyAwesomeCommand.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-command', ['name' => 'MyAwesomeCommand', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Console/MyAwesomeCommand.php'); + $file = $this->finder->get($this->modulePath.'/Console/MyAwesomeCommand.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_uses_set_command_name_in_class() + public function test_it_uses_set_command_name_in_class() { $code = $this->artisan( 'module:make-command', ['name' => 'MyAwesomeCommand', 'module' => 'Blog', '--command' => 'my:awesome'] ); - $file = $this->finder->get($this->modulePath . '/Console/MyAwesomeCommand.php'); + $file = $this->finder->get($this->modulePath.'/Console/MyAwesomeCommand.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { - $this->app['config']->set('modules.paths.generator.command.path', 'Commands'); + $this->app['config']->set('modules.paths.generator.command.path', 'app/CustomCommands'); $code = $this->artisan('module:make-command', ['name' => 'AwesomeCommand', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Commands/AwesomeCommand.php'); + $file = $this->finder->get($this->modulePath.'/CustomCommands/AwesomeCommand.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.command.namespace', 'Commands'); $code = $this->artisan('module:make-command', ['name' => 'AwesomeCommand', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Console/AwesomeCommand.php'); + $file = $this->finder->get($this->modulePath.'/Console/AwesomeCommand.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/ComponentClassMakeCommandTest.php b/tests/Commands/Make/ComponentClassMakeCommandTest.php similarity index 61% rename from tests/Commands/ComponentClassMakeCommandTest.php rename to tests/Commands/Make/ComponentClassMakeCommandTest.php index 779675060..868ea6da6 100644 --- a/tests/Commands/ComponentClassMakeCommandTest.php +++ b/tests/Commands/Make/ComponentClassMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -32,38 +34,36 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_the_component_class() + public function test_it_generates_the_component_class() { $code = $this->artisan('module:make-component', ['name' => 'Blog', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/View/Component/Blog.php')); + $this->assertTrue(is_file($this->modulePath.'/View/Components/Blog.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_the_component_view_from_component_class_command() + + public function test_it_generates_the_component_view_from_component_class_command() { $code = $this->artisan('module:make-component', ['name' => 'Blog', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Resources/views/components/blog.blade.php'); + $file = $this->finder->get($this->getModuleBasePath().'/resources/views/components/blog.blade.php'); $this->assertTrue(str_contains($file, '
')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + + public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-component', ['name' => 'Blog', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/View/Component/Blog.php'); + $file = $this->finder->get($this->modulePath.'/View/Components/Blog.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { - $this->app['config']->set('modules.paths.generator.component-class.path', 'View/Component/newDirectory'); + $this->app['config']->set('modules.paths.generator.component-class.path', 'View/Components/newDirectory'); $code = $this->artisan('module:make-component', ['name' => 'Blog', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/View/Component/newDirectory/Blog.php'); + $file = $this->finder->get($this->getModuleBasePath().'/View/Components/newDirectory/Blog.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/ComponentViewMakeCommandTest.php b/tests/Commands/Make/ComponentViewMakeCommandTest.php similarity index 65% rename from tests/Commands/ComponentViewMakeCommandTest.php rename to tests/Commands/Make/ComponentViewMakeCommandTest.php index 9000343f9..b7aaddde6 100644 --- a/tests/Commands/ComponentViewMakeCommandTest.php +++ b/tests/Commands/Make/ComponentViewMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -32,30 +34,28 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_the_component_view() + public function test_it_generates_the_component_view() { $code = $this->artisan('module:make-component-view', ['name' => 'Blog', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Resources/views/components/blog.blade.php')); + $this->assertTrue(is_file($this->getModuleBasePath().'/resources/views/components/blog.blade.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + + public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-component-view', ['name' => 'Blog', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Resources/views/components/blog.blade.php'); + $file = $this->finder->get($this->getModuleBasePath().'/resources/views/components/blog.blade.php'); $this->assertTrue(str_contains($file, '
')); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.component-view.path', 'Resources/views/components/newDirectory'); $code = $this->artisan('module:make-component-view', ['name' => 'Blog', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Resources/views/components/newDirectory/blog.blade.php'); + $file = $this->finder->get($this->getModuleBasePath().'/Resources/views/components/newDirectory/blog.blade.php'); $this->assertTrue(str_contains($file, '
')); $this->assertSame(0, $code); diff --git a/tests/Commands/ControllerMakeCommandTest.php b/tests/Commands/Make/ControllerMakeCommandTest.php similarity index 56% rename from tests/Commands/ControllerMakeCommandTest.php rename to tests/Commands/Make/ControllerMakeCommandTest.php index 13d8b973c..860ac6536 100644 --- a/tests/Commands/ControllerMakeCommandTest.php +++ b/tests/Commands/Make/ControllerMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + } public function tearDown(): void @@ -32,48 +35,43 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_a_new_controller_class() + public function test_it_generates_a_new_controller_class() { $code = $this->artisan('module:make-controller', ['controller' => 'MyController', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Http/Controllers/MyController.php')); + $this->assertTrue(is_file($this->modulePath.'/Http/Controllers/MyController.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-controller', ['controller' => 'MyController', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Http/Controllers/MyController.php'); + $file = $this->finder->get($this->modulePath.'/Http/Controllers/MyController.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_appends_controller_to_name_if_not_present() + public function test_it_appends_controller_to_name_if_not_present() { $code = $this->artisan('module:make-controller', ['controller' => 'My', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Http/Controllers/MyController.php')); + $this->assertTrue(is_file($this->modulePath.'/Http/Controllers/MyController.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_appends_controller_to_class_name_if_not_present() + public function test_it_appends_controller_to_class_name_if_not_present() { $code = $this->artisan('module:make-controller', ['controller' => 'My', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Http/Controllers/MyController.php'); + $file = $this->finder->get($this->modulePath.'/Http/Controllers/MyController.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_a_plain_controller() + public function test_it_generates_a_plain_controller() { $code = $this->artisan('module:make-controller', [ 'controller' => 'MyController', @@ -81,14 +79,13 @@ public function it_generates_a_plain_controller() '--plain' => true, ]); - $file = $this->finder->get($this->modulePath . '/Http/Controllers/MyController.php'); + $file = $this->finder->get($this->modulePath.'/Http/Controllers/MyController.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_an_api_controller() + public function test_it_generates_an_api_controller() { $code = $this->artisan('module:make-controller', [ 'controller' => 'MyController', @@ -96,53 +93,63 @@ public function it_generates_an_api_controller() '--api' => true, ]); - $file = $this->finder->get($this->modulePath . '/Http/Controllers/MyController.php'); + $file = $this->finder->get($this->modulePath.'/Http/Controllers/MyController.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_generates_an_invokable_controller() + { + $code = $this->artisan('module:make-controller', [ + 'controller' => 'MyController', + 'module' => 'Blog', + '--invokable' => true, + ]); + + $file = $this->finder->get($this->modulePath.'/Http/Controllers/MyController.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.controller.path', 'Controllers'); $code = $this->artisan('module:make-controller', ['controller' => 'MyController', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Controllers/MyController.php'); + $file = $this->finder->get($this->getModuleBasePath().'/Controllers/MyController.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.controller.namespace', 'Controllers'); $code = $this->artisan('module:make-controller', ['controller' => 'MyController', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Http/Controllers/MyController.php'); + $file = $this->finder->get($this->modulePath.'/Http/Controllers/MyController.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_generate_a_controller_in_sub_namespace_in_correct_folder() + public function test_it_can_generate_a_controller_in_sub_namespace_in_correct_folder() { $code = $this->artisan('module:make-controller', ['controller' => 'Api\\MyController', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Http/Controllers/Api/MyController.php')); + $this->assertTrue(is_file($this->modulePath.'/Http/Controllers/Api/MyController.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_can_generate_a_controller_in_sub_namespace_with_correct_generated_file() + public function test_it_can_generate_a_controller_in_sub_namespace_with_correct_generated_file() { $code = $this->artisan('module:make-controller', ['controller' => 'Api\\MyController', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Http/Controllers/Api/MyController.php'); + $file = $this->finder->get($this->modulePath.'/Http/Controllers/Api/MyController.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/EnumMakeCommandTest.php b/tests/Commands/Make/EnumMakeCommandTest.php new file mode 100644 index 000000000..1cb65afcf --- /dev/null +++ b/tests/Commands/Make/EnumMakeCommandTest.php @@ -0,0 +1,82 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_a_new_enum_class() + { + $code = $this->artisan('module:make-enum', ['name' => 'MyEnum', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Enums/MyEnum.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_enum_class_can_override_with_force_option() + { + $this->artisan('module:make-enum', ['name' => 'MyEnum', 'module' => 'Blog']); + $code = $this->artisan('module:make-enum', ['name' => 'MyEnum', 'module' => 'Blog', '--force' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Enums/MyEnum.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-enum', ['name' => 'MyEnum', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Enums/MyEnum.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_enum_in_sub_namespace_in_correct_folder() + { + $code = $this->artisan('module:make-enum', ['name' => 'Api\\MyEnum', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Enums/Api/MyEnum.php')); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_enum_in_sub_namespace_with_correct_generated_file() + { + $code = $this->artisan('module:make-enum', ['name' => 'Api\\MyEnum', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Enums/Api/MyEnum.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/EventMakeCommandTest.php b/tests/Commands/Make/EventMakeCommandTest.php similarity index 65% rename from tests/Commands/EventMakeCommandTest.php rename to tests/Commands/Make/EventMakeCommandTest.php index 906c27313..bbd2f63d2 100644 --- a/tests/Commands/EventMakeCommandTest.php +++ b/tests/Commands/Make/EventMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -33,47 +34,43 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_a_new_event_class() + public function test_it_generates_a_new_event_class() { $code = $this->artisan('module:make-event', ['name' => 'PostWasCreated', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Events/PostWasCreated.php')); + $this->assertTrue(is_file($this->modulePath.'/Events/PostWasCreated.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-event', ['name' => 'PostWasCreated', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Events/PostWasCreated.php'); + $file = $this->finder->get($this->modulePath.'/Events/PostWasCreated.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.event.path', 'SuperEvents'); $code = $this->artisan('module:make-event', ['name' => 'PostWasCreated', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/SuperEvents/PostWasCreated.php'); + $file = $this->finder->get($this->getModuleBasePath().'/SuperEvents/PostWasCreated.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.event.namespace', 'SuperEvents'); $code = $this->artisan('module:make-event', ['name' => 'PostWasCreated', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Events/PostWasCreated.php'); + $file = $this->finder->get($this->modulePath.'/Events/PostWasCreated.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/EventProviderMakeCommandTest.php b/tests/Commands/Make/EventProviderMakeCommandTest.php new file mode 100644 index 000000000..6b7e87527 --- /dev/null +++ b/tests/Commands/Make/EventProviderMakeCommandTest.php @@ -0,0 +1,64 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_a_new_event_provider_class() + { + $code = $this->artisan('module:make-event-provider', ['module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Providers/EventServiceProvider.php')); + $this->assertSame(1, $code); + } + + public function test_it_generates_a_new_event_provider_class_can_override_with_force_option() + { + $this->artisan('module:make-event-provider', ['module' => 'Blog']); + $code = $this->artisan('module:make-event-provider', ['module' => 'Blog', '--force' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Providers/EventServiceProvider.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-event-provider', ['module' => 'Blog', '--force' => true]); + + $file = $this->finder->get($this->modulePath.'/Providers/EventServiceProvider.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/Make/ExceptionMakeCommandTest.php b/tests/Commands/Make/ExceptionMakeCommandTest.php new file mode 100644 index 000000000..0b8694e09 --- /dev/null +++ b/tests/Commands/Make/ExceptionMakeCommandTest.php @@ -0,0 +1,106 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_a_new_exception_class() + { + $code = $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Exceptions/MyException.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_exception_class_can_override_with_force_option() + { + $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog']); + $code = $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog', '--force' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Exceptions/MyException.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_exception_class_can_use_render_option() + { + $code = $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog', '--render' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Exceptions/MyException.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_exception_class_can_use_report_option() + { + $code = $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog', '--report' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Exceptions/MyException.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_exception_class_can_use_report_and_render_option() + { + $code = $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog', '--report' => true, '--render' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Exceptions/MyException.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-exception', ['name' => 'MyException', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Exceptions/MyException.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_exception_in_sub_namespace_in_correct_folder() + { + $code = $this->artisan('module:make-exception', ['name' => 'Api\\MyException', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Exceptions/Api/MyException.php')); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_exception_in_sub_namespace_with_correct_generated_file() + { + $code = $this->artisan('module:make-exception', ['name' => 'Api\\MyException', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Exceptions/Api/MyException.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/FactoryMakeCommandTest.php b/tests/Commands/Make/FactoryMakeCommandTest.php similarity index 75% rename from tests/Commands/FactoryMakeCommandTest.php rename to tests/Commands/Make/FactoryMakeCommandTest.php index caf39f153..6cafbf5a1 100644 --- a/tests/Commands/FactoryMakeCommandTest.php +++ b/tests/Commands/Make/FactoryMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -32,12 +34,11 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_makes_factory() + public function test_it_makes_factory() { $code = $this->artisan('module:make-factory', ['name' => 'Post', 'module' => 'Blog']); - $factoryFile = $this->modulePath . '/Database/factories/PostFactory.php'; + $factoryFile = $this->getModuleBasePath().'/database/factories/PostFactory.php'; $this->assertTrue(is_file($factoryFile), 'Factory file was not created.'); $this->assertMatchesSnapshot($this->finder->get($factoryFile)); diff --git a/tests/Commands/Make/HelperMakeCommandTest.php b/tests/Commands/Make/HelperMakeCommandTest.php new file mode 100644 index 000000000..aaa28f66c --- /dev/null +++ b/tests/Commands/Make/HelperMakeCommandTest.php @@ -0,0 +1,90 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_a_new_helper_class() + { + $code = $this->artisan('module:make-helper', ['name' => 'MyHelper', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Helpers/MyHelper.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_helper_class_can_override_with_force_option() + { + $this->artisan('module:make-helper', ['name' => 'MyHelper', 'module' => 'Blog']); + $code = $this->artisan('module:make-helper', ['name' => 'MyHelper', 'module' => 'Blog', '--force' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Helpers/MyHelper.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_helper_class_can_use_invoke_option() + { + $code = $this->artisan('module:make-helper', ['name' => 'MyHelper', 'module' => 'Blog', '--invokable' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Helpers/MyHelper.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-helper', ['name' => 'MyHelper', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Helpers/MyHelper.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_helper_in_sub_namespace_in_correct_folder() + { + $code = $this->artisan('module:make-helper', ['name' => 'Api\\MyHelper', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Helpers/Api/MyHelper.php')); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_helper_in_sub_namespace_with_correct_generated_file() + { + $code = $this->artisan('module:make-helper', ['name' => 'Api\\MyHelper', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Helpers/Api/MyHelper.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/Make/InterfaceMakeCommandTest.php b/tests/Commands/Make/InterfaceMakeCommandTest.php new file mode 100644 index 000000000..c913baa56 --- /dev/null +++ b/tests/Commands/Make/InterfaceMakeCommandTest.php @@ -0,0 +1,82 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_a_new_interface_class() + { + $code = $this->artisan('module:make-interface', ['name' => 'MyInterface', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Interfaces/MyInterface.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_interface_class_can_override_with_force_option() + { + $this->artisan('module:make-interface', ['name' => 'MyInterface', 'module' => 'Blog']); + $code = $this->artisan('module:make-interface', ['name' => 'MyInterface', 'module' => 'Blog', '--force' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Interfaces/MyInterface.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-interface', ['name' => 'MyInterface', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Interfaces/MyInterface.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_interface_in_sub_namespace_in_correct_folder() + { + $code = $this->artisan('module:make-interface', ['name' => 'Api\\MyInterface', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Interfaces/Api/MyInterface.php')); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_interface_in_sub_namespace_with_correct_generated_file() + { + $code = $this->artisan('module:make-interface', ['name' => 'Api\\MyInterface', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Interfaces/Api/MyInterface.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/JobMakeCommandTest.php b/tests/Commands/Make/JobMakeCommandTest.php similarity index 64% rename from tests/Commands/JobMakeCommandTest.php rename to tests/Commands/Make/JobMakeCommandTest.php index 30a044582..3ce343299 100644 --- a/tests/Commands/JobMakeCommandTest.php +++ b/tests/Commands/Make/JobMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -32,58 +34,53 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_the_job_class() + public function test_it_generates_the_job_class() { $code = $this->artisan('module:make-job', ['name' => 'SomeJob', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Jobs/SomeJob.php')); + $this->assertTrue(is_file($this->modulePath.'/Jobs/SomeJob.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-job', ['name' => 'SomeJob', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Jobs/SomeJob.php'); + $file = $this->finder->get($this->modulePath.'/Jobs/SomeJob.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_sync_job_file_with_content() + public function test_it_generated_correct_sync_job_file_with_content() { $code = $this->artisan('module:make-job', ['name' => 'SomeJob', 'module' => 'Blog', '--sync' => true]); - $file = $this->finder->get($this->modulePath . '/Jobs/SomeJob.php'); + $file = $this->finder->get($this->modulePath.'/Jobs/SomeJob.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.jobs.path', 'SuperJobs'); $code = $this->artisan('module:make-job', ['name' => 'SomeJob', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/SuperJobs/SomeJob.php'); + $file = $this->finder->get($this->getModuleBasePath().'/SuperJobs/SomeJob.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.jobs.namespace', 'SuperJobs'); $code = $this->artisan('module:make-job', ['name' => 'SomeJob', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Jobs/SomeJob.php'); + $file = $this->finder->get($this->modulePath.'/Jobs/SomeJob.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/ListenerMakeCommandTest.php b/tests/Commands/Make/ListenerMakeCommandTest.php similarity index 64% rename from tests/Commands/ListenerMakeCommandTest.php rename to tests/Commands/Make/ListenerMakeCommandTest.php index 6815a5067..13e706d7a 100644 --- a/tests/Commands/ListenerMakeCommandTest.php +++ b/tests/Commands/Make/ListenerMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -33,104 +34,96 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_a_new_event_class() + public function test_it_generates_a_new_event_class() { $code = $this->artisan( 'module:make-listener', ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog', '--event' => 'UserWasCreated'] ); - $this->assertTrue(is_file($this->modulePath . '/Listeners/NotifyUsersOfANewPost.php')); + $this->assertTrue(is_file($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_sync_event_with_content() + public function test_it_generated_correct_sync_event_with_content() { $code = $this->artisan( 'module:make-listener', ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog', '--event' => 'UserWasCreated'] ); - $file = $this->finder->get($this->modulePath . '/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_sync_event_in_a_subdirectory_with_content() + public function test_it_generated_correct_sync_event_in_a_subdirectory_with_content() { $code = $this->artisan( 'module:make-listener', ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog', '--event' => 'User/WasCreated'] ); - $file = $this->finder->get($this->modulePath . '/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_sync_duck_event_with_content() + public function test_it_generated_correct_sync_duck_event_with_content() { $code = $this->artisan( 'module:make-listener', ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog'] ); - $file = $this->finder->get($this->modulePath . '/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_queued_event_with_content() + public function test_it_generated_correct_queued_event_with_content() { $code = $this->artisan( 'module:make-listener', ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog', '--event' => 'UserWasCreated', '--queued' => true] ); - $file = $this->finder->get($this->modulePath . '/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_queued_event_in_a_subdirectory_with_content() + public function test_it_generated_correct_queued_event_in_a_subdirectory_with_content() { $code = $this->artisan( 'module:make-listener', ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog', '--event' => 'User/WasCreated', '--queued' => true] ); - $file = $this->finder->get($this->modulePath . '/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_queued_duck_event_with_content() + public function test_it_generated_correct_queued_duck_event_with_content() { $code = $this->artisan( 'module:make-listener', ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog', '--queued' => true] ); - $file = $this->finder->get($this->modulePath . '/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.listener.path', 'Events/Handlers'); @@ -139,14 +132,13 @@ public function it_can_change_the_default_namespace() ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog'] ); - $file = $this->finder->get($this->modulePath . '/Events/Handlers/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->getModuleBasePath().'/Events/Handlers/NotifyUsersOfANewPost.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.listener.namespace', 'Events\\Handlers'); @@ -155,7 +147,7 @@ public function it_can_change_the_default_namespace_specific() ['name' => 'NotifyUsersOfANewPost', 'module' => 'Blog'] ); - $file = $this->finder->get($this->modulePath . '/Listeners/NotifyUsersOfANewPost.php'); + $file = $this->finder->get($this->modulePath.'/Listeners/NotifyUsersOfANewPost.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/MailMakeCommandTest.php b/tests/Commands/Make/MailMakeCommandTest.php similarity index 66% rename from tests/Commands/MailMakeCommandTest.php rename to tests/Commands/Make/MailMakeCommandTest.php index e88697adb..a90f5e67f 100644 --- a/tests/Commands/MailMakeCommandTest.php +++ b/tests/Commands/Make/MailMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -32,47 +34,43 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_the_mail_class() + public function test_it_generates_the_mail_class() { $code = $this->artisan('module:make-mail', ['name' => 'SomeMail', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Emails/SomeMail.php')); + $this->assertTrue(is_file($this->modulePath.'/Emails/SomeMail.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-mail', ['name' => 'SomeMail', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Emails/SomeMail.php'); + $file = $this->finder->get($this->modulePath.'/Emails/SomeMail.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.emails.path', 'SuperEmails'); $code = $this->artisan('module:make-mail', ['name' => 'SomeMail', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/SuperEmails/SomeMail.php'); + $file = $this->finder->get($this->getModuleBasePath().'/SuperEmails/SomeMail.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.emails.namespace', 'SuperEmails'); $code = $this->artisan('module:make-mail', ['name' => 'SomeMail', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Emails/SomeMail.php'); + $file = $this->finder->get($this->modulePath.'/Emails/SomeMail.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/MiddlewareMakeCommandTest.php b/tests/Commands/Make/MiddlewareMakeCommandTest.php similarity index 65% rename from tests/Commands/MiddlewareMakeCommandTest.php rename to tests/Commands/Make/MiddlewareMakeCommandTest.php index 157d6e5ae..452901f6f 100644 --- a/tests/Commands/MiddlewareMakeCommandTest.php +++ b/tests/Commands/Make/MiddlewareMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -32,47 +34,43 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_a_new_middleware_class() + public function test_it_generates_a_new_middleware_class() { $code = $this->artisan('module:make-middleware', ['name' => 'SomeMiddleware', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Http/Middleware/SomeMiddleware.php')); + $this->assertTrue(is_file($this->modulePath.'/Http/Middleware/SomeMiddleware.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-middleware', ['name' => 'SomeMiddleware', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Http/Middleware/SomeMiddleware.php'); + $file = $this->finder->get($this->modulePath.'/Http/Middleware/SomeMiddleware.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.filter.path', 'Middleware'); $code = $this->artisan('module:make-middleware', ['name' => 'SomeMiddleware', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Middleware/SomeMiddleware.php'); + $file = $this->finder->get($this->getModuleBasePath().'/Middleware/SomeMiddleware.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.filter.namespace', 'Middleware'); $code = $this->artisan('module:make-middleware', ['name' => 'SomeMiddleware', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Http/Middleware/SomeMiddleware.php'); + $file = $this->finder->get($this->modulePath.'/Http/Middleware/SomeMiddleware.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/MigrationMakeCommandTest.php b/tests/Commands/Make/MigrationMakeCommandTest.php similarity index 56% rename from tests/Commands/MigrationMakeCommandTest.php rename to tests/Commands/Make/MigrationMakeCommandTest.php index 483240436..5158b5474 100644 --- a/tests/Commands/MigrationMakeCommandTest.php +++ b/tests/Commands/Make/MigrationMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleBasePath(); } public function tearDown(): void @@ -32,90 +34,83 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_a_new_migration_class() + public function test_it_generates_a_new_migration_class() { $code = $this->artisan('module:make-migration', ['name' => 'create_posts_table', 'module' => 'Blog']); - $files = $this->finder->allFiles($this->modulePath . '/Database/Migrations'); + $files = $this->finder->allFiles($this->modulePath.'/database/migrations'); $this->assertCount(1, $files); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_correct_create_migration_file_content() + public function test_it_generates_correct_create_migration_file_content() { $code = $this->artisan('module:make-migration', ['name' => 'create_posts_table', 'module' => 'Blog']); - $migrations = $this->finder->allFiles($this->modulePath . '/Database/Migrations'); + $migrations = $this->finder->allFiles($this->modulePath.'/database/migrations'); $fileName = $migrations[0]->getRelativePathname(); - $file = $this->finder->get($this->modulePath . '/Database/Migrations/' . $fileName); + $file = $this->finder->get($this->modulePath.'/database/migrations/'.$fileName); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_correct_add_migration_file_content() + public function test_it_generates_correct_add_migration_file_content() { $code = $this->artisan('module:make-migration', ['name' => 'add_something_to_posts_table', 'module' => 'Blog']); - $migrations = $this->finder->allFiles($this->modulePath . '/Database/Migrations'); + $migrations = $this->finder->allFiles($this->modulePath.'/database/migrations'); $fileName = $migrations[0]->getRelativePathname(); - $file = $this->finder->get($this->modulePath . '/Database/Migrations/' . $fileName); + $file = $this->finder->get($this->modulePath.'/database/migrations/'.$fileName); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_correct_delete_migration_file_content() + public function test_it_generates_correct_delete_migration_file_content() { $code = $this->artisan('module:make-migration', ['name' => 'delete_something_from_posts_table', 'module' => 'Blog']); - $migrations = $this->finder->allFiles($this->modulePath . '/Database/Migrations'); + $migrations = $this->finder->allFiles($this->modulePath.'/database/migrations'); $fileName = $migrations[0]->getRelativePathname(); - $file = $this->finder->get($this->modulePath . '/Database/Migrations/' . $fileName); + $file = $this->finder->get($this->modulePath.'/database/migrations/'.$fileName); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_correct_drop_migration_file_content() + public function test_it_generates_correct_drop_migration_file_content() { $code = $this->artisan('module:make-migration', ['name' => 'drop_posts_table', 'module' => 'Blog']); - $migrations = $this->finder->allFiles($this->modulePath . '/Database/Migrations'); + $migrations = $this->finder->allFiles($this->modulePath.'/database/migrations'); $fileName = $migrations[0]->getRelativePathname(); - $file = $this->finder->get($this->modulePath . '/Database/Migrations/' . $fileName); + $file = $this->finder->get($this->modulePath.'/database/migrations/'.$fileName); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_correct_default_migration_file_content() + public function test_it_generates_correct_default_migration_file_content() { $code = $this->artisan('module:make-migration', ['name' => 'something_random_name', 'module' => 'Blog']); - $migrations = $this->finder->allFiles($this->modulePath . '/Database/Migrations'); + $migrations = $this->finder->allFiles($this->modulePath.'/database/migrations'); $fileName = $migrations[0]->getRelativePathname(); - $file = $this->finder->get($this->modulePath . '/Database/Migrations/' . $fileName); + $file = $this->finder->get($this->modulePath.'/database/migrations/'.$fileName); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_foreign_key_constraints() + public function test_it_generates_foreign_key_constraints() { $code = $this->artisan('module:make-migration', ['name' => 'create_posts_table', 'module' => 'Blog', '--fields' => 'belongsTo:user:id:users']); - $migrations = $this->finder->allFiles($this->modulePath . '/Database/Migrations'); + $migrations = $this->finder->allFiles($this->modulePath.'/database/migrations'); $fileName = $migrations[0]->getRelativePathname(); - $file = $this->finder->get($this->modulePath . '/Database/Migrations/' . $fileName); + $file = $this->finder->get($this->modulePath.'/database/migrations/'.$fileName); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/ModelMakeCommandTest.php b/tests/Commands/Make/ModelMakeCommandTest.php similarity index 62% rename from tests/Commands/ModelMakeCommandTest.php rename to tests/Commands/Make/ModelMakeCommandTest.php index b4dd59ff7..65eb8fde4 100644 --- a/tests/Commands/ModelMakeCommandTest.php +++ b/tests/Commands/Make/ModelMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -33,124 +35,114 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_a_new_model_class() + public function test_it_generates_a_new_model_class() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Entities/Post.php')); + $this->assertTrue(is_file($this->modulePath.'/Models/Post.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Entities/Post.php'); + $file = $this->finder->get($this->modulePath.'/Models/Post.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_correct_fillable_fields() + public function test_it_generates_correct_fillable_fields() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '--fillable' => 'title,slug']); - $file = $this->finder->get($this->modulePath . '/Entities/Post.php'); + $file = $this->finder->get($this->modulePath.'/Models/Post.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_migration_file_with_model() + public function test_it_generates_migration_file_with_model() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '--migration' => true]); - $migrations = $this->finder->allFiles($this->modulePath . '/Database/Migrations'); + $migrations = $this->finder->allFiles($this->getModuleBasePath().'/database/migrations'); $migrationFile = $migrations[0]; - $migrationContent = $this->finder->get($this->modulePath . '/Database/Migrations/' . $migrationFile->getFilename()); + $migrationContent = $this->finder->get($this->getModuleBasePath().'/database/migrations/'.$migrationFile->getFilename()); $this->assertCount(1, $migrations); $this->assertMatchesSnapshot($migrationContent); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_migration_file_with_model_using_shortcut_option() + public function test_it_generates_migration_file_with_model_using_shortcut_option() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '-m' => true]); - $migrations = $this->finder->allFiles($this->modulePath . '/Database/Migrations'); + $migrations = $this->finder->allFiles($this->getModuleBasePath().'/database/migrations'); $migrationFile = $migrations[0]; - $migrationContent = $this->finder->get($this->modulePath . '/Database/Migrations/' . $migrationFile->getFilename()); + $migrationContent = $this->finder->get($this->getModuleBasePath().'/database/migrations/'.$migrationFile->getFilename()); $this->assertCount(1, $migrations); $this->assertMatchesSnapshot($migrationContent); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_controller_file_with_model() + public function test_it_generates_controller_file_with_model() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '--controller' => true]); - $controllers = $this->finder->allFiles($this->modulePath . '/Http/Controllers'); + $controllers = $this->finder->allFiles($this->modulePath.'/Http/Controllers'); $controllerFile = $controllers[1]; - $controllerContent = $this->finder->get($this->modulePath . '/Http/Controllers/' . $controllerFile->getFilename()); + $controllerContent = $this->finder->get($this->modulePath.'/Http/Controllers/'.$controllerFile->getFilename()); $this->assertCount(2, $controllers); $this->assertMatchesSnapshot($controllerContent); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_controller_file_with_model_using_shortcut_option() + public function test_it_generates_controller_file_with_model_using_shortcut_option() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '-c' => true]); - $controllers = $this->finder->allFiles($this->modulePath . '/Http/Controllers'); + $controllers = $this->finder->allFiles($this->modulePath.'/Http/Controllers'); $controllerFile = $controllers[1]; - $controllerContent = $this->finder->get($this->modulePath . '/Http/Controllers/' . $controllerFile->getFilename()); + $controllerContent = $this->finder->get($this->modulePath.'/Http/Controllers/'.$controllerFile->getFilename()); $this->assertCount(2, $controllers); $this->assertMatchesSnapshot($controllerContent); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_controller_and_migration_when_both_flags_are_present() + public function test_it_generates_controller_and_migration_when_both_flags_are_present() { $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog', '-c' => true, '-m' => true]); - $controllers = $this->finder->allFiles($this->modulePath . '/Http/Controllers'); + $controllers = $this->finder->allFiles($this->modulePath.'/Http/Controllers'); $controllerFile = $controllers[1]; - $controllerContent = $this->finder->get($this->modulePath . '/Http/Controllers/' . $controllerFile->getFilename()); + $controllerContent = $this->finder->get($this->modulePath.'/Http/Controllers/'.$controllerFile->getFilename()); $this->assertCount(2, $controllers); $this->assertMatchesSnapshot($controllerContent); - $migrations = $this->finder->allFiles($this->modulePath . '/Database/Migrations'); + $migrations = $this->finder->allFiles($this->getModuleBasePath().'/database/migrations'); $migrationFile = $migrations[0]; - $migrationContent = $this->finder->get($this->modulePath . '/Database/Migrations/' . $migrationFile->getFilename()); + $migrationContent = $this->finder->get($this->getModuleBasePath().'/database/migrations/'.$migrationFile->getFilename()); $this->assertCount(1, $migrations); $this->assertMatchesSnapshot($migrationContent); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_correct_migration_file_name_with_multiple_words_model() + public function test_it_generates_correct_migration_file_name_with_multiple_words_model() { $code = $this->artisan('module:make-model', ['model' => 'ProductDetail', 'module' => 'Blog', '-m' => true]); - $migrations = $this->finder->allFiles($this->modulePath . '/Database/Migrations'); + $migrations = $this->finder->allFiles($this->getModuleBasePath().'/database/migrations'); $migrationFile = $migrations[0]; - $migrationContent = $this->finder->get($this->modulePath . '/Database/Migrations/' . $migrationFile->getFilename()); + $migrationContent = $this->finder->get($this->getModuleBasePath().'/database/migrations/'.$migrationFile->getFilename()); $this->assertStringContainsString('create_product_details_table', $migrationFile->getFilename()); $this->assertMatchesSnapshot($migrationContent); $this->assertSame(0, $code); } - /** @test */ - public function it_displays_error_if_model_already_exists() + public function test_it_displays_error_if_model_already_exists() { $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog']); $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog']); @@ -159,27 +151,25 @@ public function it_displays_error_if_model_already_exists() $this->assertSame(E_ERROR, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.model.path', 'Models'); $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Models/Post.php'); + $file = $this->finder->get($this->getModuleBasePath().'/Models/Post.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.model.namespace', 'Models'); $code = $this->artisan('module:make-model', ['model' => 'Post', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Entities/Post.php'); + $file = $this->finder->get($this->modulePath.'/Models/Post.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ModuleMakeCommandTest.php b/tests/Commands/Make/ModuleMakeCommandTest.php new file mode 100644 index 000000000..6a1a1e811 --- /dev/null +++ b/tests/Commands/Make/ModuleMakeCommandTest.php @@ -0,0 +1,531 @@ +modulePath = $this->getModuleBasePath(); + $this->finder = $this->app['files']; + $this->repository = $this->app[RepositoryInterface::class]; + $this->activator = $this->app[ActivatorInterface::class]; + } + + public function tearDown(): void + { + $this->artisan('module:delete', ['--all' => true, '--force' => true]); + + $this->activator->reset(); + parent::tearDown(); + } + + public function test_it_generates_module() + { + $code = $this->artisan('module:make', ['name' => ['Blog']]); + + $this->assertDirectoryExists($this->modulePath); + $this->assertSame(0, $code); + } + + public function test_it_generates_module_folders() + { + $code = $this->artisan('module:make', ['name' => ['Blog']]); + + foreach (config('modules.paths.generator') as $directory) { + $this->assertDirectoryExists($this->modulePath.'/'.$directory['path']); + } + $this->assertSame(0, $code); + } + + public function test_it_generates_module_files() + { + $code = $this->artisan('module:make', ['name' => ['Blog']]); + + foreach (config('modules.stubs.files') as $file) { + $path = base_path('modules/Blog').'/'.$file; + $this->assertTrue($this->finder->exists($path), "[$file] does not exists"); + } + $path = base_path('modules/Blog').'/module.json'; + $this->assertTrue($this->finder->exists($path), '[module.json] does not exists'); + $this->assertMatchesSnapshot($this->finder->get($path)); + $this->assertSame(0, $code); + } + + public function test_it_generates_web_route_file() + { + $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'); + $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']]); + + $path = $this->modulePath.'/'.$this->app['modules']->config('stubs.files.vite'); + + $this->assertMatchesSnapshot($this->finder->get($path)); + $this->assertSame(0, $code); + } + + public function test_it_generates_module_resources() + { + $code = $this->artisan('module:make', ['name' => ['Blog']]); + + $path = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $path = $this->getModuleAppPath().'/Providers/EventServiceProvider.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $path = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $path = $this->getModuleAppPath().'/Http/Controllers/BlogController.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $path = $this->getModuleBasePath().'/database/seeders/BlogDatabaseSeeder.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $this->assertSame(0, $code); + } + + public function test_it_generates_correct_composerjson_file() + { + $code = $this->artisan('module:make', ['name' => ['Blog']]); + + $file = $this->finder->get($this->modulePath.'/composer.json'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_generates_module_folder_using_studly_case() + { + $code = $this->artisan('module:make', ['name' => ['ModuleName']]); + + $this->assertTrue($this->finder->exists(base_path('modules/ModuleName'))); + $this->assertSame(0, $code); + } + + public function test_it_generates_module_namespace_using_studly_case() + { + $code = $this->artisan('module:make', ['name' => ['ModuleName']]); + + $file = $this->finder->get($this->getModuleAppPath('ModuleName').'/Providers/ModuleNameServiceProvider.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_plain_module_with_no_resources() + { + $code = $this->artisan('module:make', ['name' => ['ModuleName'], '--plain' => true]); + + $path = base_path('modules/ModuleName').'/Providers/ModuleNameServiceProvider.php'; + $this->assertFalse($this->finder->exists($path)); + + $path = base_path('modules/ModuleName').'/Http/Controllers/ModuleNameController.php'; + $this->assertFalse($this->finder->exists($path)); + + $path = base_path('modules/ModuleName').'/Database/Seeders/ModuleNameDatabaseSeeder.php'; + $this->assertFalse($this->finder->exists($path)); + + $this->assertSame(0, $code); + } + + public function test_it_generates_a_plain_module_with_no_files() + { + $code = $this->artisan('module:make', ['name' => ['ModuleName'], '--plain' => true]); + + foreach (config('modules.stubs.files') as $file) { + $path = base_path('modules/ModuleName').'/'.$file; + $this->assertFalse($this->finder->exists($path), "[$file] exists"); + } + $path = base_path('modules/ModuleName').'/module.json'; + $this->assertTrue($this->finder->exists($path), '[module.json] does not exists'); + $this->assertSame(0, $code); + } + + public function test_it_generates_plain_module_with_no_service_provider_in_modulejson_file() + { + $code = $this->artisan('module:make', ['name' => ['ModuleName'], '--plain' => true]); + + $path = base_path('modules/ModuleName').'/module.json'; + $content = json_decode($this->finder->get($path)); + + $this->assertCount(0, $content->providers); + $this->assertSame(0, $code); + } + + public function test_it_outputs_error_when_module_exists() + { + $this->artisan('module:make', ['name' => ['Blog']]); + $code = $this->artisan('module:make', ['name' => ['Blog']]); + + $output = Artisan::output(); + $expected = 'ERROR Module [Blog] already exists!'; + + $this->assertTrue(Str::contains($output, $expected)); + + $this->assertSame(E_ERROR, $code); + } + + public function test_it_still_generates_module_if_it_exists_using_force_flag() + { + Event::fake(); + + $this->artisan('module:make', ['name' => ['Blog']]); + $code = $this->artisan('module:make', ['name' => ['Blog'], '--force' => true]); + $this->assertSame(0, $code); + + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::DELETING, strtolower('Blog'))); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::DELETED, strtolower('Blog'))); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::CREATED, strtolower('Blog'))); + } + + public function test_it_can_generate_module_with_old_config_format() + { + $this->app['config']->set('modules.paths.generator', [ + 'assets' => 'Assets', + 'config' => 'Config', + 'command' => 'Console', + 'event' => 'Events', + 'listener' => 'Listeners', + 'migration' => 'Database/Migrations', + 'factory' => 'Database/factories', + 'model' => 'Entities', + 'repository' => 'Repositories', + 'seeder' => 'Database/Seeders', + 'controller' => 'Http/Controllers', + 'filter' => 'Http/Middleware', + 'request' => 'Http/Requests', + 'provider' => 'Providers', + 'lang' => 'Resources/lang', + 'views' => 'Resources/views', + 'policies' => false, + 'rules' => false, + 'test' => 'Tests', + 'jobs' => 'Jobs', + 'emails' => 'Emails', + 'notifications' => 'Notifications', + 'resource' => false, + ]); + + $code = $this->artisan('module:make', ['name' => ['Blog']]); + + $this->assertDirectoryExists($this->modulePath.'/Assets'); + $this->assertDirectoryExists($this->modulePath.'/Emails'); + $this->assertFileDoesNotExist($this->modulePath.'/Rules'); + $this->assertFileDoesNotExist($this->modulePath.'/Policies'); + $this->assertSame(0, $code); + } + + public function test_it_can_ignore_some_folders_to_generate_with_old_format() + { + $this->app['config']->set('modules.paths.generator.assets', false); + $this->app['config']->set('modules.paths.generator.emails', false); + + $code = $this->artisan('module:make', ['name' => ['Blog']]); + + $this->assertFileDoesNotExist($this->modulePath.'/Assets'); + $this->assertFileDoesNotExist($this->modulePath.'/Emails'); + $this->assertSame(0, $code); + } + + public function test_it_can_ignore_some_folders_to_generate_with_new_format() + { + $this->app['config']->set('modules.paths.generator.assets', ['path' => 'Assets', 'generate' => false]); + $this->app['config']->set('modules.paths.generator.emails', ['path' => 'Emails', 'generate' => false]); + + $code = $this->artisan('module:make', ['name' => ['Blog']]); + + $this->assertFileDoesNotExist($this->modulePath.'/Assets'); + $this->assertFileDoesNotExist($this->modulePath.'/Emails'); + $this->assertSame(0, $code); + } + + public function test_it_can_ignore_resource_folders_to_generate() + { + $this->app['config']->set('modules.paths.generator.seeder', ['path' => 'Database/Seeders', 'generate' => false] + ); + $this->app['config']->set('modules.paths.generator.provider', ['path' => 'Providers', 'generate' => false]); + $this->app['config']->set('modules.paths.generator.route-provider', ['path' => 'Providers', 'generate' => false] + ); + $this->app['config']->set( + 'modules.paths.generator.controller', + ['path' => 'Http/Controllers', 'generate' => false] + ); + + $code = $this->artisan('module:make', ['name' => ['Blog']]); + + $this->assertFileDoesNotExist($this->modulePath.'/Database/Seeders'); + $this->assertFileDoesNotExist($this->modulePath.'/Providers'); + $this->assertFileDoesNotExist($this->modulePath.'/Http/Controllers'); + $this->assertSame(0, $code); + } + + public function test_it_generates_enabled_module() + { + $code = $this->artisan('module:make', ['name' => ['Blog']]); + + $this->assertTrue($this->repository->isEnabled('Blog')); + $this->assertSame(0, $code); + } + + public function test_it_generates_disabled_module_with_disabled_flag() + { + $code = $this->artisan('module:make', ['name' => ['Blog'], '--disabled' => true]); + + $this->assertTrue($this->repository->isDisabled('Blog')); + $this->assertSame(0, $code); + } + + public function test_it_generes_module_with_new_provider_location() + { + $this->app['config']->set('modules.paths.generator.provider', ['path' => 'Base/Providers', 'generate' => true]); + + $code = $this->artisan('module:make', ['name' => ['Blog']]); + + $this->assertDirectoryExists($this->modulePath.'/Base/Providers'); + $file = $this->finder->get($this->modulePath.'/module.json'); + $this->assertMatchesSnapshot($file); + $file = $this->finder->get($this->modulePath.'/composer.json'); + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_generates_web_module_with_resources() + { + $code = $this->artisan('module:make', ['name' => ['Blog'], '--web' => true]); + + $path = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $path = $this->getModuleAppPath().'/Http/Controllers/BlogController.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $path = $this->getModuleBasePath().'/database/seeders/BlogDatabaseSeeder.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $path = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $this->assertSame(0, $code); + } + + public function test_it_generates_api_module_with_resources() + { + $code = $this->artisan('module:make', ['name' => ['Blog'], '--api' => true]); + + $path = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $path = $this->getModuleAppPath().'/Http/Controllers/BlogController.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $path = $this->getModuleBasePath().'/database/seeders/BlogDatabaseSeeder.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $path = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $this->assertSame(0, $code); + } + + public function test_it_generates_web_module_with_resources_when_adding_more_than_one_option() + { + $code = $this->artisan('module:make', ['name' => ['Blog'], '--api' => true, '--plain' => true]); + + $path = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $path = $this->getModuleAppPath().'/Http/Controllers/BlogController.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $path = $this->getModuleBasePath().'/database/seeders/BlogDatabaseSeeder.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $path = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $this->assertTrue($this->finder->exists($path)); + $this->assertMatchesSnapshot($this->finder->get($path)); + + $this->assertSame(0, $code); + } + + public function test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable() + { + $this->app['config']->set('modules.paths.generator.provider.generate', true); + $this->app['config']->set('modules.paths.generator.route-provider.generate', true); + + $this->artisan('module:make', ['name' => ['Blog']]); + + $providerPath = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $this->assertTrue($this->finder->exists($providerPath)); + $this->assertMatchesSnapshot($this->finder->get($providerPath)); + + $RouteProviderPath = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $this->assertTrue($this->finder->exists($RouteProviderPath)); + $this->assertMatchesSnapshot($this->finder->get($RouteProviderPath)); + + $content = $this->finder->get($providerPath); + + $this->assertStringContainsString('$this->app->register(RouteServiceProvider::class);', $content); + $this->assertStringNotContainsString('// $this->app->register(RouteServiceProvider::class);', $content); + } + + public function test_it_generate_module_when_provider_is_enable_and_route_provider_is_disable() + { + $this->app['config']->set('modules.paths.generator.provider.generate', true); + $this->app['config']->set('modules.paths.generator.route-provider.generate', false); + + $this->artisan('module:make', ['name' => ['Blog']]); + + $providerPath = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $this->assertTrue($this->finder->exists($providerPath)); + $this->assertMatchesSnapshot($this->finder->get($providerPath)); + + $RouteProviderPath = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $this->assertTrue(! $this->finder->exists($RouteProviderPath)); + + $content = $this->finder->get($providerPath); + + $this->assertStringContainsString('// $this->app->register(RouteServiceProvider::class);', $content); + } + + public function test_it_generate_module_when_provider_is_disable_and_route_provider_is_disable() + { + $this->app['config']->set('modules.paths.generator.provider.generate', false); + $this->app['config']->set('modules.paths.generator.route-provider.generate', false); + + $this->artisan('module:make', ['name' => ['Blog']]); + + $providerPath = $this->getModuleAppPath().'/Providers/BlogServiceProvider.php'; + $this->assertTrue(! $this->finder->exists($providerPath)); + + $RouteProviderPath = $this->getModuleAppPath().'/Providers/RouteServiceProvider.php'; + $this->assertTrue(! $this->finder->exists($RouteProviderPath)); + + $content = $this->finder->get($this->getModuleBasePath().'/module.json'); + + $this->assertStringNotContainsString('Modules\Blog\Providers\BlogServiceProvider', $content); + } + + public function test_it_can_set_author_details() + { + $code = $this->artisan( + 'module:make', + [ + 'name' => ['Blog'], + '--author-name' => 'Joe Blogs', + '--author-email' => 'user@domain.com', + '--author-vendor' => 'JoeBlogs' + ] + ); + + $content = $this->finder->get($this->getModuleBasePath().'/composer.json'); + + $this->assertStringContainsString('Joe Blogs', $content); + $this->assertStringContainsString('user@domain.com', $content); + $this->assertStringContainsString('JoeBlogs', $content); + + $this->assertSame(0, $code); + } + + public function test_it_fires_events_when_module_created() + { + $module_name = 'Blog'; + Event::fake(); + + $code = $this->createModule($module_name); + + $this->assertSame(0, $code); + + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::CREATING, strtolower($module_name))); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::CREATED, strtolower($module_name))); + } + + public function test_it_fires_events_when_multi_module_created() + { + Event::fake(); + + $modules = [ + 'Foo', + 'Bar', + 'Zoo', + ]; + + $code = $this->artisan('module:make', ['name' => $modules]); + + $this->assertSame(0, $code); + + foreach ($modules as $module) { + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::CREATING, strtolower($module))); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::CREATED, strtolower($module))); + } + } +} diff --git a/tests/Commands/NotificationMakeCommandTest.php b/tests/Commands/Make/NotificationMakeCommandTest.php similarity index 65% rename from tests/Commands/NotificationMakeCommandTest.php rename to tests/Commands/Make/NotificationMakeCommandTest.php index a34e877ee..432f4c177 100644 --- a/tests/Commands/NotificationMakeCommandTest.php +++ b/tests/Commands/Make/NotificationMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -32,47 +34,43 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_the_mail_class() + public function test_it_generates_the_notification_class() { $code = $this->artisan('module:make-notification', ['name' => 'WelcomeNotification', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Notifications/WelcomeNotification.php')); + $this->assertTrue(is_file($this->modulePath.'/Notifications/WelcomeNotification.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-notification', ['name' => 'WelcomeNotification', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Notifications/WelcomeNotification.php'); + $file = $this->finder->get($this->modulePath.'/Notifications/WelcomeNotification.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.notifications.path', 'SuperNotifications'); $code = $this->artisan('module:make-notification', ['name' => 'WelcomeNotification', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/SuperNotifications/WelcomeNotification.php'); + $file = $this->finder->get($this->getModuleBasePath().'/SuperNotifications/WelcomeNotification.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.notifications.namespace', 'SuperNotifications'); $code = $this->artisan('module:make-notification', ['name' => 'WelcomeNotification', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Notifications/WelcomeNotification.php'); + $file = $this->finder->get($this->modulePath.'/Notifications/WelcomeNotification.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ObserverMakeCommandTest.php b/tests/Commands/Make/ObserverMakeCommandTest.php new file mode 100644 index 000000000..b043d8f41 --- /dev/null +++ b/tests/Commands/Make/ObserverMakeCommandTest.php @@ -0,0 +1,47 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_makes_observer() + { + $code = $this->artisan('module:make-observer', ['name' => 'Post', 'module' => 'Blog']); + + $observerFile = $this->modulePath.'/Observers/PostObserver.php'; + + $this->assertTrue(is_file($observerFile), 'Observer file was not created.'); + $this->assertMatchesSnapshot($this->finder->get($observerFile)); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/PolicyMakeCommandTest.php b/tests/Commands/Make/PolicyMakeCommandTest.php similarity index 71% rename from tests/Commands/PolicyMakeCommandTest.php rename to tests/Commands/Make/PolicyMakeCommandTest.php index 493582cc8..fec1f1a1c 100644 --- a/tests/Commands/PolicyMakeCommandTest.php +++ b/tests/Commands/Make/PolicyMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -32,39 +34,36 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_makes_policy() + public function test_it_makes_policy() { $code = $this->artisan('module:make-policy', ['name' => 'PostPolicy', 'module' => 'Blog']); - $policyFile = $this->modulePath . '/Policies/PostPolicy.php'; + $policyFile = $this->modulePath.'/Policies/PostPolicy.php'; $this->assertTrue(is_file($policyFile), 'Policy file was not created.'); $this->assertMatchesSnapshot($this->finder->get($policyFile)); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.policies.path', 'SuperPolicies'); $code = $this->artisan('module:make-policy', ['name' => 'PostPolicy', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/SuperPolicies/PostPolicy.php'); + $file = $this->finder->get($this->getModuleBasePath().'/SuperPolicies/PostPolicy.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.policies.namespace', 'SuperPolicies'); $code = $this->artisan('module:make-policy', ['name' => 'PostPolicy', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Policies/PostPolicy.php'); + $file = $this->finder->get($this->modulePath.'/Policies/PostPolicy.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/ProviderMakeCommandTest.php b/tests/Commands/Make/ProviderMakeCommandTest.php similarity index 65% rename from tests/Commands/ProviderMakeCommandTest.php rename to tests/Commands/Make/ProviderMakeCommandTest.php index d9a7ef2ac..32909db35 100644 --- a/tests/Commands/ProviderMakeCommandTest.php +++ b/tests/Commands/Make/ProviderMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog'], '--plain' => true, ]); + $this->modulePath = $this->getModuleAppPath(); + $this->artisan('module:make', ['name' => ['Blog'], '--plain' => true]); } public function tearDown(): void @@ -32,69 +34,64 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_a_service_provider() + public function test_it_generates_a_service_provider() { $code = $this->artisan('module:make-provider', ['name' => 'MyBlogServiceProvider', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Providers/MyBlogServiceProvider.php')); + $this->assertTrue(is_file($this->modulePath.'/Providers/MyBlogServiceProvider.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + + public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-provider', ['name' => 'MyBlogServiceProvider', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Providers/MyBlogServiceProvider.php'); + $file = $this->finder->get($this->modulePath.'/Providers/MyBlogServiceProvider.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generates_a_master_service_provider_with_resource_loading() + public function test_it_generates_a_master_service_provider_with_resource_loading() { $code = $this->artisan('module:make-provider', ['name' => 'BlogServiceProvider', 'module' => 'Blog', '--master' => true]); - $file = $this->finder->get($this->modulePath . '/Providers/BlogServiceProvider.php'); + $file = $this->finder->get($this->modulePath.'/Providers/BlogServiceProvider.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_have_custom_migration_resources_location_paths() + public function test_it_can_have_custom_migration_resources_location_paths() { $this->app['config']->set('modules.paths.generator.migration', 'migrations'); $code = $this->artisan('module:make-provider', ['name' => 'BlogServiceProvider', 'module' => 'Blog', '--master' => true]); - $file = $this->finder->get($this->modulePath . '/Providers/BlogServiceProvider.php'); + $file = $this->finder->get($this->modulePath.'/Providers/BlogServiceProvider.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.provider.path', 'SuperProviders'); $code = $this->artisan('module:make-provider', ['name' => 'BlogServiceProvider', 'module' => 'Blog', '--master' => true]); - $file = $this->finder->get($this->modulePath . '/SuperProviders/BlogServiceProvider.php'); + $file = $this->finder->get($this->getModuleBasePath().'/SuperProviders/BlogServiceProvider.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.provider.namespace', 'SuperProviders'); $code = $this->artisan('module:make-provider', ['name' => 'BlogServiceProvider', 'module' => 'Blog', '--master' => true]); - $file = $this->finder->get($this->modulePath . '/Providers/BlogServiceProvider.php'); + $file = $this->finder->get($this->modulePath.'/Providers/BlogServiceProvider.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/RepositoryMakeCommandTest.php b/tests/Commands/Make/RepositoryMakeCommandTest.php new file mode 100644 index 000000000..a6ea60a00 --- /dev/null +++ b/tests/Commands/Make/RepositoryMakeCommandTest.php @@ -0,0 +1,90 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_a_new_repository_class() + { + $code = $this->artisan('module:make-repository', ['name' => 'MyRepository', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Repositories/MyRepository.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_repository_class_can_override_with_force_option() + { + $this->artisan('module:make-repository', ['name' => 'MyRepository', 'module' => 'Blog']); + $code = $this->artisan('module:make-repository', ['name' => 'MyRepository', 'module' => 'Blog', '--force' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Repositories/MyRepository.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_repository_class_can_use_invoke_option() + { + $code = $this->artisan('module:make-repository', ['name' => 'MyRepository', 'module' => 'Blog', '--invokable' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Repositories/MyRepository.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-repository', ['name' => 'MyRepository', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Repositories/MyRepository.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_repository_in_sub_namespace_in_correct_folder() + { + $code = $this->artisan('module:make-repository', ['name' => 'Api\\MyRepository', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Repositories/Api/MyRepository.php')); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_repository_in_sub_namespace_with_correct_generated_file() + { + $code = $this->artisan('module:make-repository', ['name' => 'Api\\MyRepository', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Repositories/Api/MyRepository.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/RequestMakeCommandTest.php b/tests/Commands/Make/RequestMakeCommandTest.php similarity index 64% rename from tests/Commands/RequestMakeCommandTest.php rename to tests/Commands/Make/RequestMakeCommandTest.php index 87f7a743a..ada86afa7 100644 --- a/tests/Commands/RequestMakeCommandTest.php +++ b/tests/Commands/Make/RequestMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -32,47 +34,43 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_a_new_form_request_class() + public function test_it_generates_a_new_form_request_class() { $code = $this->artisan('module:make-request', ['name' => 'CreateBlogPostRequest', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Http/Requests/CreateBlogPostRequest.php')); + $this->assertTrue(is_file($this->modulePath.'/Http/Requests/CreateBlogPostRequest.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-request', ['name' => 'CreateBlogPostRequest', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Http/Requests/CreateBlogPostRequest.php'); + $file = $this->finder->get($this->modulePath.'/Http/Requests/CreateBlogPostRequest.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.request.path', 'SuperRequests'); $code = $this->artisan('module:make-request', ['name' => 'CreateBlogPostRequest', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/SuperRequests/CreateBlogPostRequest.php'); + $file = $this->finder->get($this->getModuleBasePath().'/SuperRequests/CreateBlogPostRequest.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.request.namespace', 'SuperRequests'); $code = $this->artisan('module:make-request', ['name' => 'CreateBlogPostRequest', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Http/Requests/CreateBlogPostRequest.php'); + $file = $this->finder->get($this->modulePath.'/Http/Requests/CreateBlogPostRequest.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/ResourceMakeCommandTest.php b/tests/Commands/Make/ResourceMakeCommandTest.php similarity index 63% rename from tests/Commands/ResourceMakeCommandTest.php rename to tests/Commands/Make/ResourceMakeCommandTest.php index b3b01323b..a8b040806 100644 --- a/tests/Commands/ResourceMakeCommandTest.php +++ b/tests/Commands/Make/ResourceMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -32,58 +34,53 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_a_new_resource_class() + public function test_it_generates_a_new_resource_class() { $code = $this->artisan('module:make-resource', ['name' => 'PostsTransformer', 'module' => 'Blog']); - $this->assertTrue(is_file($this->modulePath . '/Transformers/PostsTransformer.php')); + $this->assertTrue(is_file($this->modulePath.'/Transformers/PostsTransformer.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + public function test_it_generated_correct_file_with_content() { $code = $this->artisan('module:make-resource', ['name' => 'PostsTransformer', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Transformers/PostsTransformer.php'); + $file = $this->finder->get($this->modulePath.'/Transformers/PostsTransformer.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_generate_a_collection_resource_class() + public function test_it_can_generate_a_collection_resource_class() { $code = $this->artisan('module:make-resource', ['name' => 'PostsTransformer', 'module' => 'Blog', '--collection' => true]); - $file = $this->finder->get($this->modulePath . '/Transformers/PostsTransformer.php'); + $file = $this->finder->get($this->modulePath.'/Transformers/PostsTransformer.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { - $this->app['config']->set('modules.paths.generator.resource.path', 'Http/Resources'); + $this->app['config']->set('modules.paths.generator.resource.path', 'app/Http/Resources'); $code = $this->artisan('module:make-resource', ['name' => 'PostsTransformer', 'module' => 'Blog', '--collection' => true]); - $file = $this->finder->get($this->modulePath . '/Http/Resources/PostsTransformer.php'); + $file = $this->finder->get($this->modulePath.'/Http/Resources/PostsTransformer.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.resource.namespace', 'Http\\Resources'); $code = $this->artisan('module:make-resource', ['name' => 'PostsTransformer', 'module' => 'Blog', '--collection' => true]); - $file = $this->finder->get($this->modulePath . '/Transformers/PostsTransformer.php'); + $file = $this->finder->get($this->modulePath.'/Transformers/PostsTransformer.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/RouteProviderMakeCommandTest.php b/tests/Commands/Make/RouteProviderMakeCommandTest.php similarity index 68% rename from tests/Commands/RouteProviderMakeCommandTest.php rename to tests/Commands/Make/RouteProviderMakeCommandTest.php index abd59d775..110492fe6 100644 --- a/tests/Commands/RouteProviderMakeCommandTest.php +++ b/tests/Commands/Make/RouteProviderMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -32,10 +34,9 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_a_new_service_provider_class() + public function test_it_generates_a_new_service_provider_class() { - $path = $this->modulePath . '/Providers/RouteServiceProvider.php'; + $path = $this->modulePath.'/Providers/RouteServiceProvider.php'; $this->finder->delete($path); $code = $this->artisan('module:route-provider', ['module' => 'Blog']); @@ -43,10 +44,9 @@ public function it_generates_a_new_service_provider_class() $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_file_with_content() + public function test_it_generated_correct_file_with_content() { - $path = $this->modulePath . '/Providers/RouteServiceProvider.php'; + $path = $this->modulePath.'/Providers/RouteServiceProvider.php'; $this->finder->delete($path); $code = $this->artisan('module:route-provider', ['module' => 'Blog']); @@ -56,25 +56,23 @@ public function it_generated_correct_file_with_content() $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.provider.path', 'SuperProviders'); $code = $this->artisan('module:route-provider', ['module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/SuperProviders/RouteServiceProvider.php'); + $file = $this->finder->get($this->getModuleBasePath().'/SuperProviders/RouteServiceProvider.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.provider.namespace', 'SuperProviders'); - $path = $this->modulePath . '/Providers/RouteServiceProvider.php'; + $path = $this->modulePath.'/Providers/RouteServiceProvider.php'; $this->finder->delete($path); $code = $this->artisan('module:route-provider', ['module' => 'Blog']); @@ -84,41 +82,38 @@ public function it_can_change_the_default_namespace_specific() $this->assertSame(0, $code); } - /** @test */ - public function it_can_overwrite_route_file_names() + public function test_it_can_overwrite_route_file_names() { $this->app['config']->set('modules.stubs.files.routes/web', 'SuperRoutes/web.php'); $this->app['config']->set('modules.stubs.files.routes/api', 'SuperRoutes/api.php'); $code = $this->artisan('module:route-provider', ['module' => 'Blog', '--force' => true]); - $file = $this->finder->get($this->modulePath . '/Providers/RouteServiceProvider.php'); + $file = $this->finder->get($this->modulePath.'/Providers/RouteServiceProvider.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_overwrite_file(): void + public function test_it_can_overwrite_file(): void { $this->artisan('module:route-provider', ['module' => 'Blog']); $this->app['config']->set('modules.stubs.files.routes/web', 'SuperRoutes/web.php'); $code = $this->artisan('module:route-provider', ['module' => 'Blog', '--force' => true]); - $file = $this->finder->get($this->modulePath . '/Providers/RouteServiceProvider.php'); + $file = $this->finder->get($this->modulePath.'/Providers/RouteServiceProvider.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_custom_controller_namespace(): void + public function test_it_can_change_the_custom_controller_namespace(): void { $this->app['config']->set('modules.paths.generator.controller.path', 'Base/Http/Controllers'); $this->app['config']->set('modules.paths.generator.provider.path', 'Base/Providers'); $code = $this->artisan('module:route-provider', ['module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Base/Providers/RouteServiceProvider.php'); + $file = $this->finder->get($this->getModuleBasePath().'/Base/Providers/RouteServiceProvider.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/RuleMakeCommandTest.php b/tests/Commands/Make/RuleMakeCommandTest.php similarity index 59% rename from tests/Commands/RuleMakeCommandTest.php rename to tests/Commands/Make/RuleMakeCommandTest.php index 08f7b2956..288b411c3 100644 --- a/tests/Commands/RuleMakeCommandTest.php +++ b/tests/Commands/Make/RuleMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -32,39 +34,47 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_makes_rule() + public function test_it_makes_rule() { $code = $this->artisan('module:make-rule', ['name' => 'UniqueRule', 'module' => 'Blog']); - $ruleFile = $this->modulePath . '/Rules/UniqueRule.php'; + $ruleFile = $this->modulePath.'/Rules/UniqueRule.php'; + + $this->assertTrue(is_file($ruleFile), 'Rule file was not created.'); + $this->assertMatchesSnapshot($this->finder->get($ruleFile)); + $this->assertSame(0, $code); + } + + public function test_it_makes_implicit_rule() + { + $code = $this->artisan('module:make-rule', ['name' => 'ImplicitUniqueRule', 'module' => 'Blog', '--implicit' => true]); + + $ruleFile = $this->modulePath.'/Rules/ImplicitUniqueRule.php'; $this->assertTrue(is_file($ruleFile), 'Rule file was not created.'); $this->assertMatchesSnapshot($this->finder->get($ruleFile)); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace() + public function test_it_can_change_the_default_namespace() { $this->app['config']->set('modules.paths.generator.rules.path', 'SuperRules'); $code = $this->artisan('module:make-rule', ['name' => 'UniqueRule', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/SuperRules/UniqueRule.php'); + $file = $this->finder->get($this->getModuleBasePath().'/SuperRules/UniqueRule.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_namespace_specific() + public function test_it_can_change_the_default_namespace_specific() { $this->app['config']->set('modules.paths.generator.rules.namespace', 'SuperRules'); $code = $this->artisan('module:make-rule', ['name' => 'UniqueRule', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Rules/UniqueRule.php'); + $file = $this->finder->get($this->modulePath.'/Rules/UniqueRule.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/ScopeMakeCommandTest.php b/tests/Commands/Make/ScopeMakeCommandTest.php new file mode 100644 index 000000000..8033a5bc6 --- /dev/null +++ b/tests/Commands/Make/ScopeMakeCommandTest.php @@ -0,0 +1,82 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_a_new_scope_class() + { + $code = $this->artisan('module:make-scope', ['name' => 'MyScope', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Models/Scopes/MyScope.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_scope_class_can_override_with_force_option() + { + $this->artisan('module:make-scope', ['name' => 'MyScope', 'module' => 'Blog']); + $code = $this->artisan('module:make-scope', ['name' => 'MyScope', 'module' => 'Blog', '--force' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Models/Scopes/MyScope.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-scope', ['name' => 'MyScope', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Models/Scopes/MyScope.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_scope_in_sub_namespace_in_correct_folder() + { + $code = $this->artisan('module:make-scope', ['name' => 'Api\\MyScope', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Models/Scopes/Api/MyScope.php')); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_scope_in_sub_namespace_with_correct_generated_file() + { + $code = $this->artisan('module:make-scope', ['name' => 'Api\\MyScope', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Models/Scopes/Api/MyScope.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/Make/ServiceMakeCommandTest.php b/tests/Commands/Make/ServiceMakeCommandTest.php new file mode 100644 index 000000000..cd9179e52 --- /dev/null +++ b/tests/Commands/Make/ServiceMakeCommandTest.php @@ -0,0 +1,90 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_a_new_service_class() + { + $code = $this->artisan('module:make-service', ['name' => 'MyService', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Services/MyService.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_service_class_can_override_with_force_option() + { + $this->artisan('module:make-service', ['name' => 'MyService', 'module' => 'Blog']); + $code = $this->artisan('module:make-service', ['name' => 'MyService', 'module' => 'Blog', '--force' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Services/MyService.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_service_class_can_use_invoke_option() + { + $code = $this->artisan('module:make-service', ['name' => 'MyService', 'module' => 'Blog', '--invokable' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Services/MyService.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-service', ['name' => 'MyService', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Services/MyService.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_service_in_sub_namespace_in_correct_folder() + { + $code = $this->artisan('module:make-service', ['name' => 'Api\\MyService', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Services/Api/MyService.php')); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_service_in_sub_namespace_with_correct_generated_file() + { + $code = $this->artisan('module:make-service', ['name' => 'Api\\MyService', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Services/Api/MyService.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/TestMakeCommandTest.php b/tests/Commands/Make/TestMakeCommandTest.php similarity index 59% rename from tests/Commands/TestMakeCommandTest.php rename to tests/Commands/Make/TestMakeCommandTest.php index bde53c84a..b0d7432b9 100644 --- a/tests/Commands/TestMakeCommandTest.php +++ b/tests/Commands/Make/TestMakeCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleBasePath(); $this->activator = $this->app[ActivatorInterface::class]; } @@ -40,86 +42,85 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_generates_a_new_test_class() + public function test_it_generates_a_new_unit_test_class() + { + $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/tests/Unit/EloquentPostRepositoryTest.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_feature_test_class() { - $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog']); $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog', '--feature' => true]); - $this->assertTrue(is_file($this->modulePath . '/Tests/Unit/EloquentPostRepositoryTest.php')); - $this->assertTrue(is_file($this->modulePath . '/Tests/Feature/EloquentPostRepositoryTest.php')); + $this->assertTrue(is_file($this->modulePath.'/tests/Feature/EloquentPostRepositoryTest.php')); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_unit_file_with_content() + public function test_it_generated_correct_unit_file_with_content() { $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Tests/Unit/EloquentPostRepositoryTest.php'); + $file = $this->finder->get($this->modulePath.'/tests/Unit/EloquentPostRepositoryTest.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_generated_correct_feature_file_with_content() + public function test_it_generated_correct_feature_file_with_content() { $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog', '--feature' => true]); - $file = $this->finder->get($this->modulePath . '/Tests/Feature/EloquentPostRepositoryTest.php'); + $file = $this->finder->get($this->modulePath.'/tests/Feature/EloquentPostRepositoryTest.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_unit_namespace() + public function test_it_can_change_the_default_unit_namespace() { - $this->app['config']->set('modules.paths.generator.test.path', 'SuperTests/Unit'); + $this->app['config']->set('modules.paths.generator.test-unit.path', 'SuperTests/Unit'); $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/SuperTests/Unit/EloquentPostRepositoryTest.php'); + $file = $this->finder->get($this->getModuleBasePath().'/SuperTests/Unit/EloquentPostRepositoryTest.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_unit_namespace_specific() + public function test_it_can_change_the_default_unit_namespace_specific() { $this->app['config']->set('modules.paths.generator.test.namespace', 'SuperTests\\Unit'); $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog']); - $file = $this->finder->get($this->modulePath . '/Tests/Unit/EloquentPostRepositoryTest.php'); + $file = $this->finder->get($this->modulePath.'/tests/Unit/EloquentPostRepositoryTest.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_feature_namespace() + public function test_it_can_change_the_default_feature_namespace() { $this->app['config']->set('modules.paths.generator.test-feature.path', 'SuperTests/Feature'); $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog', '--feature' => true]); - $file = $this->finder->get($this->modulePath . '/SuperTests/Feature/EloquentPostRepositoryTest.php'); + $file = $this->finder->get($this->modulePath.'/SuperTests/Feature/EloquentPostRepositoryTest.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); } - /** @test */ - public function it_can_change_the_default_feature_namespace_specific() + public function test_it_can_change_the_default_feature_namespace_specific() { $this->app['config']->set('modules.paths.generator.test-feature.namespace', 'SuperTests\\Feature'); $code = $this->artisan('module:make-test', ['name' => 'EloquentPostRepositoryTest', 'module' => 'Blog', '--feature' => true]); - $file = $this->finder->get($this->modulePath . '/Tests/Feature/EloquentPostRepositoryTest.php'); + $file = $this->finder->get($this->getModuleBasePath().'/tests/Feature/EloquentPostRepositoryTest.php'); $this->assertMatchesSnapshot($file); $this->assertSame(0, $code); diff --git a/tests/Commands/Make/TraitMakeCommandTest.php b/tests/Commands/Make/TraitMakeCommandTest.php new file mode 100644 index 000000000..d8c6adf23 --- /dev/null +++ b/tests/Commands/Make/TraitMakeCommandTest.php @@ -0,0 +1,82 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_a_new_trait_class() + { + $code = $this->artisan('module:make-trait', ['name' => 'MyTrait', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Traits/MyTrait.php')); + $this->assertSame(0, $code); + } + + public function test_it_generates_a_new_trait_class_can_override_with_force_option() + { + $this->artisan('module:make-trait', ['name' => 'MyTrait', 'module' => 'Blog']); + $code = $this->artisan('module:make-trait', ['name' => 'MyTrait', 'module' => 'Blog', '--force' => true]); + + $this->assertTrue(is_file($this->modulePath.'/Traits/MyTrait.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-trait', ['name' => 'MyTrait', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Traits/MyTrait.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_trait_in_sub_namespace_in_correct_folder() + { + $code = $this->artisan('module:make-trait', ['name' => 'Api\\MyTrait', 'module' => 'Blog']); + + $this->assertTrue(is_file($this->modulePath.'/Traits/Api/MyTrait.php')); + $this->assertSame(0, $code); + } + + public function test_it_can_generate_a_trait_in_sub_namespace_with_correct_generated_file() + { + $code = $this->artisan('module:make-trait', ['name' => 'Api\\MyTrait', 'module' => 'Blog']); + + $file = $this->finder->get($this->modulePath.'/Traits/Api/MyTrait.php'); + + $this->assertMatchesSnapshot($file); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/Make/ViewMakeCommandTest.php b/tests/Commands/Make/ViewMakeCommandTest.php new file mode 100644 index 000000000..8651e5680 --- /dev/null +++ b/tests/Commands/Make/ViewMakeCommandTest.php @@ -0,0 +1,61 @@ +finder = $this->app['files']; + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); + } + + public function tearDown(): void + { + $this->app[RepositoryInterface::class]->delete('Blog'); + parent::tearDown(); + } + + public function test_it_generates_the_view() + { + $code = $this->artisan('module:make-view', ['name' => 'Blog', 'module' => 'Blog']); + $this->assertTrue(is_file($this->getModuleBasePath().'/resources/views/blog.blade.php')); + $this->assertSame(0, $code); + } + + public function test_it_generated_correct_file_with_content() + { + $code = $this->artisan('module:make-view', ['name' => 'Blog', 'module' => 'Blog']); + $file = $this->finder->get($this->getModuleBasePath().'/resources/views/blog.blade.php'); + $this->assertTrue(str_contains($file, '
')); + $this->assertSame(0, $code); + } + + public function test_it_can_change_the_default_namespace() + { + $this->app['config']->set('modules.paths.generator.views.path', 'resources/views'); + + $code = $this->artisan('module:make-view', ['name' => 'Blog', 'module' => 'Blog']); + + $file = $this->finder->get($this->getModuleBasePath().'/resources/views/blog.blade.php'); + + $this->assertTrue(str_contains($file, '
')); + $this->assertSame(0, $code); + } +} diff --git a/tests/Commands/Make/__snapshots__/ActionMakeCommandTest__test_it_can_generate_a_action_in_sub_namespace_with_correct_generated_file__1.txt b/tests/Commands/Make/__snapshots__/ActionMakeCommandTest__test_it_can_generate_a_action_in_sub_namespace_with_correct_generated_file__1.txt new file mode 100644 index 000000000..b21fb56ef --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ActionMakeCommandTest__test_it_can_generate_a_action_in_sub_namespace_with_correct_generated_file__1.txt @@ -0,0 +1,11 @@ + $attributes + */ + public function get(Model $model, string $key, mixed $value, array $attributes): mixed + { + return $value; + } + + /** + * Prepare the given value for storage. + * + * @param array $attributes + */ + public function set(Model $model, string $key, mixed $value, array $attributes): mixed + { + return $value; + } +} diff --git a/tests/Commands/Make/__snapshots__/CastMakeCommandTest__test_it_generated_correct_file_with_content__1.txt b/tests/Commands/Make/__snapshots__/CastMakeCommandTest__test_it_generated_correct_file_with_content__1.txt new file mode 100644 index 000000000..05d8e3e37 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/CastMakeCommandTest__test_it_generated_correct_file_with_content__1.txt @@ -0,0 +1,29 @@ + $attributes + */ + public function get(Model $model, string $key, mixed $value, array $attributes): mixed + { + return $value; + } + + /** + * Prepare the given value for storage. + * + * @param array $attributes + */ + public function set(Model $model, string $key, mixed $value, array $attributes): mixed + { + return $value; + } +} diff --git a/tests/Commands/Make/__snapshots__/ChannelMakeCommandTest__test_it_can_change_the_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/ChannelMakeCommandTest__test_it_can_change_the_default_namespace__1.txt new file mode 100644 index 000000000..55d364bf9 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ChannelMakeCommandTest__test_it_can_change_the_default_namespace__1.txt @@ -0,0 +1,24 @@ +json([]); } /** * Store a newly created resource in storage. - * @param Request $request - * @return Response */ public function store(Request $request) { // + + return response()->json([]); } /** * Show the specified resource. - * @param int $id - * @return Response */ public function show($id) { // + + return response()->json([]); } /** * Update the specified resource in storage. - * @param Request $request - * @param int $id - * @return Response */ public function update(Request $request, $id) { // + + return response()->json([]); } /** * Remove the specified resource from storage. - * @param int $id - * @return Response */ public function destroy($id) { // + + return response()->json([]); } } diff --git a/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generates_an_invokable_controller__1.txt b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generates_an_invokable_controller__1.txt new file mode 100644 index 000000000..41a1b8ced --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ControllerMakeCommandTest__test_it_generates_an_invokable_controller__1.txt @@ -0,0 +1,17 @@ +json([]); + } +} diff --git a/tests/Commands/Make/__snapshots__/EnumMakeCommandTest__test_it_can_generate_a_enum_in_sub_namespace_with_correct_generated_file__1.txt b/tests/Commands/Make/__snapshots__/EnumMakeCommandTest__test_it_can_generate_a_enum_in_sub_namespace_with_correct_generated_file__1.txt new file mode 100644 index 000000000..c9edb0b1b --- /dev/null +++ b/tests/Commands/Make/__snapshots__/EnumMakeCommandTest__test_it_can_generate_a_enum_in_sub_namespace_with_correct_generated_file__1.txt @@ -0,0 +1,8 @@ +> + */ + protected $listen = []; + + /** + * Indicates if events should be discovered. + * + * @var bool + */ + protected static $shouldDiscoverEvents = true; + + /** + * Configure the proper event listeners for email verification. + */ + protected function configureEmailVerification(): void + { + // + } +} diff --git a/tests/Commands/Make/__snapshots__/ExceptionMakeCommandTest__test_it_can_generate_a_exception_in_sub_namespace_with_correct_generated_file__1.txt b/tests/Commands/Make/__snapshots__/ExceptionMakeCommandTest__test_it_can_generate_a_exception_in_sub_namespace_with_correct_generated_file__1.txt new file mode 100644 index 000000000..4e24c9dc5 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ExceptionMakeCommandTest__test_it_can_generate_a_exception_in_sub_namespace_with_correct_generated_file__1.txt @@ -0,0 +1,10 @@ +view('view.name'); } diff --git a/tests/Commands/__snapshots__/MailMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt b/tests/Commands/Make/__snapshots__/MailMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt similarity index 84% rename from tests/Commands/__snapshots__/MailMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt rename to tests/Commands/Make/__snapshots__/MailMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt index 1247d2e77..45f802ffe 100644 --- a/tests/Commands/__snapshots__/MailMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt +++ b/tests/Commands/Make/__snapshots__/MailMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt @@ -13,8 +13,6 @@ class SomeMail extends Mailable /** * Create a new message instance. - * - * @return void */ public function __construct() { @@ -23,10 +21,8 @@ class SomeMail extends Mailable /** * Build the message. - * - * @return $this */ - public function build() + public function build(): self { return $this->view('view.name'); } diff --git a/tests/Commands/__snapshots__/MailMakeCommandTest__it_generated_correct_file_with_content__1.txt b/tests/Commands/Make/__snapshots__/MailMakeCommandTest__test_it_generated_correct_file_with_content__1.txt similarity index 84% rename from tests/Commands/__snapshots__/MailMakeCommandTest__it_generated_correct_file_with_content__1.txt rename to tests/Commands/Make/__snapshots__/MailMakeCommandTest__test_it_generated_correct_file_with_content__1.txt index 9fe735a64..5bee369ee 100644 --- a/tests/Commands/__snapshots__/MailMakeCommandTest__it_generated_correct_file_with_content__1.txt +++ b/tests/Commands/Make/__snapshots__/MailMakeCommandTest__test_it_generated_correct_file_with_content__1.txt @@ -13,8 +13,6 @@ class SomeMail extends Mailable /** * Create a new message instance. - * - * @return void */ public function __construct() { @@ -23,10 +21,8 @@ class SomeMail extends Mailable /** * Build the message. - * - * @return $this */ - public function build() + public function build(): self { return $this->view('view.name'); } diff --git a/tests/Commands/__snapshots__/MiddlewareMakeCommandTest__it_can_change_the_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/MiddlewareMakeCommandTest__test_it_can_change_the_default_namespace__1.txt similarity index 70% rename from tests/Commands/__snapshots__/MiddlewareMakeCommandTest__it_can_change_the_default_namespace__1.txt rename to tests/Commands/Make/__snapshots__/MiddlewareMakeCommandTest__test_it_can_change_the_default_namespace__1.txt index 324fdf356..e8b586751 100644 --- a/tests/Commands/__snapshots__/MiddlewareMakeCommandTest__it_can_change_the_default_namespace__1.txt +++ b/tests/Commands/Make/__snapshots__/MiddlewareMakeCommandTest__test_it_can_change_the_default_namespace__1.txt @@ -9,10 +9,6 @@ class SomeMiddleware { /** * Handle an incoming request. - * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed */ public function handle(Request $request, Closure $next) { diff --git a/tests/Commands/__snapshots__/MiddlewareMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt b/tests/Commands/Make/__snapshots__/MiddlewareMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt similarity index 70% rename from tests/Commands/__snapshots__/MiddlewareMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt rename to tests/Commands/Make/__snapshots__/MiddlewareMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt index 324fdf356..e8b586751 100644 --- a/tests/Commands/__snapshots__/MiddlewareMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt +++ b/tests/Commands/Make/__snapshots__/MiddlewareMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt @@ -9,10 +9,6 @@ class SomeMiddleware { /** * Handle an incoming request. - * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed */ public function handle(Request $request, Closure $next) { diff --git a/tests/Commands/__snapshots__/MiddlewareMakeCommandTest__it_generated_correct_file_with_content__1.txt b/tests/Commands/Make/__snapshots__/MiddlewareMakeCommandTest__test_it_generated_correct_file_with_content__1.txt similarity index 71% rename from tests/Commands/__snapshots__/MiddlewareMakeCommandTest__it_generated_correct_file_with_content__1.txt rename to tests/Commands/Make/__snapshots__/MiddlewareMakeCommandTest__test_it_generated_correct_file_with_content__1.txt index dde546720..d0763ead2 100644 --- a/tests/Commands/__snapshots__/MiddlewareMakeCommandTest__it_generated_correct_file_with_content__1.txt +++ b/tests/Commands/Make/__snapshots__/MiddlewareMakeCommandTest__test_it_generated_correct_file_with_content__1.txt @@ -9,10 +9,6 @@ class SomeMiddleware { /** * Handle an incoming request. - * - * @param \Illuminate\Http\Request $request - * @param \Closure $next - * @return mixed */ public function handle(Request $request, Closure $next) { diff --git a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_delete_migration_file_content__1.txt b/tests/Commands/Make/__snapshots__/MigrationMakeCommandTest__test_it_generates_correct_add_migration_file_content__1.txt similarity index 80% rename from tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_delete_migration_file_content__1.txt rename to tests/Commands/Make/__snapshots__/MigrationMakeCommandTest__test_it_generates_correct_add_migration_file_content__1.txt index 7f55aeaea..ec659d5fe 100644 --- a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_delete_migration_file_content__1.txt +++ b/tests/Commands/Make/__snapshots__/MigrationMakeCommandTest__test_it_generates_correct_add_migration_file_content__1.txt @@ -1,32 +1,28 @@ id(); - + $table->timestamps(); }); } /** * Reverse the migrations. - * - * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('posts'); } diff --git a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_default_migration_file_content__1.txt b/tests/Commands/Make/__snapshots__/MigrationMakeCommandTest__test_it_generates_correct_default_migration_file_content__1.txt similarity index 74% rename from tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_default_migration_file_content__1.txt rename to tests/Commands/Make/__snapshots__/MigrationMakeCommandTest__test_it_generates_correct_default_migration_file_content__1.txt index e46b052fc..88fa2f36b 100644 --- a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_default_migration_file_content__1.txt +++ b/tests/Commands/Make/__snapshots__/MigrationMakeCommandTest__test_it_generates_correct_default_migration_file_content__1.txt @@ -1,27 +1,23 @@ id(); - - $table->timestamps(); - }); + Schema::dropIfExists('posts'); } /** * Reverse the migrations. - * - * @return void */ - public function down() + public function down(): void { - Schema::dropIfExists('posts'); + Schema::create('posts', function (Blueprint $table) { + $table->id(); + + $table->timestamps(); + }); } }; diff --git a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_foreign_key_constraints__1.txt b/tests/Commands/Make/__snapshots__/MigrationMakeCommandTest__test_it_generates_foreign_key_constraints__1.txt similarity index 77% rename from tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_foreign_key_constraints__1.txt rename to tests/Commands/Make/__snapshots__/MigrationMakeCommandTest__test_it_generates_foreign_key_constraints__1.txt index 06a41628c..6546dae4d 100644 --- a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_foreign_key_constraints__1.txt +++ b/tests/Commands/Make/__snapshots__/MigrationMakeCommandTest__test_it_generates_foreign_key_constraints__1.txt @@ -1,21 +1,19 @@ id(); - $table->integer('user_id')->unsigned(); + $table->integer('user_id')->unsigned(); $table->foreign('user_id')->references('id')->on('users'); $table->timestamps(); @@ -24,10 +22,8 @@ return new class extends Migration /** * Reverse the migrations. - * - * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('posts'); } diff --git a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_can_change_the_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_can_change_the_default_namespace__1.txt new file mode 100644 index 000000000..7355e76a1 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_can_change_the_default_namespace__1.txt @@ -0,0 +1,22 @@ +id(); - + $table->timestamps(); }); } /** * Reverse the migrations. - * - * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('posts'); } diff --git a/tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_controller_and_migration_when_both_flags_are_present__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_controller_file_with_model__1.txt similarity index 72% rename from tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_controller_and_migration_when_both_flags_are_present__1.txt rename to tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_controller_file_with_model__1.txt index 0bbb67f04..3a09e23cb 100644 --- a/tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_controller_and_migration_when_both_flags_are_present__1.txt +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_controller_file_with_model__1.txt @@ -2,15 +2,13 @@ namespace Modules\Blog\Http\Controllers; -use Illuminate\Contracts\Support\Renderable; +use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use Illuminate\Routing\Controller; class PostController extends Controller { /** * Display a listing of the resource. - * @return Renderable */ public function index() { @@ -19,7 +17,6 @@ class PostController extends Controller /** * Show the form for creating a new resource. - * @return Renderable */ public function create() { @@ -28,8 +25,6 @@ class PostController extends Controller /** * Store a newly created resource in storage. - * @param Request $request - * @return Renderable */ public function store(Request $request) { @@ -38,8 +33,6 @@ class PostController extends Controller /** * Show the specified resource. - * @param int $id - * @return Renderable */ public function show($id) { @@ -48,8 +41,6 @@ class PostController extends Controller /** * Show the form for editing the specified resource. - * @param int $id - * @return Renderable */ public function edit($id) { @@ -58,9 +49,6 @@ class PostController extends Controller /** * Update the specified resource in storage. - * @param Request $request - * @param int $id - * @return Renderable */ public function update(Request $request, $id) { @@ -69,8 +57,6 @@ class PostController extends Controller /** * Remove the specified resource from storage. - * @param int $id - * @return Renderable */ public function destroy($id) { diff --git a/tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_controller_file_with_model__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_controller_file_with_model_using_shortcut_option__1.txt similarity index 72% rename from tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_controller_file_with_model__1.txt rename to tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_controller_file_with_model_using_shortcut_option__1.txt index 0bbb67f04..3a09e23cb 100644 --- a/tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_controller_file_with_model__1.txt +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_controller_file_with_model_using_shortcut_option__1.txt @@ -2,15 +2,13 @@ namespace Modules\Blog\Http\Controllers; -use Illuminate\Contracts\Support\Renderable; +use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use Illuminate\Routing\Controller; class PostController extends Controller { /** * Display a listing of the resource. - * @return Renderable */ public function index() { @@ -19,7 +17,6 @@ class PostController extends Controller /** * Show the form for creating a new resource. - * @return Renderable */ public function create() { @@ -28,8 +25,6 @@ class PostController extends Controller /** * Store a newly created resource in storage. - * @param Request $request - * @return Renderable */ public function store(Request $request) { @@ -38,8 +33,6 @@ class PostController extends Controller /** * Show the specified resource. - * @param int $id - * @return Renderable */ public function show($id) { @@ -48,8 +41,6 @@ class PostController extends Controller /** * Show the form for editing the specified resource. - * @param int $id - * @return Renderable */ public function edit($id) { @@ -58,9 +49,6 @@ class PostController extends Controller /** * Update the specified resource in storage. - * @param Request $request - * @param int $id - * @return Renderable */ public function update(Request $request, $id) { @@ -69,8 +57,6 @@ class PostController extends Controller /** * Remove the specified resource from storage. - * @param int $id - * @return Renderable */ public function destroy($id) { diff --git a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_correct_fillable_fields__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_correct_fillable_fields__1.txt new file mode 100644 index 000000000..8cd255f13 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_correct_fillable_fields__1.txt @@ -0,0 +1,22 @@ +id(); - + $table->timestamps(); }); } /** * Reverse the migrations. - * - * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('product_details'); } diff --git a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_create_migration_file_content__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_migration_file_with_model__1.txt similarity index 81% rename from tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_create_migration_file_content__1.txt rename to tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_migration_file_with_model__1.txt index e61d263de..36dc20e86 100644 --- a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_create_migration_file_content__1.txt +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_migration_file_with_model__1.txt @@ -1,31 +1,27 @@ id(); - + $table->timestamps(); }); } /** * Reverse the migrations. - * - * @return void */ - public function down() + public function down(): void { Schema::dropIfExists('posts'); } diff --git a/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_migration_file_with_model_using_shortcut_option__1.txt b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_migration_file_with_model_using_shortcut_option__1.txt new file mode 100644 index 000000000..36dc20e86 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModelMakeCommandTest__test_it_generates_migration_file_with_model_using_shortcut_option__1.txt @@ -0,0 +1,28 @@ +id(); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('posts'); + } +}; diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_disable__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_disable__1.txt new file mode 100644 index 000000000..cd8b623df --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_disable__1.txt @@ -0,0 +1,123 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + // $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $sourcePath = module_path($this->moduleName, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + + $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides(): array + { + return []; + } + + /** + * @return array + */ + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->moduleNameLower)) { + $paths[] = $path.'/modules/'.$this->moduleNameLower; + } + } + + return $paths; + } +} diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt new file mode 100644 index 000000000..62bd6a496 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__1.txt @@ -0,0 +1,123 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $sourcePath = module_path($this->moduleName, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + + $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides(): array + { + return []; + } + + /** + * @return array + */ + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->moduleNameLower)) { + $paths[] = $path.'/modules/'.$this->moduleNameLower; + } + } + + return $paths; + } +} diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__4.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__2.txt similarity index 52% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__4.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__2.txt index 288050277..dc17450cc 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__4.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generate_module_when_provider_is_enable_and_route_provider_is_enable__2.txt @@ -7,31 +7,20 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvi class RouteServiceProvider extends ServiceProvider { - /** - * The module namespace to assume when generating URLs to actions. - * - * @var string - */ - protected $moduleNamespace = 'Modules\Blog\Http\Controllers'; - /** * Called before routes are registered. * * Register any model bindings or pattern based filters. - * - * @return void */ - public function boot() + public function boot(): void { parent::boot(); } /** * Define the routes for the application. - * - * @return void */ - public function map() + public function map(): void { $this->mapApiRoutes(); @@ -42,28 +31,19 @@ class RouteServiceProvider extends ServiceProvider * Define the "web" routes for the application. * * These routes all receive session state, CSRF protection, etc. - * - * @return void */ - protected function mapWebRoutes() + protected function mapWebRoutes(): void { - Route::middleware('web') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/web.php')); + Route::middleware('web')->group(module_path('Blog', '/routes/web.php')); } /** * Define the "api" routes for the application. * * These routes are typically stateless. - * - * @return void */ - protected function mapApiRoutes() + protected function mapApiRoutes(): void { - Route::prefix('api') - ->middleware('api') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/api.php')); + Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Blog', '/routes/api.php')); } } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt new file mode 100644 index 000000000..62bd6a496 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__1.txt @@ -0,0 +1,123 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $sourcePath = module_path($this->moduleName, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + + $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides(): array + { + return []; + } + + /** + * @return array + */ + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->moduleNameLower)) { + $paths[] = $path.'/modules/'.$this->moduleNameLower; + } + } + + return $paths; + } +} diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__2.txt similarity index 70% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__2.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__2.txt index 7a087461e..bc3afb929 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__2.txt @@ -2,59 +2,58 @@ namespace Modules\Blog\Http\Controllers; +use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use Illuminate\Http\Response; -use Illuminate\Routing\Controller; class BlogController extends Controller { /** * Display a listing of the resource. - * @return Response */ public function index() { // + + return response()->json([]); } /** * Store a newly created resource in storage. - * @param Request $request - * @return Response */ public function store(Request $request) { // + + return response()->json([]); } /** * Show the specified resource. - * @param int $id - * @return Response */ public function show($id) { // + + return response()->json([]); } /** * Update the specified resource in storage. - * @param Request $request - * @param int $id - * @return Response */ public function update(Request $request, $id) { // + + return response()->json([]); } /** * Remove the specified resource from storage. - * @param int $id - * @return Response */ public function destroy($id) { // + + return response()->json([]); } } diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__3.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__3.txt similarity index 52% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__3.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__3.txt index decbc5805..97e7e2a48 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__3.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__3.txt @@ -3,19 +3,14 @@ namespace Modules\Blog\Database\Seeders; use Illuminate\Database\Seeder; -use Illuminate\Database\Eloquent\Model; class BlogDatabaseSeeder extends Seeder { /** * Run the database seeds. - * - * @return void */ - public function run() + public function run(): void { - Model::unguard(); - - // $this->call("OthersTableSeeder"); + // $this->call([]); } } diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__4.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__4.txt similarity index 52% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__4.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__4.txt index 288050277..dc17450cc 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__4.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_module_with_resources__4.txt @@ -7,31 +7,20 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvi class RouteServiceProvider extends ServiceProvider { - /** - * The module namespace to assume when generating URLs to actions. - * - * @var string - */ - protected $moduleNamespace = 'Modules\Blog\Http\Controllers'; - /** * Called before routes are registered. * * Register any model bindings or pattern based filters. - * - * @return void */ - public function boot() + public function boot(): void { parent::boot(); } /** * Define the routes for the application. - * - * @return void */ - public function map() + public function map(): void { $this->mapApiRoutes(); @@ -42,28 +31,19 @@ class RouteServiceProvider extends ServiceProvider * Define the "web" routes for the application. * * These routes all receive session state, CSRF protection, etc. - * - * @return void */ - protected function mapWebRoutes() + protected function mapWebRoutes(): void { - Route::middleware('web') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/web.php')); + Route::middleware('web')->group(module_path('Blog', '/routes/web.php')); } /** * Define the "api" routes for the application. * * These routes are typically stateless. - * - * @return void */ - protected function mapApiRoutes() + protected function mapApiRoutes(): void { - Route::prefix('api') - ->middleware('api') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/api.php')); + Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Blog', '/routes/api.php')); } } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file__1.txt new file mode 100644 index 000000000..cbdf7602e --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_api_route_file__1.txt @@ -0,0 +1,19 @@ +prefix('v1')->group(function () { + Route::apiResource('blog', BlogController::class)->names('blog'); +}); diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_correct_composerjson_file__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_correct_composerjson_file__1.txt similarity index 55% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_correct_composerjson_file__1.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_correct_composerjson_file__1.txt index acaf6a48b..746cae739 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_correct_composerjson_file__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_correct_composerjson_file__1.txt @@ -17,7 +17,14 @@ }, "autoload": { "psr-4": { - "Modules\\Blog\\": "" + "Modules\\Blog\\": "app/", + "Modules\\Blog\\Database\\Factories\\": "database/factories/", + "Modules\\Blog\\Database\\Seeders\\": "database/seeders/" + } + }, + "autoload-dev": { + "psr-4": { + "Modules\\Blog\\Tests\\": "tests/" } } } diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_files__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_files__1.txt similarity index 100% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_files__1.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_files__1.txt diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt new file mode 100644 index 000000000..f6c99ebc3 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_namespace_using_studly_case__1.txt @@ -0,0 +1,123 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $sourcePath = module_path($this->moduleName, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + + $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides(): array + { + return []; + } + + /** + * @return array + */ + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->moduleNameLower)) { + $paths[] = $path.'/modules/'.$this->moduleNameLower; + } + } + + return $paths; + } +} diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt new file mode 100644 index 000000000..62bd6a496 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__1.txt @@ -0,0 +1,123 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $sourcePath = module_path($this->moduleName, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + + $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides(): array + { + return []; + } + + /** + * @return array + */ + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->moduleNameLower)) { + $paths[] = $path.'/modules/'.$this->moduleNameLower; + } + } + + return $paths; + } +} diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__2.txt new file mode 100644 index 000000000..5f4668484 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__2.txt @@ -0,0 +1,30 @@ +> + */ + protected $listen = []; + + /** + * Indicates if events should be discovered. + * + * @var bool + */ + protected static $shouldDiscoverEvents = true; + + /** + * Configure the proper event listeners for email verification. + */ + protected function configureEmailVerification(): void + { + // + } +} diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__4.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__3.txt similarity index 52% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__4.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__3.txt index 288050277..dc17450cc 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__4.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__3.txt @@ -7,31 +7,20 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvi class RouteServiceProvider extends ServiceProvider { - /** - * The module namespace to assume when generating URLs to actions. - * - * @var string - */ - protected $moduleNamespace = 'Modules\Blog\Http\Controllers'; - /** * Called before routes are registered. * * Register any model bindings or pattern based filters. - * - * @return void */ - public function boot() + public function boot(): void { parent::boot(); } /** * Define the routes for the application. - * - * @return void */ - public function map() + public function map(): void { $this->mapApiRoutes(); @@ -42,28 +31,19 @@ class RouteServiceProvider extends ServiceProvider * Define the "web" routes for the application. * * These routes all receive session state, CSRF protection, etc. - * - * @return void */ - protected function mapWebRoutes() + protected function mapWebRoutes(): void { - Route::middleware('web') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/web.php')); + Route::middleware('web')->group(module_path('Blog', '/routes/web.php')); } /** * Define the "api" routes for the application. * * These routes are typically stateless. - * - * @return void */ - protected function mapApiRoutes() + protected function mapApiRoutes(): void { - Route::prefix('api') - ->middleware('api') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/api.php')); + Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Blog', '/routes/api.php')); } } diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__4.txt similarity index 72% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__4.txt index fa3f878dd..21acf68c4 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__4.txt @@ -2,15 +2,13 @@ namespace Modules\Blog\Http\Controllers; -use Illuminate\Contracts\Support\Renderable; +use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use Illuminate\Routing\Controller; class BlogController extends Controller { /** * Display a listing of the resource. - * @return Renderable */ public function index() { @@ -19,7 +17,6 @@ class BlogController extends Controller /** * Show the form for creating a new resource. - * @return Renderable */ public function create() { @@ -28,8 +25,6 @@ class BlogController extends Controller /** * Store a newly created resource in storage. - * @param Request $request - * @return Renderable */ public function store(Request $request) { @@ -38,8 +33,6 @@ class BlogController extends Controller /** * Show the specified resource. - * @param int $id - * @return Renderable */ public function show($id) { @@ -48,8 +41,6 @@ class BlogController extends Controller /** * Show the form for editing the specified resource. - * @param int $id - * @return Renderable */ public function edit($id) { @@ -58,9 +49,6 @@ class BlogController extends Controller /** * Update the specified resource in storage. - * @param Request $request - * @param int $id - * @return Renderable */ public function update(Request $request, $id) { @@ -69,8 +57,6 @@ class BlogController extends Controller /** * Remove the specified resource from storage. - * @param int $id - * @return Renderable */ public function destroy($id) { diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__3.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__5.txt similarity index 52% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__3.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__5.txt index decbc5805..97e7e2a48 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__3.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_module_resources__5.txt @@ -3,19 +3,14 @@ namespace Modules\Blog\Database\Seeders; use Illuminate\Database\Seeder; -use Illuminate\Database\Eloquent\Model; class BlogDatabaseSeeder extends Seeder { /** * Run the database seeds. - * - * @return void */ - public function run() + public function run(): void { - Model::unguard(); - - // $this->call("OthersTableSeeder"); + // $this->call([]); } } diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_vite_file__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_vite_file__1.txt similarity index 63% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_vite_file__1.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_vite_file__1.txt index 94f65d3fa..72d694d39 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_vite_file__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_vite_file__1.txt @@ -1,6 +1,3 @@ -const dotenvExpand = require('dotenv-expand'); -dotenvExpand(require('dotenv').config({ path: '../../.env'/*, debug: true*/})); - import { defineConfig } from 'vite'; import laravel from 'laravel-vite-plugin'; @@ -15,10 +12,15 @@ export default defineConfig({ publicDirectory: '../../public', buildDirectory: 'build-blog', input: [ - __dirname + '/Resources/assets/sass/app.scss', - __dirname + '/Resources/assets/js/app.js' + __dirname + '/resources/assets/sass/app.scss', + __dirname + '/resources/assets/js/app.js' ], refresh: true, }), ], }); + +//export const paths = [ +// 'Modules/Blog/resources/assets/sass/app.scss', +// 'Modules/Blog/resources/assets/js/app.js', +//]; \ No newline at end of file diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__1.txt new file mode 100644 index 000000000..62bd6a496 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__1.txt @@ -0,0 +1,123 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $sourcePath = module_path($this->moduleName, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + + $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides(): array + { + return []; + } + + /** + * @return array + */ + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->moduleNameLower)) { + $paths[] = $path.'/modules/'.$this->moduleNameLower; + } + } + + return $paths; + } +} diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__2.txt similarity index 72% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__2.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__2.txt index fa3f878dd..21acf68c4 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__2.txt @@ -2,15 +2,13 @@ namespace Modules\Blog\Http\Controllers; -use Illuminate\Contracts\Support\Renderable; +use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use Illuminate\Routing\Controller; class BlogController extends Controller { /** * Display a listing of the resource. - * @return Renderable */ public function index() { @@ -19,7 +17,6 @@ class BlogController extends Controller /** * Show the form for creating a new resource. - * @return Renderable */ public function create() { @@ -28,8 +25,6 @@ class BlogController extends Controller /** * Store a newly created resource in storage. - * @param Request $request - * @return Renderable */ public function store(Request $request) { @@ -38,8 +33,6 @@ class BlogController extends Controller /** * Show the specified resource. - * @param int $id - * @return Renderable */ public function show($id) { @@ -48,8 +41,6 @@ class BlogController extends Controller /** * Show the form for editing the specified resource. - * @param int $id - * @return Renderable */ public function edit($id) { @@ -58,9 +49,6 @@ class BlogController extends Controller /** * Update the specified resource in storage. - * @param Request $request - * @param int $id - * @return Renderable */ public function update(Request $request, $id) { @@ -69,8 +57,6 @@ class BlogController extends Controller /** * Remove the specified resource from storage. - * @param int $id - * @return Renderable */ public function destroy($id) { diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__3.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__3.txt similarity index 52% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__3.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__3.txt index decbc5805..97e7e2a48 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__3.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__3.txt @@ -3,19 +3,14 @@ namespace Modules\Blog\Database\Seeders; use Illuminate\Database\Seeder; -use Illuminate\Database\Eloquent\Model; class BlogDatabaseSeeder extends Seeder { /** * Run the database seeds. - * - * @return void */ - public function run() + public function run(): void { - Model::unguard(); - - // $this->call("OthersTableSeeder"); + // $this->call([]); } } diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__4.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__4.txt similarity index 52% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__4.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__4.txt index 288050277..dc17450cc 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__4.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources__4.txt @@ -7,31 +7,20 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvi class RouteServiceProvider extends ServiceProvider { - /** - * The module namespace to assume when generating URLs to actions. - * - * @var string - */ - protected $moduleNamespace = 'Modules\Blog\Http\Controllers'; - /** * Called before routes are registered. * * Register any model bindings or pattern based filters. - * - * @return void */ - public function boot() + public function boot(): void { parent::boot(); } /** * Define the routes for the application. - * - * @return void */ - public function map() + public function map(): void { $this->mapApiRoutes(); @@ -42,28 +31,19 @@ class RouteServiceProvider extends ServiceProvider * Define the "web" routes for the application. * * These routes all receive session state, CSRF protection, etc. - * - * @return void */ - protected function mapWebRoutes() + protected function mapWebRoutes(): void { - Route::middleware('web') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/web.php')); + Route::middleware('web')->group(module_path('Blog', '/routes/web.php')); } /** * Define the "api" routes for the application. * * These routes are typically stateless. - * - * @return void */ - protected function mapApiRoutes() + protected function mapApiRoutes(): void { - Route::prefix('api') - ->middleware('api') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/api.php')); + Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Blog', '/routes/api.php')); } } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt new file mode 100644 index 000000000..62bd6a496 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt @@ -0,0 +1,123 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $sourcePath = module_path($this->moduleName, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + + $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides(): array + { + return []; + } + + /** + * @return array + */ + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->moduleNameLower)) { + $paths[] = $path.'/modules/'.$this->moduleNameLower; + } + } + + return $paths; + } +} diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt similarity index 72% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__2.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt index fa3f878dd..21acf68c4 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__2.txt @@ -2,15 +2,13 @@ namespace Modules\Blog\Http\Controllers; -use Illuminate\Contracts\Support\Renderable; +use App\Http\Controllers\Controller; use Illuminate\Http\Request; -use Illuminate\Routing\Controller; class BlogController extends Controller { /** * Display a listing of the resource. - * @return Renderable */ public function index() { @@ -19,7 +17,6 @@ class BlogController extends Controller /** * Show the form for creating a new resource. - * @return Renderable */ public function create() { @@ -28,8 +25,6 @@ class BlogController extends Controller /** * Store a newly created resource in storage. - * @param Request $request - * @return Renderable */ public function store(Request $request) { @@ -38,8 +33,6 @@ class BlogController extends Controller /** * Show the specified resource. - * @param int $id - * @return Renderable */ public function show($id) { @@ -48,8 +41,6 @@ class BlogController extends Controller /** * Show the form for editing the specified resource. - * @param int $id - * @return Renderable */ public function edit($id) { @@ -58,9 +49,6 @@ class BlogController extends Controller /** * Update the specified resource in storage. - * @param Request $request - * @param int $id - * @return Renderable */ public function update(Request $request, $id) { @@ -69,8 +57,6 @@ class BlogController extends Controller /** * Remove the specified resource from storage. - * @param int $id - * @return Renderable */ public function destroy($id) { diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__3.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__3.txt similarity index 52% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__3.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__3.txt index decbc5805..97e7e2a48 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__3.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__3.txt @@ -3,19 +3,14 @@ namespace Modules\Blog\Database\Seeders; use Illuminate\Database\Seeder; -use Illuminate\Database\Eloquent\Model; class BlogDatabaseSeeder extends Seeder { /** * Run the database seeds. - * - * @return void */ - public function run() + public function run(): void { - Model::unguard(); - - // $this->call("OthersTableSeeder"); + // $this->call([]); } } diff --git a/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__4.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__4.txt new file mode 100644 index 000000000..dc17450cc --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_module_with_resources_when_adding_more_than_one_option__4.txt @@ -0,0 +1,49 @@ +mapApiRoutes(); + + $this->mapWebRoutes(); + } + + /** + * Define the "web" routes for the application. + * + * These routes all receive session state, CSRF protection, etc. + */ + protected function mapWebRoutes(): void + { + Route::middleware('web')->group(module_path('Blog', '/routes/web.php')); + } + + /** + * Define the "api" routes for the application. + * + * These routes are typically stateless. + */ + protected function mapApiRoutes(): void + { + Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Blog', '/routes/api.php')); + } +} diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_route_file__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file__1.txt similarity index 67% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_route_file__1.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file__1.txt index d4d641ff5..082efd6d4 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_route_file__1.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generates_web_route_file__1.txt @@ -1,5 +1,8 @@ group(function() { - Route::get('/', 'BlogController@index'); +Route::group([], function () { + Route::resource('blog', BlogController::class)->names('blog'); }); diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generes_module_with_new_provider_location__1.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_new_provider_location__1.txt similarity index 100% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generes_module_with_new_provider_location__1.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_new_provider_location__1.txt diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generes_module_with_new_provider_location__2.txt b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_new_provider_location__2.txt similarity index 55% rename from tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generes_module_with_new_provider_location__2.txt rename to tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_new_provider_location__2.txt index acaf6a48b..746cae739 100644 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generes_module_with_new_provider_location__2.txt +++ b/tests/Commands/Make/__snapshots__/ModuleMakeCommandTest__test_it_generes_module_with_new_provider_location__2.txt @@ -17,7 +17,14 @@ }, "autoload": { "psr-4": { - "Modules\\Blog\\": "" + "Modules\\Blog\\": "app/", + "Modules\\Blog\\Database\\Factories\\": "database/factories/", + "Modules\\Blog\\Database\\Seeders\\": "database/seeders/" + } + }, + "autoload-dev": { + "psr-4": { + "Modules\\Blog\\Tests\\": "tests/" } } } diff --git a/tests/Commands/__snapshots__/NotificationMakeCommandTest__it_can_change_the_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_can_change_the_default_namespace__1.txt similarity index 53% rename from tests/Commands/__snapshots__/NotificationMakeCommandTest__it_can_change_the_default_namespace__1.txt rename to tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_can_change_the_default_namespace__1.txt index 8b9169efd..4fb9ff311 100644 --- a/tests/Commands/__snapshots__/NotificationMakeCommandTest__it_can_change_the_default_namespace__1.txt +++ b/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_can_change_the_default_namespace__1.txt @@ -13,8 +13,6 @@ class WelcomeNotification extends Notification /** * Create a new notification instance. - * - * @return void */ public function __construct() { @@ -23,39 +21,28 @@ class WelcomeNotification extends Notification /** * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array */ - public function via($notifiable) + public function via($notifiable): array { return ['mail']; } /** * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage */ - public function toMail($notifiable) + public function toMail($notifiable): MailMessage { return (new MailMessage) - ->line('The introduction to the notification.') - ->action('Notification Action', 'https://laravel.com') - ->line('Thank you for using our application!'); + ->line('The introduction to the notification.') + ->action('Notification Action', 'https://laravel.com') + ->line('Thank you for using our application!'); } /** * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array */ - public function toArray($notifiable) + public function toArray($notifiable): array { - return [ - // - ]; + return []; } } diff --git a/tests/Commands/__snapshots__/NotificationMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt b/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt similarity index 53% rename from tests/Commands/__snapshots__/NotificationMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt rename to tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt index 8b9169efd..4fb9ff311 100644 --- a/tests/Commands/__snapshots__/NotificationMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt +++ b/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt @@ -13,8 +13,6 @@ class WelcomeNotification extends Notification /** * Create a new notification instance. - * - * @return void */ public function __construct() { @@ -23,39 +21,28 @@ class WelcomeNotification extends Notification /** * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array */ - public function via($notifiable) + public function via($notifiable): array { return ['mail']; } /** * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage */ - public function toMail($notifiable) + public function toMail($notifiable): MailMessage { return (new MailMessage) - ->line('The introduction to the notification.') - ->action('Notification Action', 'https://laravel.com') - ->line('Thank you for using our application!'); + ->line('The introduction to the notification.') + ->action('Notification Action', 'https://laravel.com') + ->line('Thank you for using our application!'); } /** * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array */ - public function toArray($notifiable) + public function toArray($notifiable): array { - return [ - // - ]; + return []; } } diff --git a/tests/Commands/__snapshots__/NotificationMakeCommandTest__it_generated_correct_file_with_content__1.txt b/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_generated_correct_file_with_content__1.txt similarity index 53% rename from tests/Commands/__snapshots__/NotificationMakeCommandTest__it_generated_correct_file_with_content__1.txt rename to tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_generated_correct_file_with_content__1.txt index 961b05228..53e7ab765 100644 --- a/tests/Commands/__snapshots__/NotificationMakeCommandTest__it_generated_correct_file_with_content__1.txt +++ b/tests/Commands/Make/__snapshots__/NotificationMakeCommandTest__test_it_generated_correct_file_with_content__1.txt @@ -13,8 +13,6 @@ class WelcomeNotification extends Notification /** * Create a new notification instance. - * - * @return void */ public function __construct() { @@ -23,39 +21,28 @@ class WelcomeNotification extends Notification /** * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array */ - public function via($notifiable) + public function via($notifiable): array { return ['mail']; } /** * Get the mail representation of the notification. - * - * @param mixed $notifiable - * @return \Illuminate\Notifications\Messages\MailMessage */ - public function toMail($notifiable) + public function toMail($notifiable): MailMessage { return (new MailMessage) - ->line('The introduction to the notification.') - ->action('Notification Action', 'https://laravel.com') - ->line('Thank you for using our application!'); + ->line('The introduction to the notification.') + ->action('Notification Action', 'https://laravel.com') + ->line('Thank you for using our application!'); } /** * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array */ - public function toArray($notifiable) + public function toArray($notifiable): array { - return [ - // - ]; + return []; } } diff --git a/tests/Commands/Make/__snapshots__/ObserverMakeCommandTest__test_it_makes_observer__1.txt b/tests/Commands/Make/__snapshots__/ObserverMakeCommandTest__test_it_makes_observer__1.txt new file mode 100644 index 000000000..f2b38c90d --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ObserverMakeCommandTest__test_it_makes_observer__1.txt @@ -0,0 +1,48 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $sourcePath = module_path($this->moduleName, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + + $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides(): array + { + return []; + } + + /** + * @return array + */ + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->moduleNameLower)) { + $paths[] = $path.'/modules/'.$this->moduleNameLower; + } + } + + return $paths; + } +} diff --git a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt new file mode 100644 index 000000000..86ef5859a --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt @@ -0,0 +1,123 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $sourcePath = module_path($this->moduleName, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + + $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides(): array + { + return []; + } + + /** + * @return array + */ + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->moduleNameLower)) { + $paths[] = $path.'/modules/'.$this->moduleNameLower; + } + } + + return $paths; + } +} diff --git a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt new file mode 100644 index 000000000..991b8969b --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_can_have_custom_migration_resources_location_paths__1.txt @@ -0,0 +1,123 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $sourcePath = module_path($this->moduleName, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + + $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides(): array + { + return []; + } + + /** + * @return array + */ + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->moduleNameLower)) { + $paths[] = $path.'/modules/'.$this->moduleNameLower; + } + } + + return $paths; + } +} diff --git a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_generated_correct_file_with_content__1.txt b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generated_correct_file_with_content__1.txt similarity index 72% rename from tests/Commands/__snapshots__/ProviderMakeCommandTest__it_generated_correct_file_with_content__1.txt rename to tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generated_correct_file_with_content__1.txt index 3019d551b..922456f3d 100644 --- a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_generated_correct_file_with_content__1.txt +++ b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generated_correct_file_with_content__1.txt @@ -8,20 +8,16 @@ class MyBlogServiceProvider extends ServiceProvider { /** * Register the service provider. - * - * @return void */ - public function register() + public function register(): void { // } /** * Get the services provided by the provider. - * - * @return array */ - public function provides() + public function provides(): array { return []; } diff --git a/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generates_a_master_service_provider_with_resource_loading__1.txt b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generates_a_master_service_provider_with_resource_loading__1.txt new file mode 100644 index 000000000..62bd6a496 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/ProviderMakeCommandTest__test_it_generates_a_master_service_provider_with_resource_loading__1.txt @@ -0,0 +1,123 @@ +registerCommands(); + $this->registerCommandSchedules(); + $this->registerTranslations(); + $this->registerConfig(); + $this->registerViews(); + $this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations')); + } + + /** + * Register the service provider. + */ + public function register(): void + { + $this->app->register(EventServiceProvider::class); + $this->app->register(RouteServiceProvider::class); + } + + /** + * Register commands in the format of Command::class + */ + protected function registerCommands(): void + { + // $this->commands([]); + } + + /** + * Register command Schedules. + */ + protected function registerCommandSchedules(): void + { + // $this->app->booted(function () { + // $schedule = $this->app->make(Schedule::class); + // $schedule->command('inspire')->hourly(); + // }); + } + + /** + * Register translations. + */ + public function registerTranslations(): void + { + $langPath = resource_path('lang/modules/'.$this->moduleNameLower); + + if (is_dir($langPath)) { + $this->loadTranslationsFrom($langPath, $this->moduleNameLower); + $this->loadJsonTranslationsFrom($langPath); + } else { + $this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower); + $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang')); + } + } + + /** + * Register config. + */ + protected function registerConfig(): void + { + $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config'); + $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower); + } + + /** + * Register views. + */ + public function registerViews(): void + { + $viewPath = resource_path('views/modules/'.$this->moduleNameLower); + $sourcePath = module_path($this->moduleName, 'resources/views'); + + $this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']); + + $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); + + $componentNamespace = $this->module_namespace($this->moduleName, $this->app_path(config('modules.paths.generator.component-class.path'))); + Blade::componentNamespace($componentNamespace, $this->moduleNameLower); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides(): array + { + return []; + } + + /** + * @return array + */ + private function getPublishableViewPaths(): array + { + $paths = []; + foreach (config('view.paths') as $path) { + if (is_dir($path.'/modules/'.$this->moduleNameLower)) { + $paths[] = $path.'/modules/'.$this->moduleNameLower; + } + } + + return $paths; + } +} diff --git a/tests/Commands/Make/__snapshots__/RepositoryMakeCommandTest__test_it_can_generate_a_repository_in_sub_namespace_with_correct_generated_file__1.txt b/tests/Commands/Make/__snapshots__/RepositoryMakeCommandTest__test_it_can_generate_a_repository_in_sub_namespace_with_correct_generated_file__1.txt new file mode 100644 index 000000000..6ddffc7b9 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/RepositoryMakeCommandTest__test_it_can_generate_a_repository_in_sub_namespace_with_correct_generated_file__1.txt @@ -0,0 +1,11 @@ +mapApiRoutes(); @@ -42,28 +31,19 @@ class RouteServiceProvider extends ServiceProvider * Define the "web" routes for the application. * * These routes all receive session state, CSRF protection, etc. - * - * @return void */ - protected function mapWebRoutes() + protected function mapWebRoutes(): void { - Route::middleware('web') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/web.php')); + Route::middleware('web')->group(module_path('Blog', '/routes/web.php')); } /** * Define the "api" routes for the application. * * These routes are typically stateless. - * - * @return void */ - protected function mapApiRoutes() + protected function mapApiRoutes(): void { - Route::prefix('api') - ->middleware('api') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/api.php')); + Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Blog', '/routes/api.php')); } } diff --git a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_change_the_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt similarity index 52% rename from tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_change_the_default_namespace__1.txt rename to tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt index ebc5786a4..af40c469e 100644 --- a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_change_the_default_namespace__1.txt +++ b/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_change_the_default_namespace__1.txt @@ -7,31 +7,20 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvi class RouteServiceProvider extends ServiceProvider { - /** - * The module namespace to assume when generating URLs to actions. - * - * @var string - */ - protected $moduleNamespace = 'Modules\Blog\Http\Controllers'; - /** * Called before routes are registered. * * Register any model bindings or pattern based filters. - * - * @return void */ - public function boot() + public function boot(): void { parent::boot(); } /** * Define the routes for the application. - * - * @return void */ - public function map() + public function map(): void { $this->mapApiRoutes(); @@ -42,28 +31,19 @@ class RouteServiceProvider extends ServiceProvider * Define the "web" routes for the application. * * These routes all receive session state, CSRF protection, etc. - * - * @return void */ - protected function mapWebRoutes() + protected function mapWebRoutes(): void { - Route::middleware('web') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/web.php')); + Route::middleware('web')->group(module_path('Blog', '/routes/web.php')); } /** * Define the "api" routes for the application. * * These routes are typically stateless. - * - * @return void */ - protected function mapApiRoutes() + protected function mapApiRoutes(): void { - Route::prefix('api') - ->middleware('api') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/api.php')); + Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Blog', '/routes/api.php')); } } diff --git a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt b/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt similarity index 52% rename from tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt rename to tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt index ebc5786a4..af40c469e 100644 --- a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt +++ b/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_change_the_default_namespace_specific__1.txt @@ -7,31 +7,20 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvi class RouteServiceProvider extends ServiceProvider { - /** - * The module namespace to assume when generating URLs to actions. - * - * @var string - */ - protected $moduleNamespace = 'Modules\Blog\Http\Controllers'; - /** * Called before routes are registered. * * Register any model bindings or pattern based filters. - * - * @return void */ - public function boot() + public function boot(): void { parent::boot(); } /** * Define the routes for the application. - * - * @return void */ - public function map() + public function map(): void { $this->mapApiRoutes(); @@ -42,28 +31,19 @@ class RouteServiceProvider extends ServiceProvider * Define the "web" routes for the application. * * These routes all receive session state, CSRF protection, etc. - * - * @return void */ - protected function mapWebRoutes() + protected function mapWebRoutes(): void { - Route::middleware('web') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/web.php')); + Route::middleware('web')->group(module_path('Blog', '/routes/web.php')); } /** * Define the "api" routes for the application. * * These routes are typically stateless. - * - * @return void */ - protected function mapApiRoutes() + protected function mapApiRoutes(): void { - Route::prefix('api') - ->middleware('api') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/api.php')); + Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Blog', '/routes/api.php')); } } diff --git a/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_overwrite_file__1.txt b/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_overwrite_file__1.txt new file mode 100644 index 000000000..e8d7205d7 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_overwrite_file__1.txt @@ -0,0 +1,49 @@ +mapApiRoutes(); + + $this->mapWebRoutes(); + } + + /** + * Define the "web" routes for the application. + * + * These routes all receive session state, CSRF protection, etc. + */ + protected function mapWebRoutes(): void + { + Route::middleware('web')->group(module_path('Blog', '/SuperRoutes/web.php')); + } + + /** + * Define the "api" routes for the application. + * + * These routes are typically stateless. + */ + protected function mapApiRoutes(): void + { + Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Blog', '/routes/api.php')); + } +} diff --git a/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_overwrite_route_file_names__1.txt b/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_overwrite_route_file_names__1.txt new file mode 100644 index 000000000..7c40e3d35 --- /dev/null +++ b/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_can_overwrite_route_file_names__1.txt @@ -0,0 +1,49 @@ +mapApiRoutes(); + + $this->mapWebRoutes(); + } + + /** + * Define the "web" routes for the application. + * + * These routes all receive session state, CSRF protection, etc. + */ + protected function mapWebRoutes(): void + { + Route::middleware('web')->group(module_path('Blog', '/SuperRoutes/web.php')); + } + + /** + * Define the "api" routes for the application. + * + * These routes are typically stateless. + */ + protected function mapApiRoutes(): void + { + Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Blog', '/SuperRoutes/api.php')); + } +} diff --git a/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_generated_correct_file_with_content__1.txt b/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_generated_correct_file_with_content__1.txt new file mode 100644 index 000000000..dc17450cc --- /dev/null +++ b/tests/Commands/Make/__snapshots__/RouteProviderMakeCommandTest__test_it_generated_correct_file_with_content__1.txt @@ -0,0 +1,49 @@ +mapApiRoutes(); + + $this->mapWebRoutes(); + } + + /** + * Define the "web" routes for the application. + * + * These routes all receive session state, CSRF protection, etc. + */ + protected function mapWebRoutes(): void + { + Route::middleware('web')->group(module_path('Blog', '/routes/web.php')); + } + + /** + * Define the "api" routes for the application. + * + * These routes are typically stateless. + */ + protected function mapApiRoutes(): void + { + Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Blog', '/routes/api.php')); + } +} diff --git a/tests/Commands/Make/__snapshots__/RuleMakeCommandTest__test_it_can_change_the_default_namespace__1.txt b/tests/Commands/Make/__snapshots__/RuleMakeCommandTest__test_it_can_change_the_default_namespace__1.txt new file mode 100644 index 000000000..23757e05f --- /dev/null +++ b/tests/Commands/Make/__snapshots__/RuleMakeCommandTest__test_it_can_change_the_default_namespace__1.txt @@ -0,0 +1,17 @@ +get('/'); diff --git a/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_feature_namespace_specific__1.txt b/tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_can_change_the_default_feature_namespace_specific__1.txt similarity index 85% rename from tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_feature_namespace_specific__1.txt rename to tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_can_change_the_default_feature_namespace_specific__1.txt index 4ccecd857..dba6e35a1 100644 --- a/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_feature_namespace_specific__1.txt +++ b/tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_can_change_the_default_feature_namespace_specific__1.txt @@ -10,10 +10,8 @@ class EloquentPostRepositoryTest extends TestCase { /** * A basic feature test example. - * - * @return void */ - public function testExample() + public function testExample(): void { $response = $this->get('/'); diff --git a/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_unit_namespace__1.txt b/tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_can_change_the_default_unit_namespace__1.txt similarity index 100% rename from tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_unit_namespace__1.txt rename to tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_can_change_the_default_unit_namespace__1.txt diff --git a/tests/Commands/__snapshots__/TestMakeCommandTest__it_generated_correct_unit_file_with_content__1.txt b/tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_can_change_the_default_unit_namespace_specific__1.txt similarity index 100% rename from tests/Commands/__snapshots__/TestMakeCommandTest__it_generated_correct_unit_file_with_content__1.txt rename to tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_can_change_the_default_unit_namespace_specific__1.txt diff --git a/tests/Commands/__snapshots__/TestMakeCommandTest__it_generated_correct_feature_file_with_content__1.txt b/tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_generated_correct_feature_file_with_content__1.txt similarity index 85% rename from tests/Commands/__snapshots__/TestMakeCommandTest__it_generated_correct_feature_file_with_content__1.txt rename to tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_generated_correct_feature_file_with_content__1.txt index 04d4c6b90..6378738a3 100644 --- a/tests/Commands/__snapshots__/TestMakeCommandTest__it_generated_correct_feature_file_with_content__1.txt +++ b/tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_generated_correct_feature_file_with_content__1.txt @@ -10,10 +10,8 @@ class EloquentPostRepositoryTest extends TestCase { /** * A basic feature test example. - * - * @return void */ - public function testExample() + public function testExample(): void { $response = $this->get('/'); diff --git a/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_unit_namespace_specific__1.txt b/tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_generated_correct_unit_file_with_content__1.txt similarity index 89% rename from tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_unit_namespace_specific__1.txt rename to tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_generated_correct_unit_file_with_content__1.txt index 273dc9657..fcbfc0da3 100644 --- a/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_unit_namespace_specific__1.txt +++ b/tests/Commands/Make/__snapshots__/TestMakeCommandTest__test_it_generated_correct_unit_file_with_content__1.txt @@ -1,6 +1,6 @@ repository = new LaravelFileRepository($this->app); - $this->finder = $this->app['files']; - } - - /** @test */ - public function it_migrates_a_module() - { - $this->repository->addLocation(__DIR__ . '/../stubs/Recipe'); - - $this->artisan('module:migrate', ['module' => 'Recipe']); - - dd(Schema::hasTable('recipe__recipes'), $this->app['db']->table('recipe__recipes')->get()); - } -} diff --git a/tests/Commands/ModuleDeleteCommandTest.php b/tests/Commands/ModuleDeleteCommandTest.php deleted file mode 100644 index 939ec52d9..000000000 --- a/tests/Commands/ModuleDeleteCommandTest.php +++ /dev/null @@ -1,50 +0,0 @@ -finder = $this->app['files']; - $this->activator = new FileActivator($this->app); - } - - /** @test */ - public function it_can_delete_a_module_from_disk(): void - { - $this->artisan('module:make', ['name' => ['WrongModule']]); - $this->assertDirectoryExists(base_path('modules/WrongModule')); - - $code = $this->artisan('module:delete', ['module' => 'WrongModule']); - $this->assertFileDoesNotExist(base_path('modules/WrongModule')); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_deletes_modules_from_status_file(): void - { - $this->artisan('module:make', ['name' => ['WrongModule']]); - $this->assertMatchesSnapshot($this->finder->get($this->activator->getStatusesFilePath())); - - $code = $this->artisan('module:delete', ['module' => 'WrongModule']); - $this->assertMatchesSnapshot($this->finder->get($this->activator->getStatusesFilePath())); - $this->assertSame(0, $code); - } -} diff --git a/tests/Commands/ModuleMakeCommandTest.php b/tests/Commands/ModuleMakeCommandTest.php deleted file mode 100644 index 0fcbc0966..000000000 --- a/tests/Commands/ModuleMakeCommandTest.php +++ /dev/null @@ -1,430 +0,0 @@ -modulePath = base_path('modules/Blog'); - $this->finder = $this->app['files']; - $this->repository = $this->app[RepositoryInterface::class]; - $this->activator = $this->app[ActivatorInterface::class]; - } - - public function tearDown(): void - { - $this->finder->deleteDirectory($this->modulePath); - if ($this->finder->isDirectory(base_path('modules/ModuleName'))) { - $this->finder->deleteDirectory(base_path('modules/ModuleName')); - } - $this->activator->reset(); - parent::tearDown(); - } - - /** @test */ - public function it_generates_module() - { - $code = $this->artisan('module:make', ['name' => ['Blog']]); - - $this->assertDirectoryExists($this->modulePath); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generates_module_folders() - { - $code = $this->artisan('module:make', ['name' => ['Blog']]); - - foreach (config('modules.paths.generator') as $directory) { - $this->assertDirectoryExists($this->modulePath . '/' . $directory['path']); - } - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generates_module_files() - { - $code = $this->artisan('module:make', ['name' => ['Blog']]); - - foreach (config('modules.stubs.files') as $file) { - $path = base_path('modules/Blog') . '/' . $file; - $this->assertTrue($this->finder->exists($path), "[$file] does not exists"); - } - $path = base_path('modules/Blog') . '/module.json'; - $this->assertTrue($this->finder->exists($path), '[module.json] does not exists'); - $this->assertMatchesSnapshot($this->finder->get($path)); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generates_web_route_file() - { - $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); - } - - /** @test */ - public function it_generates_api_route_file() - { - $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); - } - - /** @test */ - public function it_generates_vite_file() - { - $code = $this->artisan('module:make', ['name' => ['Blog']]); - - $path = $this->modulePath . '/' . $this->app['modules']->config('stubs.files.vite'); - - $this->assertMatchesSnapshot($this->finder->get($path)); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generates_module_resources() - { - $code = $this->artisan('module:make', ['name' => ['Blog']]); - - $path = base_path('modules/Blog') . '/Providers/BlogServiceProvider.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $path = base_path('modules/Blog') . '/Http/Controllers/BlogController.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $path = base_path('modules/Blog') . '/Database/Seeders/BlogDatabaseSeeder.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $path = base_path('modules/Blog') . '/Providers/RouteServiceProvider.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generates_correct_composerjson_file() - { - $code = $this->artisan('module:make', ['name' => ['Blog']]); - - $file = $this->finder->get($this->modulePath . '/composer.json'); - - $this->assertMatchesSnapshot($file); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generates_module_folder_using_studly_case() - { - $code = $this->artisan('module:make', ['name' => ['ModuleName']]); - - $this->assertTrue($this->finder->exists(base_path('modules/ModuleName'))); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generates_module_namespace_using_studly_case() - { - $code = $this->artisan('module:make', ['name' => ['ModuleName']]); - - $file = $this->finder->get(base_path('modules/ModuleName') . '/Providers/ModuleNameServiceProvider.php'); - - $this->assertMatchesSnapshot($file); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generates_a_plain_module_with_no_resources() - { - $code = $this->artisan('module:make', ['name' => ['ModuleName'], '--plain' => true]); - - $path = base_path('modules/ModuleName') . '/Providers/ModuleNameServiceProvider.php'; - $this->assertFalse($this->finder->exists($path)); - - $path = base_path('modules/ModuleName') . '/Http/Controllers/ModuleNameController.php'; - $this->assertFalse($this->finder->exists($path)); - - $path = base_path('modules/ModuleName') . '/Database/Seeders/ModuleNameDatabaseSeeder.php'; - $this->assertFalse($this->finder->exists($path)); - - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generates_a_plain_module_with_no_files() - { - $code = $this->artisan('module:make', ['name' => ['ModuleName'], '--plain' => true]); - - foreach (config('modules.stubs.files') as $file) { - $path = base_path('modules/ModuleName') . '/' . $file; - $this->assertFalse($this->finder->exists($path), "[$file] exists"); - } - $path = base_path('modules/ModuleName') . '/module.json'; - $this->assertTrue($this->finder->exists($path), '[module.json] does not exists'); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generates_plain_module_with_no_service_provider_in_modulejson_file() - { - $code = $this->artisan('module:make', ['name' => ['ModuleName'], '--plain' => true]); - - $path = base_path('modules/ModuleName') . '/module.json'; - $content = json_decode($this->finder->get($path)); - - $this->assertCount(0, $content->providers); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_outputs_error_when_module_exists() - { - $this->artisan('module:make', ['name' => ['Blog']]); - $code = $this->artisan('module:make', ['name' => ['Blog']]); - - $output = Artisan::output(); - $expected = 'ERROR Module [Blog] already exists!'; - - $this->assertTrue(Str::contains($output, $expected)); - - $this->assertSame(E_ERROR, $code); - } - - /** @test */ - public function it_still_generates_module_if_it_exists_using_force_flag() - { - $this->artisan('module:make', ['name' => ['Blog']]); - $code = $this->artisan('module:make', ['name' => ['Blog'], '--force' => true]); - - $output = Artisan::output(); - - $notExpected = 'Module [Blog] already exist! -'; - $this->assertNotEquals($notExpected, $output); - $this->assertTrue(Str::contains($output, 'Module [Blog] created successfully.')); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_can_generate_module_with_old_config_format() - { - $this->app['config']->set('modules.paths.generator', [ - 'assets' => 'Assets', - 'config' => 'Config', - 'command' => 'Console', - 'event' => 'Events', - 'listener' => 'Listeners', - 'migration' => 'Database/Migrations', - 'factory' => 'Database/factories', - 'model' => 'Entities', - 'repository' => 'Repositories', - 'seeder' => 'Database/Seeders', - 'controller' => 'Http/Controllers', - 'filter' => 'Http/Middleware', - 'request' => 'Http/Requests', - 'provider' => 'Providers', - 'lang' => 'Resources/lang', - 'views' => 'Resources/views', - 'policies' => false, - 'rules' => false, - 'test' => 'Tests', - 'jobs' => 'Jobs', - 'emails' => 'Emails', - 'notifications' => 'Notifications', - 'resource' => false, - ]); - - $code = $this->artisan('module:make', ['name' => ['Blog']]); - - $this->assertDirectoryExists($this->modulePath . '/Assets'); - $this->assertDirectoryExists($this->modulePath . '/Emails'); - $this->assertFileDoesNotExist($this->modulePath . '/Rules'); - $this->assertFileDoesNotExist($this->modulePath . '/Policies'); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_can_ignore_some_folders_to_generate_with_old_format() - { - $this->app['config']->set('modules.paths.generator.assets', false); - $this->app['config']->set('modules.paths.generator.emails', false); - - $code = $this->artisan('module:make', ['name' => ['Blog']]); - - $this->assertFileDoesNotExist($this->modulePath . '/Assets'); - $this->assertFileDoesNotExist($this->modulePath . '/Emails'); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_can_ignore_some_folders_to_generate_with_new_format() - { - $this->app['config']->set('modules.paths.generator.assets', ['path' => 'Assets', 'generate' => false]); - $this->app['config']->set('modules.paths.generator.emails', ['path' => 'Emails', 'generate' => false]); - - $code = $this->artisan('module:make', ['name' => ['Blog']]); - - $this->assertFileDoesNotExist($this->modulePath . '/Assets'); - $this->assertFileDoesNotExist($this->modulePath . '/Emails'); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_can_ignore_resource_folders_to_generate() - { - $this->app['config']->set('modules.paths.generator.seeder', ['path' => 'Database/Seeders', 'generate' => false]); - $this->app['config']->set('modules.paths.generator.provider', ['path' => 'Providers', 'generate' => false]); - $this->app['config']->set('modules.paths.generator.controller', ['path' => 'Http/Controllers', 'generate' => false]); - - $code = $this->artisan('module:make', ['name' => ['Blog']]); - - $this->assertFileDoesNotExist($this->modulePath . '/Database/Seeders'); - $this->assertFileDoesNotExist($this->modulePath . '/Providers'); - $this->assertFileDoesNotExist($this->modulePath . '/Http/Controllers'); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generates_enabled_module() - { - $code = $this->artisan('module:make', ['name' => ['Blog']]); - - $this->assertTrue($this->repository->isEnabled('Blog')); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generates_disabled_module_with_disabled_flag() - { - $code = $this->artisan('module:make', ['name' => ['Blog'], '--disabled' => true]); - - $this->assertTrue($this->repository->isDisabled('Blog')); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generes_module_with_new_provider_location() - { - $this->app['config']->set('modules.paths.generator.provider', ['path' => 'Base/Providers', 'generate' => true]); - - $code = $this->artisan('module:make', ['name' => ['Blog']]); - - $this->assertDirectoryExists($this->modulePath . '/Base/Providers'); - $file = $this->finder->get($this->modulePath . '/module.json'); - $this->assertMatchesSnapshot($file); - $file = $this->finder->get($this->modulePath . '/composer.json'); - $this->assertMatchesSnapshot($file); - $this->assertSame(0, $code); - } - - /** @test */ - public function it_generates_web_module_with_resources() - { - $code = $this->artisan('module:make', ['name' => ['Blog'], '--web' => true]); - - $path = base_path('modules/Blog') . '/Providers/BlogServiceProvider.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $path = base_path('modules/Blog') . '/Http/Controllers/BlogController.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $path = base_path('modules/Blog') . '/Database/Seeders/BlogDatabaseSeeder.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $path = base_path('modules/Blog') . '/Providers/RouteServiceProvider.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $this->assertSame(0, $code); - } - /** @test */ - public function it_generates_api_module_with_resources() - { - $code = $this->artisan('module:make', ['name' => ['Blog'], '--api' => true]); - - $path = base_path('modules/Blog') . '/Providers/BlogServiceProvider.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $path = base_path('modules/Blog') . '/Http/Controllers/BlogController.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $path = base_path('modules/Blog') . '/Database/Seeders/BlogDatabaseSeeder.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $path = base_path('modules/Blog') . '/Providers/RouteServiceProvider.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $this->assertSame(0, $code); - } - /** @test */ - public function it_generates_web_module_with_resources_when_adding_more_than_one_option() - { - $code = $this->artisan('module:make', ['name' => ['Blog'], '--api' => true,'--plain'=>true]); - - $path = base_path('modules/Blog') . '/Providers/BlogServiceProvider.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $path = base_path('modules/Blog') . '/Http/Controllers/BlogController.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $path = base_path('modules/Blog') . '/Database/Seeders/BlogDatabaseSeeder.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $path = base_path('modules/Blog') . '/Providers/RouteServiceProvider.php'; - $this->assertTrue($this->finder->exists($path)); - $this->assertMatchesSnapshot($this->finder->get($path)); - - $this->assertSame(0, $code); - } -} diff --git a/tests/Commands/PublishCommandTest.php b/tests/Commands/Publish/PublishCommandTest.php similarity index 71% rename from tests/Commands/PublishCommandTest.php rename to tests/Commands/Publish/PublishCommandTest.php index d9c0b03cf..7aa02e1e2 100644 --- a/tests/Commands/PublishCommandTest.php +++ b/tests/Commands/Publish/PublishCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); + $this->createModule(); + $this->modulePath = $this->getModuleBasePath(); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); - $this->finder->put($this->modulePath . '/Assets/script.js', 'assetfile'); + $this->finder->put($this->modulePath.'/resources/assets/script.js', 'assetfile'); } public function tearDown(): void @@ -31,8 +32,7 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_published_module_assets() + public function test_it_published_module_assets() { $code = $this->artisan('module:publish', ['module' => 'Blog']); diff --git a/tests/Commands/PublishMigrationCommandTest.php b/tests/Commands/Publish/PublishMigrationCommandTest.php similarity index 81% rename from tests/Commands/PublishMigrationCommandTest.php rename to tests/Commands/Publish/PublishMigrationCommandTest.php index bca073d65..9eb005726 100644 --- a/tests/Commands/PublishMigrationCommandTest.php +++ b/tests/Commands/Publish/PublishMigrationCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); $this->artisan('module:make-migration', ['name' => 'create_posts_table', 'module' => 'Blog']); } @@ -32,8 +33,7 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_publishes_module_migrations() + public function test_it_publishes_module_migrations() { $code = $this->artisan('module:publish-migration', ['module' => 'Blog']); diff --git a/tests/Commands/PublishTranslationCommandTest.php b/tests/Commands/Publish/PublishTranslationCommandTest.php similarity index 77% rename from tests/Commands/PublishTranslationCommandTest.php rename to tests/Commands/Publish/PublishTranslationCommandTest.php index b1136831b..0e8da296d 100644 --- a/tests/Commands/PublishTranslationCommandTest.php +++ b/tests/Commands/Publish/PublishTranslationCommandTest.php @@ -1,6 +1,6 @@ modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void @@ -30,8 +31,7 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_published_module_translations() + public function test_it_published_module_translations() { $code = $this->artisan('module:publish-translation', ['module' => 'Blog']); diff --git a/tests/Commands/__snapshots__/CommandMakeCommandTest__it_can_change_the_default_namespace__1.php b/tests/Commands/__snapshots__/CommandMakeCommandTest__it_can_change_the_default_namespace__1.php deleted file mode 100644 index 99de97898..000000000 --- a/tests/Commands/__snapshots__/CommandMakeCommandTest__it_can_change_the_default_namespace__1.php +++ /dev/null @@ -1,69 +0,0 @@ -view(\'view.name\'); - } -} -'; diff --git a/tests/Commands/__snapshots__/MailMakeCommandTest__it_can_change_the_default_namespace_specific__1.php b/tests/Commands/__snapshots__/MailMakeCommandTest__it_can_change_the_default_namespace_specific__1.php deleted file mode 100644 index cb794bfca..000000000 --- a/tests/Commands/__snapshots__/MailMakeCommandTest__it_can_change_the_default_namespace_specific__1.php +++ /dev/null @@ -1,34 +0,0 @@ -view(\'view.name\'); - } -} -'; diff --git a/tests/Commands/__snapshots__/MailMakeCommandTest__it_generated_correct_file_with_content__1.php b/tests/Commands/__snapshots__/MailMakeCommandTest__it_generated_correct_file_with_content__1.php deleted file mode 100644 index 7cfe15f98..000000000 --- a/tests/Commands/__snapshots__/MailMakeCommandTest__it_generated_correct_file_with_content__1.php +++ /dev/null @@ -1,34 +0,0 @@ -view(\'view.name\'); - } -} -'; diff --git a/tests/Commands/__snapshots__/MiddlewareMakeCommandTest__it_can_change_the_default_namespace__1.php b/tests/Commands/__snapshots__/MiddlewareMakeCommandTest__it_can_change_the_default_namespace__1.php deleted file mode 100644 index 45fa67977..000000000 --- a/tests/Commands/__snapshots__/MiddlewareMakeCommandTest__it_can_change_the_default_namespace__1.php +++ /dev/null @@ -1,22 +0,0 @@ -id(); - - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists(\'posts\'); - } -} -'; diff --git a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_default_migration_file_content__1.php b/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_default_migration_file_content__1.php deleted file mode 100644 index c9ac87189..000000000 --- a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_default_migration_file_content__1.php +++ /dev/null @@ -1,29 +0,0 @@ -bigIncrements(\'id\'); - - $table->timestamps(); - }); - } -} -'; diff --git a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_drop_migration_file_content__1.txt b/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_drop_migration_file_content__1.txt deleted file mode 100644 index b116319f8..000000000 --- a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_correct_drop_migration_file_content__1.txt +++ /dev/null @@ -1,32 +0,0 @@ -bigIncrements('id'); - - $table->timestamps(); - }); - } -}; diff --git a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_foreign_key_constraints__1.php b/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_foreign_key_constraints__1.php deleted file mode 100644 index dcf66c310..000000000 --- a/tests/Commands/__snapshots__/MigrationMakeCommandTest__it_generates_foreign_key_constraints__1.php +++ /dev/null @@ -1,35 +0,0 @@ -id(); - $table->integer(\'user_id\')->unsigned(); - $table->foreign(\'user_id\')->references(\'id\')->on(\'users\'); - - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists(\'posts\'); - } -} -'; diff --git a/tests/Commands/__snapshots__/ModelMakeCommandTest__it_can_change_the_default_namespace__1.php b/tests/Commands/__snapshots__/ModelMakeCommandTest__it_can_change_the_default_namespace__1.php deleted file mode 100644 index 6ddb78334..000000000 --- a/tests/Commands/__snapshots__/ModelMakeCommandTest__it_can_change_the_default_namespace__1.php +++ /dev/null @@ -1,19 +0,0 @@ -id(); - - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists(\'posts\'); - } -} -'; diff --git a/tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_controller_file_with_model__1.php b/tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_controller_file_with_model__1.php deleted file mode 100644 index 7b0a1aea8..000000000 --- a/tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_controller_file_with_model__1.php +++ /dev/null @@ -1,80 +0,0 @@ -id(); - - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists(\'product_details\'); - } -} -'; diff --git a/tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_migration_file_with_model__1.php b/tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_migration_file_with_model__1.php deleted file mode 100644 index a4d625b66..000000000 --- a/tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_migration_file_with_model__1.php +++ /dev/null @@ -1,33 +0,0 @@ -id(); - - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists(\'posts\'); - } -} -'; diff --git a/tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_migration_file_with_model_using_shortcut_option__1.php b/tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_migration_file_with_model_using_shortcut_option__1.php deleted file mode 100644 index a4d625b66..000000000 --- a/tests/Commands/__snapshots__/ModelMakeCommandTest__it_generates_migration_file_with_model_using_shortcut_option__1.php +++ /dev/null @@ -1,33 +0,0 @@ -id(); - - $table->timestamps(); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists(\'posts\'); - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleDeleteCommandTest__it_deletes_modules_from_status_file__1.php b/tests/Commands/__snapshots__/ModuleDeleteCommandTest__it_deletes_modules_from_status_file__1.php deleted file mode 100644 index 17552d87f..000000000 --- a/tests/Commands/__snapshots__/ModuleDeleteCommandTest__it_deletes_modules_from_status_file__1.php +++ /dev/null @@ -1,3 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, \'Database/Migrations\')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, \'Config/config.php\') => config_path($this->moduleNameLower . \'.php\'), - ], \'config\'); - $this->mergeConfigFrom( - module_path($this->moduleName, \'Config/config.php\'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path(\'views/modules/\' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, \'Resources/views\'); - - $this->publishes([ - $sourcePath => $viewPath - ], [\'views\', $this->moduleNameLower . \'-module-views\']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path(\'lang/modules/\' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, \'Resources/lang\'), $this->moduleNameLower); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\\Config::get(\'view.paths\') as $path) { - if (is_dir($path . \'/modules/\' . $this->moduleNameLower)) { - $paths[] = $path . \'/modules/\' . $this->moduleNameLower; - } - } - return $paths; - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__1.txt b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__1.txt deleted file mode 100644 index a395df1e7..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__1.txt +++ /dev/null @@ -1,114 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'), - ], 'config'); - $this->mergeConfigFrom( - module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path('views/modules/' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, 'Resources/views'); - - $this->publishes([ - $sourcePath => $viewPath - ], ['views', $this->moduleNameLower . '-module-views']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path('lang/modules/' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - $this->loadJsonTranslationsFrom($langPath); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang')); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\Config::get('view.paths') as $path) { - if (is_dir($path . '/modules/' . $this->moduleNameLower)) { - $paths[] = $path . '/modules/' . $this->moduleNameLower; - } - } - return $paths; - } -} diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__2.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__2.php deleted file mode 100644 index 4acdf9b01..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__2.php +++ /dev/null @@ -1,61 +0,0 @@ -call("OthersTableSeeder"); - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__4.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__4.php deleted file mode 100644 index 9cd3981be..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_module_with_resources__4.php +++ /dev/null @@ -1,70 +0,0 @@ -mapApiRoutes(); - - $this->mapWebRoutes(); - } - - /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware(\'web\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/web.php\')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. - * - * @return void - */ - protected function mapApiRoutes() - { - Route::prefix(\'api\') - ->middleware(\'api\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/api.php\')); - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_route_file__1.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_route_file__1.php deleted file mode 100644 index 2de6fa801..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_route_file__1.php +++ /dev/null @@ -1,18 +0,0 @@ -get(\'/blog\', function (Request $request) { - return $request->user(); -});'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_route_file__1.txt b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_route_file__1.txt deleted file mode 100644 index dec192862..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_api_route_file__1.txt +++ /dev/null @@ -1,18 +0,0 @@ -get('/blog', function (Request $request) { - return $request->user(); -}); \ No newline at end of file diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_correct_composerjson_file__1.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_correct_composerjson_file__1.php deleted file mode 100644 index d413f1025..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_correct_composerjson_file__1.php +++ /dev/null @@ -1,24 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->registerFactories(); - $this->loadMigrationsFrom(__DIR__ . \'/../Database/Migrations\'); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - // - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - __DIR__.\'/../Config/config.php\' => config_path(\'blog.php\'), - ], \'config\'); - $this->mergeConfigFrom( - __DIR__.\'/../Config/config.php\', \'blog\' - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path(\'views/modules/blog\'); - - $sourcePath = __DIR__.\'/../Resources/views\'; - - $this->publishes([ - $sourcePath => $viewPath - ],\'views\'); - - $this->loadViewsFrom(array_merge(array_map(function ($path) { - return $path . \'/modules/blog\'; - }, \\Config::get(\'view.paths\')), [$sourcePath]), \'blog\'); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path(\'lang/modules/blog\'); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, \'blog\'); - } else { - $this->loadTranslationsFrom(__DIR__ .\'/../Resources/lang\', \'blog\'); - } - } - - /** - * Register an additional directory of factories. - * - * @return void - */ - public function registerFactories() - { - if (! app()->environment(\'production\')) { - app(Factory::class)->load(__DIR__ . \'/../Database/factories\'); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_files__1.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_files__1.php deleted file mode 100644 index bd6212e6f..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_files__1.php +++ /dev/null @@ -1,14 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, \'Database/Migrations\')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, \'Config/config.php\') => config_path($this->moduleNameLower . \'.php\'), - ], \'config\'); - $this->mergeConfigFrom( - module_path($this->moduleName, \'Config/config.php\'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path(\'views/modules/\' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, \'Resources/views\'); - - $this->publishes([ - $sourcePath => $viewPath - ], [\'views\', $this->moduleNameLower . \'-module-views\']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path(\'lang/modules/\' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, \'Resources/lang\'), $this->moduleNameLower); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\\Config::get(\'view.paths\') as $path) { - if (is_dir($path . \'/modules/\' . $this->moduleNameLower)) { - $paths[] = $path . \'/modules/\' . $this->moduleNameLower; - } - } - return $paths; - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_namespace_using_studly_case__1.txt b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_namespace_using_studly_case__1.txt deleted file mode 100644 index 30379cbc0..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_namespace_using_studly_case__1.txt +++ /dev/null @@ -1,114 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'), - ], 'config'); - $this->mergeConfigFrom( - module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path('views/modules/' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, 'Resources/views'); - - $this->publishes([ - $sourcePath => $viewPath - ], ['views', $this->moduleNameLower . '-module-views']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path('lang/modules/' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - $this->loadJsonTranslationsFrom($langPath); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang')); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\Config::get('view.paths') as $path) { - if (is_dir($path . '/modules/' . $this->moduleNameLower)) { - $paths[] = $path . '/modules/' . $this->moduleNameLower; - } - } - return $paths; - } -} diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__1.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__1.php deleted file mode 100644 index f5c541ede..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__1.php +++ /dev/null @@ -1,113 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, \'Database/Migrations\')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, \'Config/config.php\') => config_path($this->moduleNameLower . \'.php\'), - ], \'config\'); - $this->mergeConfigFrom( - module_path($this->moduleName, \'Config/config.php\'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path(\'views/modules/\' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, \'Resources/views\'); - - $this->publishes([ - $sourcePath => $viewPath - ], [\'views\', $this->moduleNameLower . \'-module-views\']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path(\'lang/modules/\' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, \'Resources/lang\'), $this->moduleNameLower); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\\Config::get(\'view.paths\') as $path) { - if (is_dir($path . \'/modules/\' . $this->moduleNameLower)) { - $paths[] = $path . \'/modules/\' . $this->moduleNameLower; - } - } - return $paths; - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__1.txt b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__1.txt deleted file mode 100644 index a395df1e7..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__1.txt +++ /dev/null @@ -1,114 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'), - ], 'config'); - $this->mergeConfigFrom( - module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path('views/modules/' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, 'Resources/views'); - - $this->publishes([ - $sourcePath => $viewPath - ], ['views', $this->moduleNameLower . '-module-views']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path('lang/modules/' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - $this->loadJsonTranslationsFrom($langPath); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang')); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\Config::get('view.paths') as $path) { - if (is_dir($path . '/modules/' . $this->moduleNameLower)) { - $paths[] = $path . '/modules/' . $this->moduleNameLower; - } - } - return $paths; - } -} diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__2.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__2.php deleted file mode 100644 index 285d62595..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__2.php +++ /dev/null @@ -1,80 +0,0 @@ -call("OthersTableSeeder"); - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__4.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__4.php deleted file mode 100644 index 9cd3981be..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_module_resources__4.php +++ /dev/null @@ -1,70 +0,0 @@ -mapApiRoutes(); - - $this->mapWebRoutes(); - } - - /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware(\'web\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/web.php\')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. - * - * @return void - */ - protected function mapApiRoutes() - { - Route::prefix(\'api\') - ->middleware(\'api\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/api.php\')); - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_route_file__1.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_route_file__1.php deleted file mode 100644 index af9b3987a..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_route_file__1.php +++ /dev/null @@ -1,4 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, \'Database/Migrations\')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, \'Config/config.php\') => config_path($this->moduleNameLower . \'.php\'), - ], \'config\'); - $this->mergeConfigFrom( - module_path($this->moduleName, \'Config/config.php\'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path(\'views/modules/\' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, \'Resources/views\'); - - $this->publishes([ - $sourcePath => $viewPath - ], [\'views\', $this->moduleNameLower . \'-module-views\']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path(\'lang/modules/\' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, \'Resources/lang\'), $this->moduleNameLower); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\\Config::get(\'view.paths\') as $path) { - if (is_dir($path . \'/modules/\' . $this->moduleNameLower)) { - $paths[] = $path . \'/modules/\' . $this->moduleNameLower; - } - } - return $paths; - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__1.txt b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__1.txt deleted file mode 100644 index a395df1e7..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__1.txt +++ /dev/null @@ -1,114 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'), - ], 'config'); - $this->mergeConfigFrom( - module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path('views/modules/' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, 'Resources/views'); - - $this->publishes([ - $sourcePath => $viewPath - ], ['views', $this->moduleNameLower . '-module-views']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path('lang/modules/' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - $this->loadJsonTranslationsFrom($langPath); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang')); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\Config::get('view.paths') as $path) { - if (is_dir($path . '/modules/' . $this->moduleNameLower)) { - $paths[] = $path . '/modules/' . $this->moduleNameLower; - } - } - return $paths; - } -} diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__2.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__2.php deleted file mode 100644 index ac5268910..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__2.php +++ /dev/null @@ -1,80 +0,0 @@ -call("OthersTableSeeder"); - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__4.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__4.php deleted file mode 100644 index 9cd3981be..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources__4.php +++ /dev/null @@ -1,70 +0,0 @@ -mapApiRoutes(); - - $this->mapWebRoutes(); - } - - /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware(\'web\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/web.php\')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. - * - * @return void - */ - protected function mapApiRoutes() - { - Route::prefix(\'api\') - ->middleware(\'api\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/api.php\')); - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__1.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__1.php deleted file mode 100644 index f5c541ede..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__1.php +++ /dev/null @@ -1,113 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, \'Database/Migrations\')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, \'Config/config.php\') => config_path($this->moduleNameLower . \'.php\'), - ], \'config\'); - $this->mergeConfigFrom( - module_path($this->moduleName, \'Config/config.php\'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path(\'views/modules/\' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, \'Resources/views\'); - - $this->publishes([ - $sourcePath => $viewPath - ], [\'views\', $this->moduleNameLower . \'-module-views\']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path(\'lang/modules/\' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, \'Resources/lang\'), $this->moduleNameLower); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\\Config::get(\'view.paths\') as $path) { - if (is_dir($path . \'/modules/\' . $this->moduleNameLower)) { - $paths[] = $path . \'/modules/\' . $this->moduleNameLower; - } - } - return $paths; - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt deleted file mode 100644 index a395df1e7..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__1.txt +++ /dev/null @@ -1,114 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'), - ], 'config'); - $this->mergeConfigFrom( - module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path('views/modules/' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, 'Resources/views'); - - $this->publishes([ - $sourcePath => $viewPath - ], ['views', $this->moduleNameLower . '-module-views']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path('lang/modules/' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - $this->loadJsonTranslationsFrom($langPath); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang')); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\Config::get('view.paths') as $path) { - if (is_dir($path . '/modules/' . $this->moduleNameLower)) { - $paths[] = $path . '/modules/' . $this->moduleNameLower; - } - } - return $paths; - } -} diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__2.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__2.php deleted file mode 100644 index ac5268910..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__2.php +++ /dev/null @@ -1,80 +0,0 @@ -call("OthersTableSeeder"); - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__4.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__4.php deleted file mode 100644 index 9cd3981be..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_module_with_resources_when_adding_more_than_one_option__4.php +++ /dev/null @@ -1,70 +0,0 @@ -mapApiRoutes(); - - $this->mapWebRoutes(); - } - - /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware(\'web\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/web.php\')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. - * - * @return void - */ - protected function mapApiRoutes() - { - Route::prefix(\'api\') - ->middleware(\'api\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/api.php\')); - } -} -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_route_file__1.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_route_file__1.php deleted file mode 100644 index ac0affec8..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generates_web_route_file__1.php +++ /dev/null @@ -1,17 +0,0 @@ -group(function() { - Route::get(\'/\', \'BlogController@index\'); -}); -'; diff --git a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generes_module_with_new_provider_location__1.php b/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generes_module_with_new_provider_location__1.php deleted file mode 100644 index 080ee490e..000000000 --- a/tests/Commands/__snapshots__/ModuleMakeCommandTest__it_generes_module_with_new_provider_location__1.php +++ /dev/null @@ -1,14 +0,0 @@ -line(\'The introduction to the notification.\') - ->action(\'Notification Action\', \'https://laravel.com\') - ->line(\'Thank you for using our application!\'); - } - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) - { - return [ - // - ]; - } -} -'; diff --git a/tests/Commands/__snapshots__/NotificationMakeCommandTest__it_can_change_the_default_namespace_specific__1.php b/tests/Commands/__snapshots__/NotificationMakeCommandTest__it_can_change_the_default_namespace_specific__1.php deleted file mode 100644 index bfdcb789b..000000000 --- a/tests/Commands/__snapshots__/NotificationMakeCommandTest__it_can_change_the_default_namespace_specific__1.php +++ /dev/null @@ -1,62 +0,0 @@ -line(\'The introduction to the notification.\') - ->action(\'Notification Action\', \'https://laravel.com\') - ->line(\'Thank you for using our application!\'); - } - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) - { - return [ - // - ]; - } -} -'; diff --git a/tests/Commands/__snapshots__/NotificationMakeCommandTest__it_generated_correct_file_with_content__1.php b/tests/Commands/__snapshots__/NotificationMakeCommandTest__it_generated_correct_file_with_content__1.php deleted file mode 100644 index 2bf33e256..000000000 --- a/tests/Commands/__snapshots__/NotificationMakeCommandTest__it_generated_correct_file_with_content__1.php +++ /dev/null @@ -1,62 +0,0 @@ -line(\'The introduction to the notification.\') - ->action(\'Notification Action\', \'https://laravel.com\') - ->line(\'Thank you for using our application!\'); - } - - /** - * Get the array representation of the notification. - * - * @param mixed $notifiable - * @return array - */ - public function toArray($notifiable) - { - return [ - // - ]; - } -} -'; diff --git a/tests/Commands/__snapshots__/PolicyMakeCommandTest__it_can_change_the_default_namespace__1.php b/tests/Commands/__snapshots__/PolicyMakeCommandTest__it_can_change_the_default_namespace__1.php deleted file mode 100644 index bacc4f1c3..000000000 --- a/tests/Commands/__snapshots__/PolicyMakeCommandTest__it_can_change_the_default_namespace__1.php +++ /dev/null @@ -1,21 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, \'Database/Migrations\')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, \'Config/config.php\') => config_path($this->moduleNameLower . \'.php\'), - ], \'config\'); - $this->mergeConfigFrom( - module_path($this->moduleName, \'Config/config.php\'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path(\'views/modules/\' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, \'Resources/views\'); - - $this->publishes([ - $sourcePath => $viewPath - ], [\'views\', $this->moduleNameLower . \'-module-views\']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path(\'lang/modules/\' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, \'Resources/lang\'), $this->moduleNameLower); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\\Config::get(\'view.paths\') as $path) { - if (is_dir($path . \'/modules/\' . $this->moduleNameLower)) { - $paths[] = $path . \'/modules/\' . $this->moduleNameLower; - } - } - return $paths; - } -} -'; diff --git a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_change_the_default_namespace__1.txt b/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_change_the_default_namespace__1.txt deleted file mode 100644 index 9bd8d748f..000000000 --- a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_change_the_default_namespace__1.txt +++ /dev/null @@ -1,114 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'), - ], 'config'); - $this->mergeConfigFrom( - module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path('views/modules/' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, 'Resources/views'); - - $this->publishes([ - $sourcePath => $viewPath - ], ['views', $this->moduleNameLower . '-module-views']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path('lang/modules/' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - $this->loadJsonTranslationsFrom($langPath); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang')); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\Config::get('view.paths') as $path) { - if (is_dir($path . '/modules/' . $this->moduleNameLower)) { - $paths[] = $path . '/modules/' . $this->moduleNameLower; - } - } - return $paths; - } -} diff --git a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_change_the_default_namespace_specific__1.php b/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_change_the_default_namespace_specific__1.php deleted file mode 100644 index a577c2600..000000000 --- a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_change_the_default_namespace_specific__1.php +++ /dev/null @@ -1,113 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, \'Database/Migrations\')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, \'Config/config.php\') => config_path($this->moduleNameLower . \'.php\'), - ], \'config\'); - $this->mergeConfigFrom( - module_path($this->moduleName, \'Config/config.php\'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path(\'views/modules/\' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, \'Resources/views\'); - - $this->publishes([ - $sourcePath => $viewPath - ], [\'views\', $this->moduleNameLower . \'-module-views\']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path(\'lang/modules/\' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, \'Resources/lang\'), $this->moduleNameLower); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\\Config::get(\'view.paths\') as $path) { - if (is_dir($path . \'/modules/\' . $this->moduleNameLower)) { - $paths[] = $path . \'/modules/\' . $this->moduleNameLower; - } - } - return $paths; - } -} -'; diff --git a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt b/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt deleted file mode 100644 index 9bd8d748f..000000000 --- a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_change_the_default_namespace_specific__1.txt +++ /dev/null @@ -1,114 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'), - ], 'config'); - $this->mergeConfigFrom( - module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path('views/modules/' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, 'Resources/views'); - - $this->publishes([ - $sourcePath => $viewPath - ], ['views', $this->moduleNameLower . '-module-views']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path('lang/modules/' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - $this->loadJsonTranslationsFrom($langPath); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang')); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\Config::get('view.paths') as $path) { - if (is_dir($path . '/modules/' . $this->moduleNameLower)) { - $paths[] = $path . '/modules/' . $this->moduleNameLower; - } - } - return $paths; - } -} diff --git a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_have_custom_migration_resources_location_paths__1.php b/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_have_custom_migration_resources_location_paths__1.php deleted file mode 100644 index 40f52c705..000000000 --- a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_have_custom_migration_resources_location_paths__1.php +++ /dev/null @@ -1,113 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, \'migrations\')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, \'Config/config.php\') => config_path($this->moduleNameLower . \'.php\'), - ], \'config\'); - $this->mergeConfigFrom( - module_path($this->moduleName, \'Config/config.php\'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path(\'views/modules/\' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, \'Resources/views\'); - - $this->publishes([ - $sourcePath => $viewPath - ], [\'views\', $this->moduleNameLower . \'-module-views\']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path(\'lang/modules/\' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, \'Resources/lang\'), $this->moduleNameLower); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\\Config::get(\'view.paths\') as $path) { - if (is_dir($path . \'/modules/\' . $this->moduleNameLower)) { - $paths[] = $path . \'/modules/\' . $this->moduleNameLower; - } - } - return $paths; - } -} -'; diff --git a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_have_custom_migration_resources_location_paths__1.txt b/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_have_custom_migration_resources_location_paths__1.txt deleted file mode 100644 index a5e94c436..000000000 --- a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_can_have_custom_migration_resources_location_paths__1.txt +++ /dev/null @@ -1,114 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'migrations')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'), - ], 'config'); - $this->mergeConfigFrom( - module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path('views/modules/' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, 'Resources/views'); - - $this->publishes([ - $sourcePath => $viewPath - ], ['views', $this->moduleNameLower . '-module-views']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path('lang/modules/' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - $this->loadJsonTranslationsFrom($langPath); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang')); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\Config::get('view.paths') as $path) { - if (is_dir($path . '/modules/' . $this->moduleNameLower)) { - $paths[] = $path . '/modules/' . $this->moduleNameLower; - } - } - return $paths; - } -} diff --git a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_generated_correct_file_with_content__1.php b/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_generated_correct_file_with_content__1.php deleted file mode 100644 index bfeedbc16..000000000 --- a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_generated_correct_file_with_content__1.php +++ /dev/null @@ -1,29 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, \'Database/Migrations\')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, \'Config/config.php\') => config_path($this->moduleNameLower . \'.php\'), - ], \'config\'); - $this->mergeConfigFrom( - module_path($this->moduleName, \'Config/config.php\'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path(\'views/modules/\' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, \'Resources/views\'); - - $this->publishes([ - $sourcePath => $viewPath - ], [\'views\', $this->moduleNameLower . \'-module-views\']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path(\'lang/modules/\' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, \'Resources/lang\'), $this->moduleNameLower); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\\Config::get(\'view.paths\') as $path) { - if (is_dir($path . \'/modules/\' . $this->moduleNameLower)) { - $paths[] = $path . \'/modules/\' . $this->moduleNameLower; - } - } - return $paths; - } -} -'; diff --git a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_generates_a_master_service_provider_with_resource_loading__1.txt b/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_generates_a_master_service_provider_with_resource_loading__1.txt deleted file mode 100644 index a395df1e7..000000000 --- a/tests/Commands/__snapshots__/ProviderMakeCommandTest__it_generates_a_master_service_provider_with_resource_loading__1.txt +++ /dev/null @@ -1,114 +0,0 @@ -registerTranslations(); - $this->registerConfig(); - $this->registerViews(); - $this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations')); - } - - /** - * Register the service provider. - * - * @return void - */ - public function register() - { - $this->app->register(RouteServiceProvider::class); - } - - /** - * Register config. - * - * @return void - */ - protected function registerConfig() - { - $this->publishes([ - module_path($this->moduleName, 'Config/config.php') => config_path($this->moduleNameLower . '.php'), - ], 'config'); - $this->mergeConfigFrom( - module_path($this->moduleName, 'Config/config.php'), $this->moduleNameLower - ); - } - - /** - * Register views. - * - * @return void - */ - public function registerViews() - { - $viewPath = resource_path('views/modules/' . $this->moduleNameLower); - - $sourcePath = module_path($this->moduleName, 'Resources/views'); - - $this->publishes([ - $sourcePath => $viewPath - ], ['views', $this->moduleNameLower . '-module-views']); - - $this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower); - } - - /** - * Register translations. - * - * @return void - */ - public function registerTranslations() - { - $langPath = resource_path('lang/modules/' . $this->moduleNameLower); - - if (is_dir($langPath)) { - $this->loadTranslationsFrom($langPath, $this->moduleNameLower); - $this->loadJsonTranslationsFrom($langPath); - } else { - $this->loadTranslationsFrom(module_path($this->moduleName, 'Resources/lang'), $this->moduleNameLower); - $this->loadJsonTranslationsFrom(module_path($this->moduleName, 'Resources/lang')); - } - } - - /** - * Get the services provided by the provider. - * - * @return array - */ - public function provides() - { - return []; - } - - private function getPublishableViewPaths(): array - { - $paths = []; - foreach (\Config::get('view.paths') as $path) { - if (is_dir($path . '/modules/' . $this->moduleNameLower)) { - $paths[] = $path . '/modules/' . $this->moduleNameLower; - } - } - return $paths; - } -} diff --git a/tests/Commands/__snapshots__/RequestMakeCommandTest__it_can_change_the_default_namespace__1.php b/tests/Commands/__snapshots__/RequestMakeCommandTest__it_can_change_the_default_namespace__1.php deleted file mode 100644 index aaeae44be..000000000 --- a/tests/Commands/__snapshots__/RequestMakeCommandTest__it_can_change_the_default_namespace__1.php +++ /dev/null @@ -1,31 +0,0 @@ -mapApiRoutes(); - - $this->mapWebRoutes(); - } - - /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware(\'web\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/web.php\')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. - * - * @return void - */ - protected function mapApiRoutes() - { - Route::prefix(\'api\') - ->middleware(\'api\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/api.php\')); - } -} -'; diff --git a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_change_the_default_namespace__1.php b/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_change_the_default_namespace__1.php deleted file mode 100644 index d714134bb..000000000 --- a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_change_the_default_namespace__1.php +++ /dev/null @@ -1,70 +0,0 @@ -mapApiRoutes(); - - $this->mapWebRoutes(); - } - - /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware(\'web\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/web.php\')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. - * - * @return void - */ - protected function mapApiRoutes() - { - Route::prefix(\'api\') - ->middleware(\'api\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/api.php\')); - } -} -'; diff --git a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_change_the_default_namespace_specific__1.php b/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_change_the_default_namespace_specific__1.php deleted file mode 100644 index d714134bb..000000000 --- a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_change_the_default_namespace_specific__1.php +++ /dev/null @@ -1,70 +0,0 @@ -mapApiRoutes(); - - $this->mapWebRoutes(); - } - - /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware(\'web\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/web.php\')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. - * - * @return void - */ - protected function mapApiRoutes() - { - Route::prefix(\'api\') - ->middleware(\'api\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/api.php\')); - } -} -'; diff --git a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_overwrite_file__1.php b/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_overwrite_file__1.php deleted file mode 100644 index 0dcae567e..000000000 --- a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_overwrite_file__1.php +++ /dev/null @@ -1,70 +0,0 @@ -mapApiRoutes(); - - $this->mapWebRoutes(); - } - - /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware(\'web\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/SuperRoutes/web.php\')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. - * - * @return void - */ - protected function mapApiRoutes() - { - Route::prefix(\'api\') - ->middleware(\'api\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/api.php\')); - } -} -'; diff --git a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_overwrite_file__1.txt b/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_overwrite_file__1.txt deleted file mode 100644 index 99fb6b8d6..000000000 --- a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_overwrite_file__1.txt +++ /dev/null @@ -1,69 +0,0 @@ -mapApiRoutes(); - - $this->mapWebRoutes(); - } - - /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware('web') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/SuperRoutes/web.php')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. - * - * @return void - */ - protected function mapApiRoutes() - { - Route::prefix('api') - ->middleware('api') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/api.php')); - } -} diff --git a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_overwrite_route_file_names__1.php b/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_overwrite_route_file_names__1.php deleted file mode 100644 index a97f9af62..000000000 --- a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_overwrite_route_file_names__1.php +++ /dev/null @@ -1,70 +0,0 @@ -mapApiRoutes(); - - $this->mapWebRoutes(); - } - - /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware(\'web\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/SuperRoutes/web.php\')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. - * - * @return void - */ - protected function mapApiRoutes() - { - Route::prefix(\'api\') - ->middleware(\'api\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/SuperRoutes/api.php\')); - } -} -'; diff --git a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_overwrite_route_file_names__1.txt b/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_overwrite_route_file_names__1.txt deleted file mode 100644 index 4caf69906..000000000 --- a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_can_overwrite_route_file_names__1.txt +++ /dev/null @@ -1,69 +0,0 @@ -mapApiRoutes(); - - $this->mapWebRoutes(); - } - - /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware('web') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/SuperRoutes/web.php')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. - * - * @return void - */ - protected function mapApiRoutes() - { - Route::prefix('api') - ->middleware('api') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/SuperRoutes/api.php')); - } -} diff --git a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_generated_correct_file_with_content__1.php b/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_generated_correct_file_with_content__1.php deleted file mode 100644 index 9cd3981be..000000000 --- a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_generated_correct_file_with_content__1.php +++ /dev/null @@ -1,70 +0,0 @@ -mapApiRoutes(); - - $this->mapWebRoutes(); - } - - /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware(\'web\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/web.php\')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. - * - * @return void - */ - protected function mapApiRoutes() - { - Route::prefix(\'api\') - ->middleware(\'api\') - ->namespace($this->moduleNamespace) - ->group(module_path(\'Blog\', \'/Routes/api.php\')); - } -} -'; diff --git a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_generated_correct_file_with_content__1.txt b/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_generated_correct_file_with_content__1.txt deleted file mode 100644 index 288050277..000000000 --- a/tests/Commands/__snapshots__/RouteProviderMakeCommandTest__it_generated_correct_file_with_content__1.txt +++ /dev/null @@ -1,69 +0,0 @@ -mapApiRoutes(); - - $this->mapWebRoutes(); - } - - /** - * Define the "web" routes for the application. - * - * These routes all receive session state, CSRF protection, etc. - * - * @return void - */ - protected function mapWebRoutes() - { - Route::middleware('web') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/web.php')); - } - - /** - * Define the "api" routes for the application. - * - * These routes are typically stateless. - * - * @return void - */ - protected function mapApiRoutes() - { - Route::prefix('api') - ->middleware('api') - ->namespace($this->moduleNamespace) - ->group(module_path('Blog', '/Routes/api.php')); - } -} diff --git a/tests/Commands/__snapshots__/RuleMakeCommandTest__it_can_change_the_default_namespace__1.php b/tests/Commands/__snapshots__/RuleMakeCommandTest__it_can_change_the_default_namespace__1.php deleted file mode 100644 index 580fb550c..000000000 --- a/tests/Commands/__snapshots__/RuleMakeCommandTest__it_can_change_the_default_namespace__1.php +++ /dev/null @@ -1,41 +0,0 @@ -get(\'/\'); - - $response->assertStatus(200); - } -} -'; diff --git a/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_feature_namespace_specific__1.php b/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_feature_namespace_specific__1.php deleted file mode 100644 index fe9e1d912..000000000 --- a/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_feature_namespace_specific__1.php +++ /dev/null @@ -1,23 +0,0 @@ -get(\'/\'); - - $response->assertStatus(200); - } -} -'; diff --git a/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_unit_namespace__1.php b/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_unit_namespace__1.php deleted file mode 100644 index d179b47c3..000000000 --- a/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_unit_namespace__1.php +++ /dev/null @@ -1,21 +0,0 @@ -assertTrue(true); - } -} -'; diff --git a/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_unit_namespace_specific__1.php b/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_unit_namespace_specific__1.php deleted file mode 100644 index d179b47c3..000000000 --- a/tests/Commands/__snapshots__/TestMakeCommandTest__it_can_change_the_default_unit_namespace_specific__1.php +++ /dev/null @@ -1,21 +0,0 @@ -assertTrue(true); - } -} -'; diff --git a/tests/Commands/__snapshots__/TestMakeCommandTest__it_generated_correct_feature_file_with_content__1.php b/tests/Commands/__snapshots__/TestMakeCommandTest__it_generated_correct_feature_file_with_content__1.php deleted file mode 100644 index 771d3cdeb..000000000 --- a/tests/Commands/__snapshots__/TestMakeCommandTest__it_generated_correct_feature_file_with_content__1.php +++ /dev/null @@ -1,23 +0,0 @@ -get(\'/\'); - - $response->assertStatus(200); - } -} -'; diff --git a/tests/Commands/__snapshots__/TestMakeCommandTest__it_generated_correct_unit_file_with_content__1.php b/tests/Commands/__snapshots__/TestMakeCommandTest__it_generated_correct_unit_file_with_content__1.php deleted file mode 100644 index c9f491c82..000000000 --- a/tests/Commands/__snapshots__/TestMakeCommandTest__it_generated_correct_unit_file_with_content__1.php +++ /dev/null @@ -1,21 +0,0 @@ -assertTrue(true); - } -} -'; diff --git a/tests/ContractsServiceProviderTest.php b/tests/Contracts/RepositoryInterfaceTest.php similarity index 51% rename from tests/ContractsServiceProviderTest.php rename to tests/Contracts/RepositoryInterfaceTest.php index cbd4f0e5c..1ce60cd52 100644 --- a/tests/ContractsServiceProviderTest.php +++ b/tests/Contracts/RepositoryInterfaceTest.php @@ -1,14 +1,14 @@ assertInstanceOf(LaravelFileRepository::class, app(RepositoryInterface::class)); } diff --git a/tests/ModuleFacadeTest.php b/tests/Facades/ModuleFacadeTest.php similarity index 68% rename from tests/ModuleFacadeTest.php rename to tests/Facades/ModuleFacadeTest.php index 5bd37a56e..dedd37ba5 100644 --- a/tests/ModuleFacadeTest.php +++ b/tests/Facades/ModuleFacadeTest.php @@ -1,21 +1,20 @@ assertTrue(is_array($modules)); } - /** @test */ - public function it_creates_macros_via_facade() + public function test_it_creates_macros_via_facade() { $modules = Module::macro('testMacro', function () { return true; @@ -24,8 +23,7 @@ public function it_creates_macros_via_facade() $this->assertTrue(Module::hasMacro('testMacro')); } - /** @test */ - public function it_calls_macros_via_facade() + public function test_it_calls_macros_via_facade() { $modules = Module::macro('testMacro', function () { return 'a value'; diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php index eaf7e790e..f6299d152 100644 --- a/tests/HelpersTest.php +++ b/tests/HelpersTest.php @@ -3,6 +3,7 @@ namespace Nwidart\Modules\Tests; use Illuminate\Support\Str; +use Nwidart\Modules\Contracts\RepositoryInterface; class HelpersTest extends BaseTestCase { @@ -10,6 +11,7 @@ class HelpersTest extends BaseTestCase * @var \Illuminate\Filesystem\Filesystem */ private $finder; + /** * @var string */ @@ -18,25 +20,23 @@ class HelpersTest extends BaseTestCase public function setUp(): void { parent::setUp(); - $this->modulePath = base_path('modules/Blog'); $this->finder = $this->app['files']; - $this->artisan('module:make', ['name' => ['Blog']]); + $this->createModule(); + $this->modulePath = $this->getModuleAppPath(); } public function tearDown(): void { - $this->finder->deleteDirectory($this->modulePath); + $this->app[RepositoryInterface::class]->delete('Blog'); parent::tearDown(); } - /** @test */ - public function it_finds_the_module_path() + public function test_it_finds_the_module_path() { $this->assertTrue(Str::contains(module_path('Blog'), 'modules/Blog')); } - /** @test */ - public function it_can_bind_a_relative_path_to_module_path() + public function test_it_can_bind_a_relative_path_to_module_path() { $this->assertTrue(Str::contains(module_path('Blog', 'config/config.php'), 'modules/Blog/config/config.php')); } diff --git a/tests/JsonTest.php b/tests/JsonTest.php index 2cfe521d6..955a37a27 100644 --- a/tests/JsonTest.php +++ b/tests/JsonTest.php @@ -15,31 +15,28 @@ class JsonTest extends BaseTestCase public function setUp(): void { parent::setUp(); - $path = __DIR__ . '/stubs/valid/module.json'; + $path = __DIR__.'/stubs/valid/module.json'; $this->json = new Json($path, $this->app['files']); } - /** @test */ - public function it_gets_the_file_path() + public function test_it_gets_the_file_path() { - $path = __DIR__ . '/stubs/valid/module.json'; + $path = __DIR__.'/stubs/valid/module.json'; $this->assertEquals($path, $this->json->getPath()); } - /** @test */ - public function it_throws_an_exception_with_invalid_json() + public function test_it_throws_an_exception_with_invalid_json() { - $path = __DIR__ . '/stubs/InvalidJsonModule/module.json'; + $path = __DIR__.'/stubs/InvalidJsonModule/module.json'; $this->expectException(InvalidJsonException::class); - $this->expectExceptionMessage('Error processing file: ' . $path . '. Error: Syntax error'); + $this->expectExceptionMessage('Error processing file: '.$path.'. Error: Syntax error'); new Json($path, $this->app['files']); } - /** @test */ - public function it_gets_attributes_from_json_file() + public function test_it_gets_attributes_from_json_file() { $this->assertEquals('Order', $this->json->get('name')); $this->assertEquals('order', $this->json->get('alias')); @@ -50,8 +47,7 @@ public function it_gets_attributes_from_json_file() $this->assertEquals(1, $this->json->get('order')); } - /** @test */ - public function it_reads_attributes_from_magic_get_method() + public function test_it_reads_attributes_from_magic_get_method() { $this->assertEquals('Order', $this->json->name); $this->assertEquals('order', $this->json->alias); @@ -62,27 +58,24 @@ public function it_reads_attributes_from_magic_get_method() $this->assertEquals(1, $this->json->order); } - /** @test */ - public function it_makes_json_class() + public function test_it_makes_json_class() { - $path = __DIR__ . '/stubs/valid/module.json'; + $path = __DIR__.'/stubs/valid/module.json'; $json = Json::make($path, $this->app['files']); $this->assertInstanceOf(Json::class, $json); } - /** @test */ - public function it_sets_a_path() + public function test_it_sets_a_path() { - $path = __DIR__ . '/stubs/valid/module.json'; + $path = __DIR__.'/stubs/valid/module.json'; $this->assertEquals($path, $this->json->getPath()); $this->json->setPath('some/path.json'); $this->assertEquals('some/path.json', $this->json->getPath()); } - /** @test */ - public function it_decodes_json() + public function test_it_decodes_json() { $expected = '{ "name": "Order", @@ -107,16 +100,14 @@ public function it_decodes_json() $this->assertEquals($expected, $this->json->toJsonPretty()); } - /** @test */ - public function it_sets_a_key_value() + public function test_it_sets_a_key_value() { $this->json->set('key', 'value'); $this->assertEquals('value', $this->json->get('key')); } - /** @test */ - public function it_can_be_casted_to_string() + public function test_it_can_be_casted_to_string() { $expected = '{ "name": "Order", @@ -140,6 +131,6 @@ public function it_can_be_casted_to_string() ] } '; - $this->assertEquals($expected, (string)$this->json); + $this->assertEquals($expected, (string) $this->json); } } diff --git a/tests/LaravelFileRepositoryTest.php b/tests/LaravelFileRepositoryTest.php index 9c544672f..4dc0adb72 100644 --- a/tests/LaravelFileRepositoryTest.php +++ b/tests/LaravelFileRepositoryTest.php @@ -32,11 +32,11 @@ public function setUp(): void public function tearDown(): void { $this->activator->reset(); + $this->artisan('module:delete', ['--all' => true, '--force' => true]); parent::tearDown(); } - /** @test */ - public function it_adds_location_to_paths() + public function test_it_adds_location_to_paths() { $this->repository->addLocation('some/path'); @@ -45,106 +45,93 @@ public function it_adds_location_to_paths() $this->assertEquals('some/path', $paths[0]); } - /** @test */ - public function it_returns_a_collection() + public function test_it_returns_a_collection() { - $this->repository->addLocation(__DIR__ . '/stubs/valid'); + $this->repository->addLocation(__DIR__.'/stubs/valid'); $this->assertInstanceOf(Collection::class, $this->repository->toCollection()); $this->assertInstanceOf(Collection::class, $this->repository->collections()); } - /** @test */ - public function it_returns_all_enabled_modules() + public function test_it_returns_all_enabled_modules() { - $this->repository->addLocation(__DIR__ . '/stubs/valid'); + $this->repository->addLocation(__DIR__.'/stubs/valid'); $this->assertCount(0, $this->repository->getByStatus(true)); $this->assertCount(0, $this->repository->allEnabled()); } - /** @test */ - public function it_returns_all_disabled_modules() + public function test_it_returns_all_disabled_modules() { - $this->repository->addLocation(__DIR__ . '/stubs/valid'); + $this->repository->addLocation(__DIR__.'/stubs/valid'); $this->assertCount(2, $this->repository->getByStatus(false)); $this->assertCount(2, $this->repository->allDisabled()); } - /** @test */ - public function it_counts_all_modules() + public function test_it_counts_all_modules() { - $this->repository->addLocation(__DIR__ . '/stubs/valid'); + $this->repository->addLocation(__DIR__.'/stubs/valid'); $this->assertEquals(2, $this->repository->count()); } - /** @test */ - public function it_finds_a_module() + public function test_it_finds_a_module() { - $this->repository->addLocation(__DIR__ . '/stubs/valid'); + $this->repository->addLocation(__DIR__.'/stubs/valid'); $this->assertInstanceOf(Module::class, $this->repository->find('recipe')); } - /** @test */ - public function it_find_or_fail_throws_exception_if_module_not_found() + public function test_it_find_or_fail_throws_exception_if_module_not_found() { $this->expectException(ModuleNotFoundException::class); $this->repository->findOrFail('something'); } - /** @test */ - public function it_finds_the_module_asset_path() + public function test_it_finds_the_module_asset_path() { - $this->repository->addLocation(__DIR__ . '/stubs/valid/Recipe'); + $this->repository->addLocation(__DIR__.'/stubs/valid/Recipe'); $assetPath = $this->repository->assetPath('recipe'); $this->assertEquals(public_path('modules/recipe'), $assetPath); } - /** @test */ - public function it_gets_the_used_storage_path() + public function test_it_gets_the_used_storage_path() { $path = $this->repository->getUsedStoragePath(); $this->assertEquals(storage_path('app/modules/modules.used'), $path); } - /** @test */ - public function it_sets_used_module() + public function test_it_sets_used_module() { - $this->repository->addLocation(__DIR__ . '/stubs/valid'); + $this->repository->addLocation(__DIR__.'/stubs/valid'); $this->repository->setUsed('Recipe'); $this->assertEquals('Recipe', $this->repository->getUsedNow()); } - /** @test */ - public function it_returns_laravel_filesystem() + public function test_it_returns_laravel_filesystem() { $this->assertInstanceOf(Filesystem::class, $this->repository->getFiles()); } - /** @test */ - public function it_gets_the_assets_path() + public function test_it_gets_the_assets_path() { $this->assertEquals(public_path('modules'), $this->repository->getAssetsPath()); } - /** @test */ - public function it_gets_a_specific_module_asset() + public function test_it_gets_a_specific_module_asset() { $path = $this->repository->asset('recipe:test.js'); $this->assertEquals('//localhost/modules/recipe/test.js', $path); } - /** @test */ - public function it_throws_exception_if_module_is_omitted() + public function test_it_throws_exception_if_module_is_omitted() { $this->expectException(InvalidAssetPath::class); $this->expectExceptionMessage('Module name was not specified in asset [test.js].'); @@ -152,70 +139,62 @@ public function it_throws_exception_if_module_is_omitted() $this->repository->asset('test.js'); } - /** @test */ - public function it_can_detect_if_module_is_active() + public function test_it_can_detect_if_module_is_active() { - $this->repository->addLocation(__DIR__ . '/stubs/valid'); + $this->repository->addLocation(__DIR__.'/stubs/valid'); $this->repository->enable('Recipe'); $this->assertTrue($this->repository->isEnabled('Recipe')); } - /** @test */ - public function it_can_detect_if_module_is_inactive() + public function test_it_can_detect_if_module_is_inactive() { - $this->repository->addLocation(__DIR__ . '/stubs/valid'); + $this->repository->addLocation(__DIR__.'/stubs/valid'); $this->repository->isDisabled('Recipe'); $this->assertTrue($this->repository->isDisabled('Recipe')); } - /** @test */ - public function it_can_get_and_set_the_stubs_path() + public function test_it_can_get_and_set_the_stubs_path() { $this->repository->setStubPath('some/stub/path'); $this->assertEquals('some/stub/path', $this->repository->getStubPath()); } - /** @test */ - public function it_gets_the_configured_stubs_path_if_enabled() + public function test_it_gets_the_configured_stubs_path_if_enabled() { $this->app['config']->set('modules.stubs.enabled', true); $this->assertEquals(base_path('vendor/nwidart/laravel-modules/src/Commands/stubs'), $this->repository->getStubPath()); } - /** @test */ - public function it_returns_default_stub_path() + public function test_it_returns_default_stub_path() { $this->assertNull($this->repository->getStubPath()); } - /** @test */ - public function it_can_disabled_a_module() + public function test_it_can_disabled_a_module() { - $this->repository->addLocation(__DIR__ . '/stubs/valid'); + $this->repository->addLocation(__DIR__.'/stubs/valid'); $this->repository->disable('Recipe'); $this->assertTrue($this->repository->isDisabled('Recipe')); } - /** @test */ - public function it_can_enable_a_module() + public function test_it_can_enable_a_module() { - $this->repository->addLocation(__DIR__ . '/stubs/valid'); + $this->repository->addLocation(__DIR__.'/stubs/valid'); $this->repository->enable('Recipe'); $this->assertTrue($this->repository->isEnabled('Recipe')); } - /** @test */ - public function it_can_delete_a_module() + public function test_it_can_delete_a_module() { $this->artisan('module:make', ['name' => ['Blog']]); @@ -224,8 +203,7 @@ public function it_can_delete_a_module() $this->assertFalse(is_dir(base_path('modules/Blog'))); } - /** @test */ - public function it_can_register_macros() + public function test_it_can_register_macros() { Module::macro('registeredMacro', function () { }); @@ -233,20 +211,18 @@ public function it_can_register_macros() $this->assertTrue(Module::hasMacro('registeredMacro')); } - /** @test */ - public function it_does_not_have_unregistered_macros() + public function test_it_does_not_have_unregistered_macros() { $this->assertFalse(Module::hasMacro('unregisteredMacro')); } - /** @test */ - public function it_calls_macros_on_modules() + public function test_it_calls_macros_on_modules() { Module::macro('getReverseName', function () { return strrev($this->getLowerName()); }); - $this->repository->addLocation(__DIR__ . '/stubs/valid'); + $this->repository->addLocation(__DIR__.'/stubs/valid'); $module = $this->repository->find('recipe'); $this->assertEquals('epicer', $module->getReverseName()); diff --git a/tests/LaravelModuleTest.php b/tests/LaravelModuleTest.php index c91452221..dd8878c53 100644 --- a/tests/LaravelModuleTest.php +++ b/tests/LaravelModuleTest.php @@ -5,6 +5,7 @@ use Illuminate\Support\Facades\Event; use Modules\Recipe\Providers\DeferredServiceProvider; use Modules\Recipe\Providers\RecipeServiceProvider; +use Nwidart\Modules\Constants\ModuleEvent; use Nwidart\Modules\Contracts\ActivatorInterface; use Nwidart\Modules\Json; @@ -23,7 +24,7 @@ class LaravelModuleTest extends BaseTestCase public function setUp(): void { parent::setUp(); - $this->module = new TestingModule($this->app, 'Recipe Name', __DIR__ . '/stubs/valid/Recipe'); + $this->module = new TestingModule($this->app, 'Recipe Name', __DIR__.'/stubs/valid/Recipe'); $this->activator = $this->app[ActivatorInterface::class]; } @@ -36,72 +37,63 @@ public function tearDown(): void public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - symlink(__DIR__ . '/stubs/valid', __DIR__ . '/stubs/valid_symlink'); + symlink(__DIR__.'/stubs/valid', __DIR__.'/stubs/valid_symlink'); } public static function tearDownAfterClass(): void { parent::tearDownAfterClass(); - unlink(__DIR__ . '/stubs/valid_symlink'); + unlink(__DIR__.'/stubs/valid_symlink'); } - /** @test */ - public function it_gets_module_name() + public function test_it_gets_module_name() { $this->assertEquals('Recipe Name', $this->module->getName()); } - /** @test */ - public function it_gets_lowercase_module_name() + public function test_it_gets_lowercase_module_name() { $this->assertEquals('recipe name', $this->module->getLowerName()); } - /** @test */ - public function it_gets_studly_name() + public function test_it_gets_studly_name() { $this->assertEquals('RecipeName', $this->module->getStudlyName()); } - /** @test */ - public function it_gets_snake_name() + public function test_it_gets_snake_name() { $this->assertEquals('recipe_name', $this->module->getSnakeName()); } - /** @test */ - public function it_gets_module_description() + public function test_it_gets_module_description() { $this->assertEquals('recipe module', $this->module->getDescription()); } - /** @test */ - public function it_gets_module_path() + public function test_it_gets_module_path() { - $this->assertEquals(__DIR__ . '/stubs/valid/Recipe', $this->module->getPath()); + $this->assertEquals(__DIR__.'/stubs/valid/Recipe', $this->module->getPath()); } - /** @test */ - public function it_gets_module_path_with_symlink() + public function test_it_gets_module_path_with_symlink() { // symlink created in setUpBeforeClass - $this->module = new TestingModule($this->app, 'Recipe Name', __DIR__ . '/stubs/valid_symlink/Recipe'); + $this->module = new TestingModule($this->app, 'Recipe Name', __DIR__.'/stubs/valid_symlink/Recipe'); - $this->assertEquals(__DIR__ . '/stubs/valid_symlink/Recipe', $this->module->getPath()); + $this->assertEquals(__DIR__.'/stubs/valid_symlink/Recipe', $this->module->getPath()); // symlink deleted in tearDownAfterClass } - /** @test */ - public function it_loads_module_translations() + public function test_it_loads_module_translations() { - (new TestingModule($this->app, 'Recipe', __DIR__ . '/stubs/valid/Recipe'))->boot(); + (new TestingModule($this->app, 'Recipe', __DIR__.'/stubs/valid/Recipe'))->boot(); $this->assertEquals('Recipe', trans('recipe::recipes.title.recipes')); } - /** @test */ - public function it_reads_module_json_files() + public function test_it_reads_module_json_files() { $jsonModule = $this->module->json(); $composerJson = $this->module->json('composer.json'); @@ -112,8 +104,7 @@ public function it_reads_module_json_files() $this->assertEquals('asgard-module', $composerJson->get('type')); } - /** @test */ - public function it_reads_key_from_module_json_file_via_helper_method() + public function test_it_reads_key_from_module_json_file_via_helper_method() { $this->assertEquals('Recipe', $this->module->get('name')); $this->assertEquals('0.1', $this->module->get('version')); @@ -121,34 +112,29 @@ public function it_reads_key_from_module_json_file_via_helper_method() $this->assertEquals(['required_module'], $this->module->get('requires')); } - /** @test */ - public function it_reads_key_from_composer_json_file_via_helper_method() + public function test_it_reads_key_from_composer_json_file_via_helper_method() { $this->assertEquals('nwidart/recipe', $this->module->getComposerAttr('name')); } - /** @test */ - public function it_casts_module_to_string() + public function test_it_casts_module_to_string() { $this->assertEquals('RecipeName', (string) $this->module); } - /** @test */ - public function it_module_status_check() + public function test_it_module_status_check() { $this->assertFalse($this->module->isStatus(true)); $this->assertTrue($this->module->isStatus(false)); } - /** @test */ - public function it_checks_module_enabled_status() + public function test_it_checks_module_enabled_status() { $this->assertFalse($this->module->isEnabled()); $this->assertTrue($this->module->isDisabled()); } - /** @test */ - public function it_sets_active_status(): void + public function test_it_sets_active_status(): void { $this->module->setActive(true); $this->assertTrue($this->module->isEnabled()); @@ -156,30 +142,27 @@ public function it_sets_active_status(): void $this->assertFalse($this->module->isEnabled()); } - /** @test */ - public function it_fires_events_when_module_is_enabled() + public function test_it_fires_events_when_module_is_enabled() { Event::fake(); $this->module->enable(); - Event::assertDispatched(sprintf('modules.%s.enabling', $this->module->getLowerName())); - Event::assertDispatched(sprintf('modules.%s.enabled', $this->module->getLowerName())); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::ENABLING, $this->module->getLowerName())); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::ENABLED, $this->module->getLowerName())); } - /** @test */ - public function it_fires_events_when_module_is_disabled() + public function test_it_fires_events_when_module_is_disabled() { Event::fake(); $this->module->disable(); - Event::assertDispatched(sprintf('modules.%s.disabling', $this->module->getLowerName())); - Event::assertDispatched(sprintf('modules.%s.disabled', $this->module->getLowerName())); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::DISABLING, $this->module->getLowerName())); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::DISABLED, $this->module->getLowerName())); } - /** @test */ - public function it_has_a_good_providers_manifest_path() + public function test_it_has_a_good_providers_manifest_path() { $this->assertEquals( $this->app->bootstrapPath("cache/{$this->module->getSnakeName()}_module.php"), @@ -187,8 +170,7 @@ public function it_has_a_good_providers_manifest_path() ); } - /** @test */ - public function it_makes_a_manifest_file_when_providers_are_loaded() + public function test_it_makes_a_manifest_file_when_providers_are_loaded() { $cachedServicesPath = $this->module->getCachedServicesPath(); @@ -205,15 +187,13 @@ public function it_makes_a_manifest_file_when_providers_are_loaded() RecipeServiceProvider::class, DeferredServiceProvider::class, ], - 'eager' => [RecipeServiceProvider::class], - 'deferred' => ['deferred' => DeferredServiceProvider::class], - 'when' => - [DeferredServiceProvider::class => []], + 'eager' => [RecipeServiceProvider::class], + 'deferred' => ['deferred' => DeferredServiceProvider::class], + 'when' => [DeferredServiceProvider::class => []], ], $manifest); } - /** @test */ - public function it_can_load_a_deferred_provider() + public function test_it_can_load_a_deferred_provider() { @unlink($this->module->getCachedServicesPath()); @@ -230,6 +210,11 @@ public function it_can_load_a_deferred_provider() $this->assertEquals('bar', app('foo')); } + + public function test_it_can_load_assets_is_empty_when_no_manifest_exists() + { + $this->assertEquals([], $this->module->getAssets()); + } } class TestingModule extends \Nwidart\Modules\Laravel\Module diff --git a/tests/LaravelModulesServiceProviderTest.php b/tests/LaravelModulesServiceProviderTest.php index 4cb35c11c..45cf67900 100644 --- a/tests/LaravelModulesServiceProviderTest.php +++ b/tests/LaravelModulesServiceProviderTest.php @@ -8,21 +8,18 @@ class LaravelModulesServiceProviderTest extends BaseTestCase { - /** @test */ - public function it_binds_modules_key_to_repository_class() + public function test_it_binds_modules_key_to_repository_class() { $this->assertInstanceOf(RepositoryInterface::class, app(RepositoryInterface::class)); $this->assertInstanceOf(RepositoryInterface::class, app('modules')); } - /** @test */ - public function it_binds_activator_to_activator_class() + public function test_it_binds_activator_to_activator_class() { $this->assertInstanceOf(ActivatorInterface::class, app(ActivatorInterface::class)); } - /** @test */ - public function it_throws_exception_if_config_is_invalid() + public function test_it_throws_exception_if_config_is_invalid() { $this->expectException(InvalidActivatorClass::class); diff --git a/tests/LumenModuleTest.php b/tests/LumenModuleTest.php index 73ab59522..1dc142ea6 100644 --- a/tests/LumenModuleTest.php +++ b/tests/LumenModuleTest.php @@ -3,6 +3,7 @@ namespace Nwidart\Modules\Tests; use Illuminate\Support\Facades\Event; +use Nwidart\Modules\Constants\ModuleEvent; use Nwidart\Modules\Contracts\ActivatorInterface; use Nwidart\Modules\Json; @@ -21,7 +22,7 @@ class LumenModuleTest extends BaseTestCase public function setUp(): void { parent::setUp(); - $this->module = new LumenTestingModule($this->app, 'Recipe Name', __DIR__ . '/stubs/valid/Recipe'); + $this->module = new LumenTestingModule($this->app, 'Recipe Name', __DIR__.'/stubs/valid/Recipe'); $this->activator = $this->app[ActivatorInterface::class]; } @@ -31,51 +32,43 @@ public function tearDown(): void parent::tearDown(); } - /** @test */ - public function it_gets_module_name() + public function test_it_gets_module_name() { $this->assertEquals('Recipe Name', $this->module->getName()); } - /** @test */ - public function it_gets_lowercase_module_name() + public function test_it_gets_lowercase_module_name() { $this->assertEquals('recipe name', $this->module->getLowerName()); } - /** @test */ - public function it_gets_studly_name() + public function test_it_gets_studly_name() { $this->assertEquals('RecipeName', $this->module->getStudlyName()); } - /** @test */ - public function it_gets_snake_name() + public function test_it_gets_snake_name() { $this->assertEquals('recipe_name', $this->module->getSnakeName()); } - /** @test */ - public function it_gets_module_description() + public function test_it_gets_module_description() { $this->assertEquals('recipe module', $this->module->getDescription()); } - /** @test */ - public function it_gets_module_path() + public function test_it_gets_module_path() { - $this->assertEquals(__DIR__ . '/stubs/valid/Recipe', $this->module->getPath()); + $this->assertEquals(__DIR__.'/stubs/valid/Recipe', $this->module->getPath()); } - /** @test */ - public function it_loads_module_translations() + public function test_it_loads_module_translations() { - (new LumenTestingModule($this->app, 'Recipe', __DIR__ . '/stubs/valid/Recipe'))->boot(); + (new LumenTestingModule($this->app, 'Recipe', __DIR__.'/stubs/valid/Recipe'))->boot(); $this->assertEquals('Recipe', trans('recipe::recipes.title.recipes')); } - /** @test */ - public function it_reads_module_json_files() + public function test_it_reads_module_json_files() { $jsonModule = $this->module->json(); $composerJson = $this->module->json('composer.json'); @@ -86,8 +79,7 @@ public function it_reads_module_json_files() $this->assertEquals('asgard-module', $composerJson->get('type')); } - /** @test */ - public function it_reads_key_from_module_json_file_via_helper_method() + public function test_it_reads_key_from_module_json_file_via_helper_method() { $this->assertEquals('Recipe', $this->module->get('name')); $this->assertEquals('0.1', $this->module->get('version')); @@ -95,56 +87,49 @@ public function it_reads_key_from_module_json_file_via_helper_method() $this->assertEquals(['required_module'], $this->module->get('requires')); } - /** @test */ - public function it_reads_key_from_composer_json_file_via_helper_method() + public function test_it_reads_key_from_composer_json_file_via_helper_method() { $this->assertEquals('nwidart/recipe', $this->module->getComposerAttr('name')); } - /** @test */ - public function it_casts_module_to_string() + public function test_it_casts_module_to_string() { $this->assertEquals('RecipeName', (string) $this->module); } - /** @test */ - public function it_module_status_check() + public function test_it_module_status_check() { $this->assertFalse($this->module->isStatus(true)); $this->assertTrue($this->module->isStatus(false)); } - /** @test */ - public function it_checks_module_enabled_status() + public function test_it_checks_module_enabled_status() { $this->assertFalse($this->module->isEnabled()); $this->assertTrue($this->module->isDisabled()); } - /** @test */ - public function it_fires_events_when_module_is_enabled() + public function test_it_fires_events_when_module_is_enabled() { Event::fake(); $this->module->enable(); - Event::assertDispatched(sprintf('modules.%s.enabling', $this->module->getLowerName())); - Event::assertDispatched(sprintf('modules.%s.enabled', $this->module->getLowerName())); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::ENABLING, $this->module->getLowerName())); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::ENABLED, $this->module->getLowerName())); } - /** @test */ - public function it_fires_events_when_module_is_disabled() + public function test_it_fires_events_when_module_is_disabled() { Event::fake(); $this->module->disable(); - Event::assertDispatched(sprintf('modules.%s.disabling', $this->module->getLowerName())); - Event::assertDispatched(sprintf('modules.%s.disabled', $this->module->getLowerName())); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::DISABLING, $this->module->getLowerName())); + Event::assertDispatched(sprintf('modules.%s.'.ModuleEvent::DISABLED, $this->module->getLowerName())); } - /** @test */ - public function it_has_a_good_providers_manifest_path() + public function test_it_has_a_good_providers_manifest_path() { $this->assertEquals( $this->app->basePath("storage/app/{$this->module->getSnakeName()}_module.php"), @@ -153,6 +138,4 @@ public function it_has_a_good_providers_manifest_path() } } -class LumenTestingModule extends \Nwidart\Modules\Lumen\Module -{ -} +class LumenTestingModule extends \Nwidart\Modules\Lumen\Module {} diff --git a/tests/StubTest.php b/tests/StubTest.php index 6e5ee5ad1..00089f026 100644 --- a/tests/StubTest.php +++ b/tests/StubTest.php @@ -28,30 +28,27 @@ public function tearDown(): void ]); } - /** @test */ - public function it_initialises_a_stub_instance() + public function test_it_initialises_a_stub_instance() { $stub = new Stub('/model.stub', [ 'NAME' => 'Name', ]); $this->assertTrue(Str::contains($stub->getPath(), 'src/Commands/stubs/model.stub')); - $this->assertEquals(['NAME' => 'Name', ], $stub->getReplaces()); + $this->assertEquals(['NAME' => 'Name'], $stub->getReplaces()); } - /** @test */ - public function it_sets_new_replaces_array() + public function test_it_sets_new_replaces_array() { $stub = new Stub('/model.stub', [ 'NAME' => 'Name', ]); - $stub->replace(['VENDOR' => 'MyVendor', ]); - $this->assertEquals(['VENDOR' => 'MyVendor', ], $stub->getReplaces()); + $stub->replace(['VENDOR' => 'MyVendor']); + $this->assertEquals(['VENDOR' => 'MyVendor'], $stub->getReplaces()); } - /** @test */ - public function it_stores_stub_to_specific_path() + public function test_it_stores_stub_to_specific_path() { $stub = new Stub('/command.stub', [ 'COMMAND_NAME' => 'my:command', @@ -64,8 +61,7 @@ public function it_stores_stub_to_specific_path() $this->assertTrue($this->finder->exists(base_path('my-command.php'))); } - /** @test */ - public function it_sets_new_path() + public function test_it_sets_new_path() { $stub = new Stub('/model.stub', [ 'NAME' => 'Name', @@ -76,8 +72,7 @@ public function it_sets_new_path() $this->assertTrue(Str::contains($stub->getPath(), 'Commands/stubs/new-path/')); } - /** @test */ - public function use_default_stub_if_override_not_exists() + public function test_use_default_stub_if_override_not_exists() { $stub = new Stub('/command.stub', [ 'COMMAND_NAME' => 'my:command', @@ -85,21 +80,20 @@ public function use_default_stub_if_override_not_exists() 'CLASS' => 'MyCommand', ]); - $stub->setBasePath(__DIR__ . '/stubs'); + $stub->setBasePath(__DIR__.'/stubs'); $stub->saveTo(base_path(), 'stub-override-not-exists.php'); $this->assertTrue($this->finder->exists(base_path('stub-override-not-exists.php'))); } - /** @test */ - public function use_override_stub_if_exists() + public function test_use_override_stub_if_exists() { $stub = new Stub('/model.stub', [ 'NAME' => 'Name', ]); - $stub->setBasePath(__DIR__ . '/stubs'); + $stub->setBasePath(__DIR__.'/stubs'); $stub->saveTo(base_path(), 'stub-override-exists.php'); diff --git a/tests/GenerateConfigReaderTest.php b/tests/Support/Config/GenerateConfigReaderTest.php similarity index 76% rename from tests/GenerateConfigReaderTest.php rename to tests/Support/Config/GenerateConfigReaderTest.php index 427108701..101ccc3e6 100644 --- a/tests/GenerateConfigReaderTest.php +++ b/tests/Support/Config/GenerateConfigReaderTest.php @@ -1,24 +1,23 @@ assertInstanceOf(GeneratorPath::class, $seedConfig); - $this->assertEquals('Database/Seeders', $seedConfig->getPath()); + $this->assertEquals('database/seeders', $seedConfig->getPath()); $this->assertTrue($seedConfig->generate()); } - /** @test */ - public function it_can_read_a_configuration_value_with_new_format_set_to_false() + public function test_it_can_read_a_configuration_value_with_new_format_set_to_false() { $this->app['config']->set('modules.paths.generator.seeder', ['path' => 'Database/Seeders', 'generate' => false]); @@ -29,8 +28,7 @@ public function it_can_read_a_configuration_value_with_new_format_set_to_false() $this->assertFalse($seedConfig->generate()); } - /** @test */ - public function it_can_read_a_configuration_value_with_old_format() + public function test_it_can_read_a_configuration_value_with_old_format() { $this->app['config']->set('modules.paths.generator.seeder', 'Database/Seeders'); @@ -41,8 +39,7 @@ public function it_can_read_a_configuration_value_with_old_format() $this->assertTrue($seedConfig->generate()); } - /** @test */ - public function it_can_read_a_configuration_value_with_old_format_set_to_false() + public function test_it_can_read_a_configuration_value_with_old_format_set_to_false() { $this->app['config']->set('modules.paths.generator.seeder', false); @@ -53,8 +50,7 @@ public function it_can_read_a_configuration_value_with_old_format_set_to_false() $this->assertFalse($seedConfig->generate()); } - /** @test */ - public function it_can_guess_namespace_from_path() + public function test_it_can_guess_namespace_from_path() { $this->app['config']->set('modules.paths.generator.provider', ['path' => 'Base/Providers', 'generate' => true]); diff --git a/tests/NameParserTest.php b/tests/Support/Migrations/NameParserTest.php similarity index 66% rename from tests/NameParserTest.php rename to tests/Support/Migrations/NameParserTest.php index 731e21ade..4bba0e895 100644 --- a/tests/NameParserTest.php +++ b/tests/Support/Migrations/NameParserTest.php @@ -1,29 +1,27 @@ getOriginalName()); } - /** @test */ - public function it_gets_the_table_name() + public function test_it_gets_the_table_name() { $parser = new NameParser('create_users_table'); self::assertEquals('users', $parser->getTableName()); } - /** @test */ - public function it_gets_the_action_name() + public function test_it_gets_the_action_name() { self::assertEquals('create', (new NameParser('create_users_table'))->getAction()); self::assertEquals('update', (new NameParser('update_users_table'))->getAction()); @@ -31,14 +29,12 @@ public function it_gets_the_action_name() self::assertEquals('remove', (new NameParser('remove_users_table'))->getAction()); } - /** @test */ - public function it_gets_first_part_of_name_if_no_action_was_guessed() + public function test_it_gets_first_part_of_name_if_no_action_was_guessed() { self::assertEquals('something', (new NameParser('something_random'))->getAction()); } - /** @test */ - public function it_gets_the_correct_matched_results() + public function test_it_gets_the_correct_matched_results() { $matches = (new NameParser('create_users_table'))->getMatches(); @@ -50,8 +46,7 @@ public function it_gets_the_correct_matched_results() self::assertEquals($expected, $matches); } - /** @test */ - public function it_gets_the_exploded_parts_of_migration_name() + public function test_it_gets_the_exploded_parts_of_migration_name() { $parser = new NameParser('create_users_table'); @@ -64,40 +59,34 @@ public function it_gets_the_exploded_parts_of_migration_name() self::assertEquals($expected, $parser->getData()); } - /** @test */ - public function it_can_check_if_current_migration_type_matches_given_type() + public function test_it_can_check_if_current_migration_type_matches_given_type() { $parser = new NameParser('create_users_table'); self::assertTrue($parser->is('create')); } - /** @test */ - public function it_can_check_if_current_migration_is_about_adding() + public function test_it_can_check_if_current_migration_is_about_adding() { self::assertTrue((new NameParser('add_users_table'))->isAdd()); } - /** @test */ - public function it_can_check_if_current_migration_is_about_deleting() + public function test_it_can_check_if_current_migration_is_about_deleting() { self::assertTrue((new NameParser('delete_users_table'))->isDelete()); } - /** @test */ - public function it_can_check_if_current_migration_is_about_creating() + public function test_it_can_check_if_current_migration_is_about_creating() { self::assertTrue((new NameParser('create_users_table'))->isCreate()); } - /** @test */ - public function it_can_check_if_current_migration_is_about_dropping() + public function test_it_can_check_if_current_migration_is_about_dropping() { self::assertTrue((new NameParser('drop_users_table'))->isDrop()); } - /** @test */ - public function it_makes_a_regex_pattern() + public function test_it_makes_a_regex_pattern() { self::assertEquals('/create_(.*)_table/', (new NameParser('create_users_table'))->getPattern()); self::assertEquals('/add_(.*)_to_(.*)_table/', (new NameParser('add_column_to_users_table'))->getPattern()); diff --git a/tests/SchemaParserTest.php b/tests/Support/Migrations/SchemaParserTest.php similarity index 70% rename from tests/SchemaParserTest.php rename to tests/Support/Migrations/SchemaParserTest.php index d4016087a..2d5dbb787 100644 --- a/tests/SchemaParserTest.php +++ b/tests/Support/Migrations/SchemaParserTest.php @@ -1,13 +1,13 @@ render()); } - /** @test */ - public function it_generates_migration_methods_for_up_method() + public function test_it_generates_migration_methods_for_up_method() { $parser = new SchemaParser('username:string, password:integer'); @@ -32,8 +31,7 @@ public function it_generates_migration_methods_for_up_method() self::assertEquals($expected, $parser->up()); } - /** @test */ - public function it_generates_migration_methods_for_down_method() + public function test_it_generates_migration_methods_for_down_method() { $parser = new SchemaParser('username:string, password:integer'); diff --git a/tests/Traits/PathNamespaceTest.php b/tests/Traits/PathNamespaceTest.php new file mode 100644 index 000000000..ceffac04e --- /dev/null +++ b/tests/Traits/PathNamespaceTest.php @@ -0,0 +1,51 @@ +class = new UsePathNamespaceTrait(); + } + + public function test_studly_path() + { + $this->assertSame('Blog/Services', $this->class->studly_path('/blog/services')); + } + + public function test_studly_namespace() + { + $this->assertSame('/blog/services', $this->class->studly_namespace('/blog/services')); + } + + public function test_path_namespace() + { + $this->assertSame('Blog\Services', $this->class->path_namespace('/blog/services')); + } + + public function test_module_namespace() + { + $this->assertSame('Modules\Blog/services', $this->class->module_namespace('blog/services')); + } + + public function test_clean_path() + { + $this->assertSame('blog/services', $this->class->clean_path('blog/services')); + $this->assertSame('', $this->class->clean_path('')); + } + + public function test_app_path() + { + $configPath = config('modules.paths.app_folder'); + $configPath = rtrim($configPath, '/'); + + $this->assertSame($configPath, $this->class->app_path()); + $this->assertSame($configPath, $this->class->app_path(null)); + $this->assertSame('app/blog/services', $this->class->app_path('blog/services')); + } +} diff --git a/tests/Traits/UsePathNamespaceTrait.php b/tests/Traits/UsePathNamespaceTrait.php new file mode 100644 index 000000000..1eaff1d60 --- /dev/null +++ b/tests/Traits/UsePathNamespaceTrait.php @@ -0,0 +1,10 @@ +group(['prefix' =>'/recipe'], function (Router $router) { +$router->group(['prefix' => '/recipe'], function (Router $router) { $router->bind('recipes', function ($id) { return app('Modules\Recipe\Repositories\RecipeRepository')->find($id); }); $router->resource('recipes', 'RecipeController', ['except' => ['show'], 'names' => [ - 'index' => 'admin.recipe.recipe.index', - 'create' => 'admin.recipe.recipe.create', - 'store' => 'admin.recipe.recipe.store', - 'edit' => 'admin.recipe.recipe.edit', - 'update' => 'admin.recipe.recipe.update', - 'destroy' => 'admin.recipe.recipe.destroy', - ]]); + 'index' => 'admin.recipe.recipe.index', + 'create' => 'admin.recipe.recipe.create', + 'store' => 'admin.recipe.recipe.store', + 'edit' => 'admin.recipe.recipe.edit', + 'update' => 'admin.recipe.recipe.update', + 'destroy' => 'admin.recipe.recipe.destroy', + ]]); // append }); diff --git a/tests/stubs/valid/Recipe/Providers/DeferredServiceProvider.php b/tests/stubs/valid/Recipe/Providers/DeferredServiceProvider.php index 446473628..65ba14f66 100644 --- a/tests/stubs/valid/Recipe/Providers/DeferredServiceProvider.php +++ b/tests/stubs/valid/Recipe/Providers/DeferredServiceProvider.php @@ -19,7 +19,7 @@ public function register() }); app()->bind('deferred', function () { - return; + }); } diff --git a/tests/stubs/valid/Recipe/Providers/RecipeServiceProvider.php b/tests/stubs/valid/Recipe/Providers/RecipeServiceProvider.php index 3ef5fd411..a914dee15 100644 --- a/tests/stubs/valid/Recipe/Providers/RecipeServiceProvider.php +++ b/tests/stubs/valid/Recipe/Providers/RecipeServiceProvider.php @@ -30,7 +30,7 @@ public function register() */ public function provides() { - return array(); + return []; } private function registerBindings() diff --git a/tests/stubs/valid/Recipe/Sidebar/SidebarExtender.php b/tests/stubs/valid/Recipe/Sidebar/SidebarExtender.php index 47d27eee2..fce3410d2 100644 --- a/tests/stubs/valid/Recipe/Sidebar/SidebarExtender.php +++ b/tests/stubs/valid/Recipe/Sidebar/SidebarExtender.php @@ -15,8 +15,6 @@ class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender protected $auth; /** - * @param Authentication $auth - * * @internal param Guard $guard */ public function __construct(Authentication $auth) @@ -25,8 +23,6 @@ public function __construct(Authentication $auth) } /** - * @param Menu $menu - * * @return Menu */ public function extendWith(Menu $menu)