Skip to content

Commit 00c04bf

Browse files
fix: testing feature
1 parent 21490f9 commit 00c04bf

26 files changed

+75
-59
lines changed

.env.example

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
APP_NAME=LaravelInertiaVueSpa
2-
APP_ENV=local
2+
APP_ENV=local ## or 'testing'
33
APP_KEY=
44
APP_DEBUG=true
55
APP_URL=http://localhost
@@ -8,13 +8,17 @@ LOG_CHANNEL=stack
88
LOG_DEPRECATIONS_CHANNEL=null
99
LOG_LEVEL=debug
1010

11+
# use this for docker
1112
DB_CONNECTION=mysql
12-
DB_HOST=mysql
13-
DB_PORT=3306
13+
DB_HOST=mysql
14+
DB_PORT=3306
1415
DB_DATABASE=LaravelInertiaVueSpa.Database_2024!
15-
DB_USERNAME=root
16+
DB_USERNAME=root
1617
DB_PASSWORD=LaravelInertiaVueSpa.Password_2024!
1718

19+
# modify this for sqlite
20+
# DB_DATABASE=/home/${yourusername}/${path}/database/database.sqlite
21+
1822
BROADCAST_DRIVER=log
1923
CACHE_DRIVER=file
2024
FILESYSTEM_DISK=local
@@ -55,4 +59,4 @@ VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
5559
VITE_PUSHER_HOST="${PUSHER_HOST}"
5660
VITE_PUSHER_PORT="${PUSHER_PORT}"
5761
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
58-
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
62+
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

.github/workflows/phpunit_action.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@ jobs:
1010
project-tests:
1111

1212
runs-on: ubuntu-latest
13-
13+
1414
steps:
1515
- uses: actions/checkout@v2
16-
16+
1717
- name: Copy .env
1818
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
19-
19+
2020
- name: Update Dependencies (if needed)
2121
run: composer update --no-ansi --no-interaction --no-scripts --no-progress
22-
22+
2323
- name: Install Dependencies
2424
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress
25-
25+
2626
- name: Generate key
2727
run: php artisan key:generate
28-
28+
2929
- name: Directory Permissions
3030
run: chmod -R 777 storage bootstrap/cache
31-
31+
3232
- name: Create Database
3333
run: |
3434
mkdir -p database
35-
touch database/database.sqlite
36-
35+
[ -f database/database.sqlite ] || touch database/database.sqlite
36+
3737
- name: Build assets for development
3838
env:
3939
LARAVEL_BYPASS_ENV_CHECK: 1
4040
run: npm install && npm run dev &
41-
41+
4242
- name: Wait for server to start
43-
run: sleep 10s
44-
43+
run: sleep 10s
44+
4545
- name: Execute tests (Unit and Feature tests) via PHPUnit
4646
env:
4747
DB_CONNECTION: sqlite

bootstrap/cache/.gitignore

100644100755
File mode changed.

config/database.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
|
1616
*/
1717

18-
'default' => env('DB_CONNECTION', 'mysql'),
18+
'default' => env('DB_CONNECTION', 'sqlite'),
1919

2020
/*
2121
|--------------------------------------------------------------------------
@@ -38,7 +38,7 @@
3838
'sqlite' => [
3939
'driver' => 'sqlite',
4040
'url' => env('DATABASE_URL'),
41-
'database' => env('DB_DATABASE', database_path('database.sqlite')),
41+
'database' => dirname(__DIR__).'/database/database.sqlite',
4242
'prefix' => '',
4343
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
4444
],

config/queue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686

8787
'failed' => [
8888
'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
89-
'database' => env('DB_CONNECTION', 'mysql'),
89+
'database' => env('DB_CONNECTION', 'sqlite'),
9090
'table' => 'failed_jobs',
9191
],
9292

database/factories/UserFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function definition(): array
2828
'name' => $this->faker->name(),
2929
'email' => $this->faker->unique()->safeEmail(),
3030
'email_verified_at' => now(),
31-
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
31+
'password' => $this->faker->password(8),
3232
'two_factor_secret' => null,
3333
'two_factor_recovery_codes' => null,
3434
'remember_token' => Str::random(10),

phpunit.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
<directory suffix="Test.php">./tests/Feature</directory>
99
</testsuite>
1010
</testsuites>
11-
<php>
12-
<env name="APP_ENV" value="testing"/>
11+
<env name="APP_ENV" value="testing" force="true" />
1312
<env name="BCRYPT_ROUNDS" value="4"/>
1413
<env name="CACHE_DRIVER" value="array"/>
1514
<env name="DB_CONNECTION" value="sqlite"/>
@@ -18,7 +17,6 @@
1817
<env name="QUEUE_CONNECTION" value="sync"/>
1918
<env name="SESSION_DRIVER" value="array"/>
2019
<env name="TELESCOPE_ENABLED" value="false"/>
21-
</php>
2220
<source>
2321
<include>
2422
<directory suffix=".php">./app</directory>

storage/app/.gitignore

100644100755
File mode changed.

storage/app/public/.gitignore

100644100755
File mode changed.

storage/framework/.gitignore

100644100755
File mode changed.

storage/framework/cache/.gitignore

100644100755
File mode changed.

storage/framework/cache/data/.gitignore

100644100755
File mode changed.

storage/framework/sessions/.gitignore

100644100755
File mode changed.

storage/framework/testing/.gitignore

100644100755
File mode changed.

storage/framework/views/.gitignore

100644100755
File mode changed.

storage/logs/.gitignore

100644100755
File mode changed.

tests/Feature/AuthenticationTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,21 @@ public function test_login_screen_can_be_rendered(): void
2020

2121
public function test_users_can_authenticate_using_the_login_screen(): void
2222
{
23-
$user = User::factory()->create();
23+
$password = 'password123';
24+
$user = User::factory()->create([
25+
'password' => bcrypt($password),
26+
]);
2427

2528
$response = $this->post('/login', [
2629
'email' => $user->email,
27-
'password' => 'password',
30+
'password' => $password,
2831
]);
2932

3033
$this->assertAuthenticated();
3134
$response->assertRedirect(RouteServiceProvider::HOME);
3235
}
3336

37+
3438
public function test_users_can_not_authenticate_with_invalid_password(): void
3539
{
3640
$user = User::factory()->create();

tests/Feature/BrowserSessionsTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class BrowserSessionsTest extends TestCase
1212

1313
public function test_other_browser_sessions_can_be_logged_out(): void
1414
{
15-
$this->actingAs($user = User::factory()->create());
15+
$user = User::factory()->create([
16+
'password' => bcrypt('password'),
17+
]);
18+
19+
$this->actingAs($user);
1620

1721
$response = $this->delete('/user/other-browser-sessions', [
1822
'password' => 'password',

tests/Feature/DeleteApiTokenTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function test_api_tokens_can_be_deleted(): void
2828
'abilities' => ['create', 'read'],
2929
]);
3030

31-
$response = $this->delete('/user/api-tokens/'.$token->id);
31+
$response = $this->delete('/user/api-tokens/' . $token->id);
3232

3333
$this->assertCount(0, $user->fresh()->tokens);
3434
}

tests/Feature/EmailVerificationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function test_email_can_be_verified(): void
5353
Event::assertDispatched(Verified::class);
5454

5555
$this->assertTrue($user->fresh()->hasVerifiedEmail());
56-
$response->assertRedirect(RouteServiceProvider::HOME.'?verified=1');
56+
$response->assertRedirect(RouteServiceProvider::HOME . '?verified=1');
5757
}
5858

5959
public function test_email_can_not_verified_with_invalid_hash(): void

tests/Feature/PasswordConfirmationTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,22 @@ public function test_confirm_password_screen_can_be_rendered(): void
2222

2323
public function test_password_can_be_confirmed(): void
2424
{
25-
$user = User::factory()->create();
25+
$user = User::factory()->create([
26+
'password' => bcrypt('password'),
27+
]);
2628

27-
$response = $this->actingAs($user)->post('/user/confirm-password', [
29+
$this->actingAs($user);
30+
31+
$response = $this->post('/user/confirm-password', [
2832
'password' => 'password',
2933
]);
3034

3135
$response->assertRedirect();
36+
3237
$response->assertSessionHasNoErrors();
3338
}
3439

40+
3541
public function test_password_is_not_confirmed_with_invalid_password(): void
3642
{
3743
$user = User::factory()->create();

tests/Feature/PasswordResetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function test_reset_password_screen_can_be_rendered(): void
6262
]);
6363

6464
Notification::assertSentTo($user, ResetPassword::class, function (object $notification) {
65-
$response = $this->get('/reset-password/'.$notification->token);
65+
$response = $this->get('/reset-password/' . $notification->token);
6666

6767
$response->assertStatus(200);
6868

tests/Feature/RoleManagementTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public function test_role_model_update_feature()
2727
$role = Role::factory()->create();
2828

2929
$response = $this->put('/roles/' . $role->id, [
30-
'name' => 'Updated role name']);
30+
'name' => 'Updated role name'
31+
]);
3132

3233
$this->assertDatabaseHas('roles', [
3334
'id' => $role->id,
@@ -90,5 +91,4 @@ public function test_role_user_count_is_shown_with_one_user()
9091

9192
$response->assertSee(1);
9293
}
93-
9494
}

tests/Feature/UpdatePasswordTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ class UpdatePasswordTest extends TestCase
1313

1414
public function test_password_can_be_updated(): void
1515
{
16-
$this->actingAs($user = User::factory()->create());
16+
$user = User::factory()->create([
17+
'password' => bcrypt('password'),
18+
]);
19+
20+
$this->actingAs(user: $user);
1721

1822
$response = $this->put('/user/password', [
1923
'current_password' => 'password',
@@ -26,7 +30,11 @@ public function test_password_can_be_updated(): void
2630

2731
public function test_current_password_must_be_correct(): void
2832
{
29-
$this->actingAs($user = User::factory()->create());
33+
$user = User::factory()->create([
34+
'password' => bcrypt('password'),
35+
]);
36+
37+
$this->actingAs($user);
3038

3139
$response = $this->put('/user/password', [
3240
'current_password' => 'wrong-password',
@@ -41,7 +49,11 @@ public function test_current_password_must_be_correct(): void
4149

4250
public function test_new_passwords_must_match(): void
4351
{
44-
$this->actingAs($user = User::factory()->create());
52+
$user = User::factory()->create([
53+
'password' => bcrypt('password'),
54+
]);
55+
56+
$this->actingAs($user);
4557

4658
$response = $this->put('/user/password', [
4759
'current_password' => 'password',

tests/Feature/UserManagementTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ public function test_user_model_update_feature()
2727

2828
$response = $this->put('/users/' . $user->id, [
2929
'name' => 'John Doe',
30-
'email' => 'updated@mail.com']);
31-
32-
$this->assertDatabaseHas('users', [
33-
'id' => $user->id,
34-
'name' => 'John Doe',
35-
'email' => 'updated@mail.com']
30+
'email' => 'updated@mail.com'
31+
]);
32+
33+
$this->assertDatabaseHas(
34+
'users',
35+
[
36+
'id' => $user->id,
37+
'name' => 'John Doe',
38+
'email' => 'updated@mail.com'
39+
]
3640
);
3741

3842
$response->assertStatus(302);

tests/Unit/ExampleTest.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)