From 3c0631eae3c879b3c5b72f09610c17dc77892735 Mon Sep 17 00:00:00 2001 From: Mahmood Ahmad Date: Sat, 18 Mar 2023 11:18:49 +0200 Subject: [PATCH 1/4] Update SendResponse.stub --- src/Core/Base/SendResponse.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Base/SendResponse.stub b/src/Core/Base/SendResponse.stub index 9676200..89d1ca2 100644 --- a/src/Core/Base/SendResponse.stub +++ b/src/Core/Base/SendResponse.stub @@ -51,7 +51,7 @@ trait SendResponse } if (env('APP_DEBUG') == true) { - $errors = $e->errors(); + $errors = $e->getTrace(); $message = $e->getMessage(); } From 19c01e6f59460018cf8e11cc951d9af783baf19e Mon Sep 17 00:00:00 2001 From: Mahmood Ahmad Date: Sat, 18 Mar 2023 16:23:38 +0200 Subject: [PATCH 2/4] adding support for Laravel 10.x + fixing bugs --- README.md | 6 ++++++ docs/error-handling.md | 2 +- docs/introduction.md | 2 +- docs/middlewares.md | 4 ++-- src/Core/Base/{TestCase.stub => ApiTestCase.stub} | 15 +++++++++++---- src/Core/Base/WebControllerTest.stub | 6 +++--- src/Core/Base/WebTestCase.stub | 10 ++++++++++ src/Core/Module/UnitTest.stub | 7 ++++--- src/config.php | 3 ++- 9 files changed, 40 insertions(+), 15 deletions(-) rename src/Core/Base/{TestCase.stub => ApiTestCase.stub} (94%) create mode 100644 src/Core/Base/WebTestCase.stub diff --git a/README.md b/README.md index cce3dbb..5cf5b35 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,12 @@ ![Codacy grade](https://img.shields.io/codacy/grade/c8ff813591bf46ee9711e57188149288) [![Total Downloads](https://img.shields.io/packagist/dt/yepwoo/laragine.svg)](https://packagist.org/packages/yepwoo/laragine) +| **Supported Laravel Versions** | +|-------------| +| 8.x | +| 9.x | +| 10.x | + We developed Laragine to make the software development using Laravel faster and cleaner, so you can get things done faster, not only that, Laragine is not about quantity only, it's all about quantity and quality. #### Quick short video: diff --git a/docs/error-handling.md b/docs/error-handling.md index c3c7e9e..60746ab 100644 --- a/docs/error-handling.md +++ b/docs/error-handling.md @@ -29,7 +29,7 @@ class Handler extends ExceptionHandler } ``` -Now, we need to use this helper function `client_validation_response` (it accepts 2 arguments, the first is the rules array and the second (optional) is the start error code) in the validation file (`lang\en\validation.php` in Laravel `9.x` or `resources\lang\en\validation.php` Laravel `8.x`) by assigning the array to a variable and then return the helper function, here is the full code snippet: +Now, we need to use this helper function `client_validation_response` (it accepts 2 arguments, the first is the rules array and the second (optional) is the start error code) in the validation file (`lang\en\validation.php` in Laravel `9.x` and `10.x` (in `10.x` you need to run this command first: `php artisan lang:publish`) or `resources\lang\en\validation.php` Laravel `8.x`) by assigning the array to a variable and then return the helper function, here is the full code snippet: ```php $array = [ diff --git a/docs/introduction.md b/docs/introduction.md index 7b5feed..fc22f7f 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -32,7 +32,7 @@ It's also very important to understand the following terms: ### Notes -* Laragine currently is working on **Laravel 8.x and 9.x** +* Laragine currently is working on **Laravel 8.x, 9.x and 10.x** * Laragine directory will be in the root directory under `Core` directory diff --git a/docs/middlewares.md b/docs/middlewares.md index cc02c47..1f0c68a 100644 --- a/docs/middlewares.md +++ b/docs/middlewares.md @@ -6,10 +6,10 @@ Useful middlewares to help you protect the system and for better security: to check if the client side includes a valid `api-key` header in any API request. -to use it, first add `API_KEY=your_api_key_here` in `.env` file, second in the **Kernel** (`app\Http\Kernel.php`) add it in `$routeMiddleware` as below: +to use it, first add `API_KEY=your_api_key_here` in `.env` file, second in the **Kernel** (`app\Http\Kernel.php`) add it in `$routeMiddleware` or `middlewareAliases` if it's Laravel `10.x` as below: ```php -protected $routeMiddleware = [ +protected $middlewareAliases = [ ... diff --git a/src/Core/Base/TestCase.stub b/src/Core/Base/ApiTestCase.stub similarity index 94% rename from src/Core/Base/TestCase.stub rename to src/Core/Base/ApiTestCase.stub index fcf7557..2106bb9 100644 --- a/src/Core/Base/TestCase.stub +++ b/src/Core/Base/ApiTestCase.stub @@ -2,12 +2,12 @@ namespace Core\Base\Tests; -use Tests\TestCase as BaseTestCase; +use Tests\TestCase; use Illuminate\Foundation\Testing\RefreshDatabase; use App\Models\User; // use Tymon\JWTAuth\Facades\JWTAuth; -class TestCase extends BaseTestCase +class ApiTestCase extends TestCase { use RefreshDatabase; @@ -18,6 +18,13 @@ class TestCase extends BaseTestCase */ protected $base_url; + /** + * the current model + * + * @var array + */ + protected $model; + /** * the data that will be sent in the request (create/update) * @@ -125,11 +132,11 @@ class TestCase extends BaseTestCase /** * create new entry * - * @return Model + * @return \Illuminate\Database\Eloquent\Model */ protected function getNewEntry() { - return Model::factory()->create(); + return $this->model::factory()->create(); } /** diff --git a/src/Core/Base/WebControllerTest.stub b/src/Core/Base/WebControllerTest.stub index 2f6bd50..d3f1eba 100644 --- a/src/Core/Base/WebControllerTest.stub +++ b/src/Core/Base/WebControllerTest.stub @@ -2,10 +2,10 @@ namespace Core\Base\Tests\Unit; -use Core\Base\Tests\TestCase; +use Core\Base\Tests\WebTestCase; use Core\Base\Controllers\Web\Controller; -class WebControllerTest extends TestCase +class WebControllerTest extends WebTestCase { /** * the web controller @@ -26,7 +26,7 @@ class WebControllerTest extends TestCase $this->controller = $this->getMockBuilder(Controller::class) ->disableOriginalConstructor() - ->setMethods(['getExplodedNamespace']) + ->onlyMethods(['getExplodedNamespace']) ->getMock(); $this->controller->expects($this->any()) diff --git a/src/Core/Base/WebTestCase.stub b/src/Core/Base/WebTestCase.stub new file mode 100644 index 0000000..c70a667 --- /dev/null +++ b/src/Core/Base/WebTestCase.stub @@ -0,0 +1,10 @@ +base_url = $this->getApiBaseUrl() . '#UNIT_NAME_PLURAL_LOWER_CASE#/'; - $this->data = Model::factory()->make()->toArray(); + $this->model = new Model(); + $this->data = $this->model::factory()->make()->toArray(); $this->json = $this->getJsonStructure(); $this->json['data'] = ['id']; diff --git a/src/config.php b/src/config.php index 406e719..a92f476 100644 --- a/src/config.php +++ b/src/config.php @@ -32,7 +32,8 @@ 'api.php' => 'routes/api.php', 'web.php' => 'routes/web.php', 'WebControllerTest.stub' => 'Tests/Unit/WebControllerTest.php', - 'TestCase.stub' => 'Tests/TestCase.php', + 'ApiTestCase.stub' => 'Tests/ApiTestCase.php', + 'WebTestCase.stub' => 'Tests/WebTestCase.php', 'Uuid.stub' => 'Traits/Model/Uuid.php', 'SendResponse.stub' => 'Traits/Response/SendResponse.php', 'File.stub' => 'Traits/ServiceProvider/File.php', From d7ea2105a8932c04d5f76aff1270d8597aaef2bb Mon Sep 17 00:00:00 2001 From: Mahmood Ahmad Date: Sat, 18 Mar 2023 11:18:49 +0200 Subject: [PATCH 3/4] Update SendResponse.stub --- src/Core/Base/SendResponse.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Base/SendResponse.stub b/src/Core/Base/SendResponse.stub index 9676200..89d1ca2 100644 --- a/src/Core/Base/SendResponse.stub +++ b/src/Core/Base/SendResponse.stub @@ -51,7 +51,7 @@ trait SendResponse } if (env('APP_DEBUG') == true) { - $errors = $e->errors(); + $errors = $e->getTrace(); $message = $e->getMessage(); } From da6f015cc3e274130eab50a9f88ed730a7d33309 Mon Sep 17 00:00:00 2001 From: Mahmood Ahmad Date: Sat, 18 Mar 2023 16:23:38 +0200 Subject: [PATCH 4/4] adding support for Laravel 10.x + fixing bugs --- README.md | 6 ++++++ docs/error-handling.md | 2 +- docs/introduction.md | 2 +- docs/middlewares.md | 4 ++-- src/Core/Base/{TestCase.stub => ApiTestCase.stub} | 15 +++++++++++---- src/Core/Base/WebControllerTest.stub | 6 +++--- src/Core/Base/WebTestCase.stub | 10 ++++++++++ src/Core/Module/UnitTest.stub | 7 ++++--- src/config.php | 3 ++- 9 files changed, 40 insertions(+), 15 deletions(-) rename src/Core/Base/{TestCase.stub => ApiTestCase.stub} (94%) create mode 100644 src/Core/Base/WebTestCase.stub diff --git a/README.md b/README.md index cce3dbb..5cf5b35 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,12 @@ ![Codacy grade](https://img.shields.io/codacy/grade/c8ff813591bf46ee9711e57188149288) [![Total Downloads](https://img.shields.io/packagist/dt/yepwoo/laragine.svg)](https://packagist.org/packages/yepwoo/laragine) +| **Supported Laravel Versions** | +|-------------| +| 8.x | +| 9.x | +| 10.x | + We developed Laragine to make the software development using Laravel faster and cleaner, so you can get things done faster, not only that, Laragine is not about quantity only, it's all about quantity and quality. #### Quick short video: diff --git a/docs/error-handling.md b/docs/error-handling.md index c3c7e9e..60746ab 100644 --- a/docs/error-handling.md +++ b/docs/error-handling.md @@ -29,7 +29,7 @@ class Handler extends ExceptionHandler } ``` -Now, we need to use this helper function `client_validation_response` (it accepts 2 arguments, the first is the rules array and the second (optional) is the start error code) in the validation file (`lang\en\validation.php` in Laravel `9.x` or `resources\lang\en\validation.php` Laravel `8.x`) by assigning the array to a variable and then return the helper function, here is the full code snippet: +Now, we need to use this helper function `client_validation_response` (it accepts 2 arguments, the first is the rules array and the second (optional) is the start error code) in the validation file (`lang\en\validation.php` in Laravel `9.x` and `10.x` (in `10.x` you need to run this command first: `php artisan lang:publish`) or `resources\lang\en\validation.php` Laravel `8.x`) by assigning the array to a variable and then return the helper function, here is the full code snippet: ```php $array = [ diff --git a/docs/introduction.md b/docs/introduction.md index 7b5feed..fc22f7f 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -32,7 +32,7 @@ It's also very important to understand the following terms: ### Notes -* Laragine currently is working on **Laravel 8.x and 9.x** +* Laragine currently is working on **Laravel 8.x, 9.x and 10.x** * Laragine directory will be in the root directory under `Core` directory diff --git a/docs/middlewares.md b/docs/middlewares.md index cc02c47..1f0c68a 100644 --- a/docs/middlewares.md +++ b/docs/middlewares.md @@ -6,10 +6,10 @@ Useful middlewares to help you protect the system and for better security: to check if the client side includes a valid `api-key` header in any API request. -to use it, first add `API_KEY=your_api_key_here` in `.env` file, second in the **Kernel** (`app\Http\Kernel.php`) add it in `$routeMiddleware` as below: +to use it, first add `API_KEY=your_api_key_here` in `.env` file, second in the **Kernel** (`app\Http\Kernel.php`) add it in `$routeMiddleware` or `middlewareAliases` if it's Laravel `10.x` as below: ```php -protected $routeMiddleware = [ +protected $middlewareAliases = [ ... diff --git a/src/Core/Base/TestCase.stub b/src/Core/Base/ApiTestCase.stub similarity index 94% rename from src/Core/Base/TestCase.stub rename to src/Core/Base/ApiTestCase.stub index fcf7557..2106bb9 100644 --- a/src/Core/Base/TestCase.stub +++ b/src/Core/Base/ApiTestCase.stub @@ -2,12 +2,12 @@ namespace Core\Base\Tests; -use Tests\TestCase as BaseTestCase; +use Tests\TestCase; use Illuminate\Foundation\Testing\RefreshDatabase; use App\Models\User; // use Tymon\JWTAuth\Facades\JWTAuth; -class TestCase extends BaseTestCase +class ApiTestCase extends TestCase { use RefreshDatabase; @@ -18,6 +18,13 @@ class TestCase extends BaseTestCase */ protected $base_url; + /** + * the current model + * + * @var array + */ + protected $model; + /** * the data that will be sent in the request (create/update) * @@ -125,11 +132,11 @@ class TestCase extends BaseTestCase /** * create new entry * - * @return Model + * @return \Illuminate\Database\Eloquent\Model */ protected function getNewEntry() { - return Model::factory()->create(); + return $this->model::factory()->create(); } /** diff --git a/src/Core/Base/WebControllerTest.stub b/src/Core/Base/WebControllerTest.stub index 2f6bd50..d3f1eba 100644 --- a/src/Core/Base/WebControllerTest.stub +++ b/src/Core/Base/WebControllerTest.stub @@ -2,10 +2,10 @@ namespace Core\Base\Tests\Unit; -use Core\Base\Tests\TestCase; +use Core\Base\Tests\WebTestCase; use Core\Base\Controllers\Web\Controller; -class WebControllerTest extends TestCase +class WebControllerTest extends WebTestCase { /** * the web controller @@ -26,7 +26,7 @@ class WebControllerTest extends TestCase $this->controller = $this->getMockBuilder(Controller::class) ->disableOriginalConstructor() - ->setMethods(['getExplodedNamespace']) + ->onlyMethods(['getExplodedNamespace']) ->getMock(); $this->controller->expects($this->any()) diff --git a/src/Core/Base/WebTestCase.stub b/src/Core/Base/WebTestCase.stub new file mode 100644 index 0000000..c70a667 --- /dev/null +++ b/src/Core/Base/WebTestCase.stub @@ -0,0 +1,10 @@ +base_url = $this->getApiBaseUrl() . '#UNIT_NAME_PLURAL_LOWER_CASE#/'; - $this->data = Model::factory()->make()->toArray(); + $this->model = new Model(); + $this->data = $this->model::factory()->make()->toArray(); $this->json = $this->getJsonStructure(); $this->json['data'] = ['id']; diff --git a/src/config.php b/src/config.php index 406e719..a92f476 100644 --- a/src/config.php +++ b/src/config.php @@ -32,7 +32,8 @@ 'api.php' => 'routes/api.php', 'web.php' => 'routes/web.php', 'WebControllerTest.stub' => 'Tests/Unit/WebControllerTest.php', - 'TestCase.stub' => 'Tests/TestCase.php', + 'ApiTestCase.stub' => 'Tests/ApiTestCase.php', + 'WebTestCase.stub' => 'Tests/WebTestCase.php', 'Uuid.stub' => 'Traits/Model/Uuid.php', 'SendResponse.stub' => 'Traits/Response/SendResponse.php', 'File.stub' => 'Traits/ServiceProvider/File.php',