diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml
new file mode 100644
index 0000000..ca702bb
--- /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_ALLOW_EMPTY_PASSWORD: "yes"
+ ports:
+ - 3306
+
+ steps:
+ - uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
+ with:
+ php-version: '8.1'
+ - uses: actions/checkout@v4
+ - name: Copy .env
+ run: php -r "file_exists('.env') || copy('.env.example', '.env');"
+ - 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
+ 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: 127.0.0.1
+ DB_PORT: ${{ job.services.mysql.ports[3306] }}
+ DB_DATABASE: ${{ secrets.DB_DATABASE }}
+ DB_USERNAME: root
+ DB_PASSWORD: ""
+ run: php artisan test
diff --git a/resources/views/products/layouts.blade.php b/resources/views/products/layouts.blade.php
index c159d92..aebfbf5 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
+ Group Tugas Ceria - CI/CD Test
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..ea7f65b
--- /dev/null
+++ b/tests/Feature/funcViewTest.php
@@ -0,0 +1,33 @@
+ 'H001',
+ 'name' => 'Kaaveh',
+ '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);
+ }
+}