diff --git a/.env.example b/.env.example index 8bc003a..236049a 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ APP_NAME=LaravelInertiaVueSpa -APP_ENV=local +APP_ENV=testing ## or 'testing' APP_KEY= APP_DEBUG=true APP_URL=http://localhost @@ -8,13 +8,17 @@ LOG_CHANNEL=stack LOG_DEPRECATIONS_CHANNEL=null LOG_LEVEL=debug +# use this for docker DB_CONNECTION=mysql -DB_HOST=mysql -DB_PORT=3306 +DB_HOST=mysql +DB_PORT=3306 DB_DATABASE=LaravelInertiaVueSpa.Database_2024! -DB_USERNAME=root +DB_USERNAME=root DB_PASSWORD=LaravelInertiaVueSpa.Password_2024! +# modify this for sqlite +# DB_DATABASE=/home/${yourusername}/${path}/database/database.sqlite + BROADCAST_DRIVER=log CACHE_DRIVER=file FILESYSTEM_DISK=local @@ -55,4 +59,4 @@ VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}" VITE_PUSHER_HOST="${PUSHER_HOST}" VITE_PUSHER_PORT="${PUSHER_PORT}" VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" -VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" \ No newline at end of file +VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" diff --git a/.github/workflows/docker_action.yml b/.github/workflows/docker_action.yml index 67a5d3b..d6ed896 100644 --- a/.github/workflows/docker_action.yml +++ b/.github/workflows/docker_action.yml @@ -7,6 +7,8 @@ on: paths: - 'Dockerfile' - 'docker-compose.yml' + pull_request: + branches: [ master ] jobs: build: @@ -18,4 +20,4 @@ jobs: - name: Build and run Docker Compose run: | - docker-compose up --build -d + docker compose up --build -d diff --git a/.github/workflows/phpunit_action.yml b/.github/workflows/phpunit_action.yml index 65c151b..c8f1031 100644 --- a/.github/workflows/phpunit_action.yml +++ b/.github/workflows/phpunit_action.yml @@ -10,38 +10,38 @@ jobs: project-tests: runs-on: ubuntu-latest - + steps: - uses: actions/checkout@v2 - + - name: Copy .env run: php -r "file_exists('.env') || copy('.env.example', '.env');" - + - name: Update Dependencies (if needed) run: composer update --no-ansi --no-interaction --no-scripts --no-progress - + - name: Install Dependencies run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress - + - name: Generate key run: php artisan key:generate - + - name: Directory Permissions run: chmod -R 777 storage bootstrap/cache - + - name: Create Database run: | mkdir -p database - touch database/database.sqlite - + [ -f database/database.sqlite ] || touch database/database.sqlite + - name: Build assets for development env: LARAVEL_BYPASS_ENV_CHECK: 1 run: npm install && npm run dev & - + - name: Wait for server to start - run: sleep 10s - + run: sleep 10s + - name: Execute tests (Unit and Feature tests) via PHPUnit env: DB_CONNECTION: sqlite @@ -49,4 +49,5 @@ jobs: CACHE_DRIVER: array SESSION_DRIVER: array QUEUE_DRIVER: sync + APP_ENV: testing run: vendor/bin/phpunit diff --git a/Dockerfile b/Dockerfile index 9f81984..4e41cbc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,8 @@ RUN composer install --no-scripts --no-autoloader COPY . . +COPY .env.example .env + RUN npm install RUN npm run build diff --git a/bootstrap/cache/.gitignore b/bootstrap/cache/.gitignore old mode 100644 new mode 100755 diff --git a/config/database.php b/config/database.php index 67f3563..67540c4 100644 --- a/config/database.php +++ b/config/database.php @@ -15,7 +15,7 @@ | */ - 'default' => env('DB_CONNECTION', 'mysql'), + 'default' => env('DB_CONNECTION', 'sqlite'), /* |-------------------------------------------------------------------------- @@ -38,7 +38,7 @@ 'sqlite' => [ 'driver' => 'sqlite', 'url' => env('DATABASE_URL'), - 'database' => env('DB_DATABASE', database_path('database.sqlite')), + 'database' => dirname(__DIR__).'/database/database.sqlite', 'prefix' => '', 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), ], diff --git a/config/queue.php b/config/queue.php index 25ea5a8..c37ff68 100644 --- a/config/queue.php +++ b/config/queue.php @@ -86,7 +86,7 @@ 'failed' => [ 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), - 'database' => env('DB_CONNECTION', 'mysql'), + 'database' => env('DB_CONNECTION', 'sqlite'), 'table' => 'failed_jobs', ], diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index b210f39..fe00431 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -28,7 +28,7 @@ public function definition(): array 'name' => $this->faker->name(), 'email' => $this->faker->unique()->safeEmail(), 'email_verified_at' => now(), - 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password + 'password' => $this->faker->password(8), 'two_factor_secret' => null, 'two_factor_recovery_codes' => null, 'remember_token' => Str::random(10), diff --git a/storage/app/.gitignore b/storage/app/.gitignore old mode 100644 new mode 100755 diff --git a/storage/app/public/.gitignore b/storage/app/public/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/.gitignore b/storage/framework/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/cache/.gitignore b/storage/framework/cache/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/cache/data/.gitignore b/storage/framework/cache/data/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/sessions/.gitignore b/storage/framework/sessions/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/testing/.gitignore b/storage/framework/testing/.gitignore old mode 100644 new mode 100755 diff --git a/storage/framework/views/.gitignore b/storage/framework/views/.gitignore old mode 100644 new mode 100755 diff --git a/storage/logs/.gitignore b/storage/logs/.gitignore old mode 100644 new mode 100755 diff --git a/tests/Feature/AuthenticationTest.php b/tests/Feature/AuthenticationTest.php index 7623fe9..67c0d39 100644 --- a/tests/Feature/AuthenticationTest.php +++ b/tests/Feature/AuthenticationTest.php @@ -20,17 +20,21 @@ public function test_login_screen_can_be_rendered(): void public function test_users_can_authenticate_using_the_login_screen(): void { - $user = User::factory()->create(); + $password = 'password123'; + $user = User::factory()->create([ + 'password' => bcrypt($password), + ]); $response = $this->post('/login', [ 'email' => $user->email, - 'password' => 'password', + 'password' => $password, ]); $this->assertAuthenticated(); $response->assertRedirect(RouteServiceProvider::HOME); } + public function test_users_can_not_authenticate_with_invalid_password(): void { $user = User::factory()->create(); diff --git a/tests/Feature/BrowserSessionsTest.php b/tests/Feature/BrowserSessionsTest.php index 46998c4..0c323e9 100644 --- a/tests/Feature/BrowserSessionsTest.php +++ b/tests/Feature/BrowserSessionsTest.php @@ -12,7 +12,11 @@ class BrowserSessionsTest extends TestCase public function test_other_browser_sessions_can_be_logged_out(): void { - $this->actingAs($user = User::factory()->create()); + $user = User::factory()->create([ + 'password' => bcrypt('password'), + ]); + + $this->actingAs($user); $response = $this->delete('/user/other-browser-sessions', [ 'password' => 'password', diff --git a/tests/Feature/DeleteApiTokenTest.php b/tests/Feature/DeleteApiTokenTest.php index 7d84a1a..ffee2ff 100644 --- a/tests/Feature/DeleteApiTokenTest.php +++ b/tests/Feature/DeleteApiTokenTest.php @@ -28,7 +28,7 @@ public function test_api_tokens_can_be_deleted(): void 'abilities' => ['create', 'read'], ]); - $response = $this->delete('/user/api-tokens/'.$token->id); + $response = $this->delete('/user/api-tokens/' . $token->id); $this->assertCount(0, $user->fresh()->tokens); } diff --git a/tests/Feature/EmailVerificationTest.php b/tests/Feature/EmailVerificationTest.php index ad0257d..08ef69b 100644 --- a/tests/Feature/EmailVerificationTest.php +++ b/tests/Feature/EmailVerificationTest.php @@ -53,7 +53,7 @@ public function test_email_can_be_verified(): void Event::assertDispatched(Verified::class); $this->assertTrue($user->fresh()->hasVerifiedEmail()); - $response->assertRedirect(RouteServiceProvider::HOME.'?verified=1'); + $response->assertRedirect(RouteServiceProvider::HOME . '?verified=1'); } public function test_email_can_not_verified_with_invalid_hash(): void diff --git a/tests/Feature/PasswordConfirmationTest.php b/tests/Feature/PasswordConfirmationTest.php index 7575d3a..401c105 100644 --- a/tests/Feature/PasswordConfirmationTest.php +++ b/tests/Feature/PasswordConfirmationTest.php @@ -22,16 +22,22 @@ public function test_confirm_password_screen_can_be_rendered(): void public function test_password_can_be_confirmed(): void { - $user = User::factory()->create(); + $user = User::factory()->create([ + 'password' => bcrypt('password'), + ]); - $response = $this->actingAs($user)->post('/user/confirm-password', [ + $this->actingAs($user); + + $response = $this->post('/user/confirm-password', [ 'password' => 'password', ]); $response->assertRedirect(); + $response->assertSessionHasNoErrors(); } + public function test_password_is_not_confirmed_with_invalid_password(): void { $user = User::factory()->create(); diff --git a/tests/Feature/PasswordResetTest.php b/tests/Feature/PasswordResetTest.php index 7c65edb..f07fbac 100644 --- a/tests/Feature/PasswordResetTest.php +++ b/tests/Feature/PasswordResetTest.php @@ -62,7 +62,7 @@ public function test_reset_password_screen_can_be_rendered(): void ]); Notification::assertSentTo($user, ResetPassword::class, function (object $notification) { - $response = $this->get('/reset-password/'.$notification->token); + $response = $this->get('/reset-password/' . $notification->token); $response->assertStatus(200); diff --git a/tests/Feature/RoleManagementTest.php b/tests/Feature/RoleManagementTest.php index e898189..fd96c62 100644 --- a/tests/Feature/RoleManagementTest.php +++ b/tests/Feature/RoleManagementTest.php @@ -27,7 +27,8 @@ public function test_role_model_update_feature() $role = Role::factory()->create(); $response = $this->put('/roles/' . $role->id, [ - 'name' => 'Updated role name']); + 'name' => 'Updated role name' + ]); $this->assertDatabaseHas('roles', [ 'id' => $role->id, @@ -90,5 +91,4 @@ public function test_role_user_count_is_shown_with_one_user() $response->assertSee(1); } - } diff --git a/tests/Feature/UpdatePasswordTest.php b/tests/Feature/UpdatePasswordTest.php index 88de460..035d18e 100644 --- a/tests/Feature/UpdatePasswordTest.php +++ b/tests/Feature/UpdatePasswordTest.php @@ -13,7 +13,11 @@ class UpdatePasswordTest extends TestCase public function test_password_can_be_updated(): void { - $this->actingAs($user = User::factory()->create()); + $user = User::factory()->create([ + 'password' => bcrypt('password'), + ]); + + $this->actingAs(user: $user); $response = $this->put('/user/password', [ 'current_password' => 'password', @@ -26,7 +30,11 @@ public function test_password_can_be_updated(): void public function test_current_password_must_be_correct(): void { - $this->actingAs($user = User::factory()->create()); + $user = User::factory()->create([ + 'password' => bcrypt('password'), + ]); + + $this->actingAs($user); $response = $this->put('/user/password', [ 'current_password' => 'wrong-password', @@ -41,7 +49,11 @@ public function test_current_password_must_be_correct(): void public function test_new_passwords_must_match(): void { - $this->actingAs($user = User::factory()->create()); + $user = User::factory()->create([ + 'password' => bcrypt('password'), + ]); + + $this->actingAs($user); $response = $this->put('/user/password', [ 'current_password' => 'password', diff --git a/tests/Feature/UserManagementTest.php b/tests/Feature/UserManagementTest.php index d7a8447..4b10d8b 100644 --- a/tests/Feature/UserManagementTest.php +++ b/tests/Feature/UserManagementTest.php @@ -27,12 +27,16 @@ public function test_user_model_update_feature() $response = $this->put('/users/' . $user->id, [ 'name' => 'John Doe', - 'email' => 'updated@mail.com']); - - $this->assertDatabaseHas('users', [ - 'id' => $user->id, - 'name' => 'John Doe', - 'email' => 'updated@mail.com'] + 'email' => 'updated@mail.com' + ]); + + $this->assertDatabaseHas( + 'users', + [ + 'id' => $user->id, + 'name' => 'John Doe', + 'email' => 'updated@mail.com' + ] ); $response->assertStatus(302);