diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml new file mode 100644 index 0000000..c812e64 --- /dev/null +++ b/.github/workflows/laravel.yml @@ -0,0 +1,35 @@ +name: Laravel + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + laravel-tests: + + runs-on: ubuntu-latest + + 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: 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: sqlite + DB_DATABASE: database/database.sqlite + run: php artisan test diff --git a/composer.lock b/composer.lock index 183f533..e9f5081 100644 --- a/composer.lock +++ b/composer.lock @@ -8057,5 +8057,5 @@ "php": "^8.1" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/resources/views/products/index.blade.php b/resources/views/products/index.blade.php index 1150158..06918bd 100644 --- a/resources/views/products/index.blade.php +++ b/resources/views/products/index.blade.php @@ -35,7 +35,7 @@ {{ $product->quantity }} {{ $product->price }} -
+ @csrf @method('DELETE') @@ -43,7 +43,7 @@ Edit - +
@@ -63,5 +63,26 @@ - -@endsection + +@forelse ($products as $product) + +@empty +@endforelse + +@endsection \ No newline at end of file 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/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..093e4f2 --- /dev/null +++ b/tests/Feature/funcViewTest.php @@ -0,0 +1,33 @@ + 'H0012', + '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); + } +}