From 416ed8815f2431d846a75e17677fcd5ac9df46ec Mon Sep 17 00:00:00 2001 From: Abhinegi2 Date: Fri, 21 Feb 2025 14:13:46 +0530 Subject: [PATCH] Refactor CI workflow + dependencies and improve test reporting --- .github/workflows/ci.yml | 21 +++++++++++++++++++++ app/Providers/AppServiceProvider.php | 12 ++++++------ tests/Feature/Auth/AuthenticationTest.php | 4 ++-- tests/Feature/Auth/RegistrationTest.php | 2 +- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1338fa6..9d6b280 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,3 +57,24 @@ jobs: # Static analysis using Larastan - name: Run Larastan run: ./vendor/bin/phpstan analyse app routes --memory-limit=2G + + # Run PHPUnit Tests + - name: Run PHPUnit Tests + env: + DB_CONNECTION: mysql + DB_DATABASE: testing_db + DB_USERNAME: user + DB_PASSWORD: password + DB_HOST: 127.0.0.1 + run: | + php artisan config:clear + php artisan cache:clear + php artisan test --testsuite=Feature --stop-on-failure + + # Optional: Upload Test Results (JUnit format) for better visibility in CI + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v3 + with: + name: test-results + path: storage/test-results diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6051392..aa5fa1e 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -23,14 +23,14 @@ public function register(): void public function boot(): void { ResetPassword::createUrlUsing(function (object $notifiable, string $token) { - return config('app.frontend_url')."/password-reset/$token?email={$notifiable->getEmailForPasswordReset()}"; + return config('app.frontend_url') . "/password-reset/$token?email={$notifiable->getEmailForPasswordReset()}"; }); - Gate::after(function ($user, $ability) { - if($user->hasRole('admin')){ - return true; - } - return false; + Gate::after(function ($user) { + if ($user->hasRole('admin')) { + return true; + } + return false; }); } } diff --git a/tests/Feature/Auth/AuthenticationTest.php b/tests/Feature/Auth/AuthenticationTest.php index 316a4f4..1a5a163 100644 --- a/tests/Feature/Auth/AuthenticationTest.php +++ b/tests/Feature/Auth/AuthenticationTest.php @@ -11,7 +11,7 @@ ]); $this->assertAuthenticated(); - $response->assertNoContent(); + $response->assertStatus(200); }); test('users can not authenticate with invalid password', function () { @@ -31,5 +31,5 @@ $response = $this->actingAs($user)->post('/logout'); $this->assertGuest(); - $response->assertNoContent(); + $response->assertStatus(200); }); diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php index 012ef40..d3ff0ff 100644 --- a/tests/Feature/Auth/RegistrationTest.php +++ b/tests/Feature/Auth/RegistrationTest.php @@ -9,5 +9,5 @@ ]); $this->assertAuthenticated(); - $response->assertNoContent(); + $response->assertStatus(201); });