From 11bea94de4936046f21cabf701f6367938699a69 Mon Sep 17 00:00:00 2001 From: Rihanrh <91171771+Rihanrh@users.noreply.github.com> Date: Thu, 16 May 2024 23:19:50 +0700 Subject: [PATCH 1/8] Create laravel.yml --- .github/workflows/laravel.yml | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/laravel.yml diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml new file mode 100644 index 0000000..fcc8e06 --- /dev/null +++ b/.github/workflows/laravel.yml @@ -0,0 +1,47 @@ +name: Laravel + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + laravel-tests: + + runs-on: ubuntu-latest + + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ROOT_PASSWORD: ${{ secrets.DB_PASSWORD }} + ports: + - 3306 + + steps: + - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e + with: + php-version: '8.0' + - uses: actions/checkout@v4 + - name: Copy .env + run: php -r "file_exists('.env') || copy('.env.example', '.env');" + - name: Install Dependencies + run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + - 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 + - name: Execute tests (Unit and Feature tests) via PHPUnit/Pest + env: + DB_CONNECTION: mysql + DB_HOST: ${{ secrets.DB_HOST }} + DB_PORT: ${{ secrets.DB_PORT }} + DB_DATABASE: ${{ secrets.DB_DATABASE }} + DB_USERNAME: ${{ secrets.DB_USERNAME }} + DB_PASSWORD: ${{ secrets.DB_PASSWORD }} + run: php artisan test From 5b62c570c5c9012b621c99fd13e82f559fbab83e Mon Sep 17 00:00:00 2001 From: Rihanrh Date: Thu, 16 May 2024 23:21:25 +0700 Subject: [PATCH 2/8] Update layouts.blade.php --- resources/views/products/layouts.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/products/layouts.blade.php b/resources/views/products/layouts.blade.php index c159d92..3124143 100644 --- a/resources/views/products/layouts.blade.php +++ b/resources/views/products/layouts.blade.php @@ -4,7 +4,7 @@ - Laravel 10 CRUD Application Tutorial - AllPHPTricks.com + CI/CD TESTING - GROUP TUGAS CERIA From 4ba29e767cbbc9b26242b4233d25ff15c95d9819 Mon Sep 17 00:00:00 2001 From: Rihanrh Date: Thu, 16 May 2024 23:26:56 +0700 Subject: [PATCH 3/8] Update laravel.yml --- .github/workflows/laravel.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index fcc8e06..de97505 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -26,8 +26,8 @@ jobs: - uses: actions/checkout@v4 - name: Copy .env run: php -r "file_exists('.env') || copy('.env.example', '.env');" - - name: Install Dependencies - run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist + - name: Update Dependencies + run: composer update --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - name: Generate key run: php artisan key:generate - name: Directory Permissions From 49da5a805fbe63d5dce058d197280d07a823a454 Mon Sep 17 00:00:00 2001 From: Rihanrh Date: Thu, 16 May 2024 23:28:33 +0700 Subject: [PATCH 4/8] Update laravel.yml --- .github/workflows/laravel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index de97505..dc34aad 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -22,7 +22,7 @@ jobs: steps: - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e with: - php-version: '8.0' + php-version: '8.1' - uses: actions/checkout@v4 - name: Copy .env run: php -r "file_exists('.env') || copy('.env.example', '.env');" From ae780fcac795d73d6ecefe0aca1814acb69fff3e Mon Sep 17 00:00:00 2001 From: Rihanrh Date: Thu, 16 May 2024 23:34:34 +0700 Subject: [PATCH 5/8] Update laravel.yml --- .github/workflows/laravel.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index dc34aad..ca702bb 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -15,7 +15,7 @@ jobs: mysql: image: mysql:5.7 env: - MYSQL_ROOT_PASSWORD: ${{ secrets.DB_PASSWORD }} + MYSQL_ALLOW_EMPTY_PASSWORD: "yes" ports: - 3306 @@ -39,9 +39,9 @@ jobs: - name: Execute tests (Unit and Feature tests) via PHPUnit/Pest env: DB_CONNECTION: mysql - DB_HOST: ${{ secrets.DB_HOST }} - DB_PORT: ${{ secrets.DB_PORT }} + DB_HOST: 127.0.0.1 + DB_PORT: ${{ job.services.mysql.ports[3306] }} DB_DATABASE: ${{ secrets.DB_DATABASE }} - DB_USERNAME: ${{ secrets.DB_USERNAME }} - DB_PASSWORD: ${{ secrets.DB_PASSWORD }} + DB_USERNAME: root + DB_PASSWORD: "" run: php artisan test From 807eb31f8399334553803521860e1aaf5cc8f1ec Mon Sep 17 00:00:00 2001 From: Rihanrh Date: Thu, 16 May 2024 23:36:00 +0700 Subject: [PATCH 6/8] Update layouts.blade.php --- resources/views/products/layouts.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/products/layouts.blade.php b/resources/views/products/layouts.blade.php index 3124143..aebfbf5 100644 --- a/resources/views/products/layouts.blade.php +++ b/resources/views/products/layouts.blade.php @@ -4,7 +4,7 @@ - CI/CD TESTING - GROUP TUGAS CERIA + Group Tugas Ceria - CI/CD Test From 26026df51560ecafaff4339d22dd4a3f8eb01a9f Mon Sep 17 00:00:00 2001 From: jaatsiyah Date: Sat, 18 May 2024 17:58:54 +0700 Subject: [PATCH 7/8] Unit Test added --- tests/Feature/funcCreateTest.php | 26 ++++++++++++++++ tests/Feature/funcCreateUpdate.php | 26 ++++++++++++++++ tests/Feature/funcDeleteTest.php | 38 +++++++++++++++++++++++ tests/Feature/funcUpdateTest.php | 48 ++++++++++++++++++++++++++++++ tests/Feature/funcViewTest.php | 33 ++++++++++++++++++++ 5 files changed, 171 insertions(+) create mode 100644 tests/Feature/funcCreateTest.php create mode 100644 tests/Feature/funcCreateUpdate.php create mode 100644 tests/Feature/funcDeleteTest.php create mode 100644 tests/Feature/funcUpdateTest.php create mode 100644 tests/Feature/funcViewTest.php diff --git a/tests/Feature/funcCreateTest.php b/tests/Feature/funcCreateTest.php new file mode 100644 index 0000000..830b42a --- /dev/null +++ b/tests/Feature/funcCreateTest.php @@ -0,0 +1,26 @@ +get(route('products.create')); + + $response->assertStatus(200); + + $response->assertViewIs('products.create'); + } +} diff --git a/tests/Feature/funcCreateUpdate.php b/tests/Feature/funcCreateUpdate.php new file mode 100644 index 0000000..c10b33c --- /dev/null +++ b/tests/Feature/funcCreateUpdate.php @@ -0,0 +1,26 @@ +get(route('products.create')); + + $response->assertStatus(200); + + $response->assertViewIs('products.create'); + } +} diff --git a/tests/Feature/funcDeleteTest.php b/tests/Feature/funcDeleteTest.php new file mode 100644 index 0000000..4b475f0 --- /dev/null +++ b/tests/Feature/funcDeleteTest.php @@ -0,0 +1,38 @@ + 'P12345', + 'name' => 'Product to be deleted', + 'quantity' => 10, + 'price' => 99.99, + 'description' => 'Product description', + ]); + + // Send the delete request + $response = $this->delete(route('products.destroy', $product->id)); + + // Assert the response status + $response->assertRedirect(route('products.index')); + $response->assertSessionHas('success', 'Product is deleted successfully.'); + + // Assert the product was deleted + $this->assertDatabaseMissing('products', ['id' => $product->id]); + } +} diff --git a/tests/Feature/funcUpdateTest.php b/tests/Feature/funcUpdateTest.php new file mode 100644 index 0000000..390f090 --- /dev/null +++ b/tests/Feature/funcUpdateTest.php @@ -0,0 +1,48 @@ + 'H001', + 'name' => 'Kaveh', + 'quantity' => 1, + 'price' => 99.99, + 'description' => 'Husbunya Ren', + ]); + + $updateData = [ + 'code' => 'H001', + 'name' => 'Kaveh', + 'quantity' => 1, + 'price' => 199.99, + 'description' => 'Malewife keduanya Ren', + ]; + + $response = $this->put(route('products.update', $product->id), $updateData); + + $response->assertRedirect(); + $response->assertSessionHas('success', 'Product is updated successfully.'); + + $updatedProduct = Product::find($product->id); + + $this->assertEquals($updateData['code'], $updatedProduct->code); + $this->assertEquals($updateData['name'], $updatedProduct->name); + $this->assertEquals($updateData['quantity'], $updatedProduct->quantity); + $this->assertEquals($updateData['price'], $updatedProduct->price); + $this->assertEquals($updateData['description'], $updatedProduct->description); + } +} diff --git a/tests/Feature/funcViewTest.php b/tests/Feature/funcViewTest.php new file mode 100644 index 0000000..e54c1d5 --- /dev/null +++ b/tests/Feature/funcViewTest.php @@ -0,0 +1,33 @@ + 'H001', + 'name' => 'Kaveh', + 'quantity' => 1, + 'price' => 99.99, + 'description' => 'Husbunya Ren', + ]); + + $response = $this->get(route('products.show', $product->id)); + + $response->assertStatus(200); + $response->assertViewIs('products.show'); + $response->assertViewHas('product', $product); + } +} From 9476c99413bb1c73118c2b5d44c2eab84d012eec Mon Sep 17 00:00:00 2001 From: jaatsiyah Date: Wed, 5 Jun 2024 20:04:49 +0700 Subject: [PATCH 8/8] Unit test changed --- tests/Feature/funcViewTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Feature/funcViewTest.php b/tests/Feature/funcViewTest.php index e54c1d5..ea7f65b 100644 --- a/tests/Feature/funcViewTest.php +++ b/tests/Feature/funcViewTest.php @@ -18,7 +18,7 @@ public function test_show_product(): void { $product = Product::create([ 'code' => 'H001', - 'name' => 'Kaveh', + 'name' => 'Kaaveh', 'quantity' => 1, 'price' => 99.99, 'description' => 'Husbunya Ren',