Skip to content

Commit

Permalink
Pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ikhsan3adi committed Jun 16, 2024
1 parent 87bda8f commit a97e8a2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
35 changes: 25 additions & 10 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
name: Laravel
name: Laravel Tests

on:
push:
branches: [ "master" ]
branches: [ "master", "main" ]
pull_request:
branches: [ "master" ]

env:
DB_CONNECTION: mysql
DB_DATABASE: db_absensi_karyawan_test
DB_PASSWORD: null

jobs:
laravel-tests:

runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
# The MySQL docker container requires these environment variables to be set
# so we can create and migrate the test database.
# See: https://hub.docker.com/_/mysql
MYSQL_ALLOW_EMPTY_PASSWORD: 1
MYSQL_DATABASE: $DB_DATABASE
MYSQL_ROOT_PASSWORD: $DB_PASSWORD
ports:
# Opens port 3306 on service container and host
# https://docs.github.com/en/actions/using-containerized-services/about-service-containers
- 3306:3306
# Before continuing, verify the mysql container is reachable from the ubuntu host
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
Expand All @@ -24,12 +43,8 @@ jobs:
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
- name: Execute tests (Unit and Feature tests) via PHPUnit/Pest
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
DB_CONNECTION: $DB_CONNECTION
DB_DATABASE: $DB_DATABASE
run: php artisan test
14 changes: 13 additions & 1 deletion tests/Feature/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@
]);

$this->assertAuthenticated();
$response->assertRedirect(route('dashboard', absolute: false));
$response->assertRedirect('/');
});

test('admin users can authenticate using the login screen', function () {
$user = User::factory()->admin()->create();

$response = $this->post('/login', [
'email' => $user->email,
'password' => 'password',
]);

$this->assertAuthenticated();
$response->assertRedirect('/admin');
});

test('users cannot authenticate with invalid password', function () {
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

it('returns a successful response', function () {
$response = $this->get('/');
$response = $this->get('/login');

$response->assertStatus(200);
});
2 changes: 1 addition & 1 deletion tests/Feature/RegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
]);

$this->assertAuthenticated();
$response->assertRedirect(route('dashboard', absolute: false));
$response->assertRedirect('/dashboard');
})->skip(function () {
return !Features::enabled(Features::registration());
}, 'Registration support is not enabled.');

0 comments on commit a97e8a2

Please sign in to comment.