Skip to content

Commit

Permalink
Merge pull request #5 from binafy/add-pint-action
Browse files Browse the repository at this point in the history
[1.x] Add Pint action
  • Loading branch information
milwad-dev authored Jun 29, 2024
2 parents 20acac6 + cf7c846 commit 75a233e
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 16 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Fix Code Style

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
php: [8.3]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json, dom, curl, libxml, mbstring
coverage: none

- name: Install Pint
run: composer global require laravel/pint

- name: Run Pint
run: pint

- name: Commit linted files
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Fixes coding style"

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
},
"require-dev": {
"pestphp/pest-plugin-laravel": "^1.4.0|^2.0.0",
"orchestra/testbench": "^7.0|^8.0|^9.0"
"orchestra/testbench": "^7.0|^8.0|^9.0",
"laravel/pint": "^1.5"
},
"config": {
"sort-packages": true,
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function scopeFirstOrCreateWithStoreItems(
Builder $query,
Model $item,
int $quantity = 1,
int|null $userId = null
?int $userId = null
): Builder {
if (is_null($userId)) {
$userId = auth()->id();
Expand Down
8 changes: 4 additions & 4 deletions src/Providers/LaravelCartServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class LaravelCartServiceProvider extends ServiceProvider
*/
public function register(): void
{
$this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');
$this->mergeConfigFrom(__DIR__ . '/../../config/laravel-cart.php', 'laravel-cart');
$this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
$this->mergeConfigFrom(__DIR__.'/../../config/laravel-cart.php', 'laravel-cart');
}

/**
Expand All @@ -22,12 +22,12 @@ public function boot(): void
{
// Publish Config
$this->publishes([
__DIR__ . '/../../config/laravel-cart.php' => config_path('laravel-cart.php'),
__DIR__.'/../../config/laravel-cart.php' => config_path('laravel-cart.php'),
], 'laravel-cart-config');

// Publish Migrations
$this->publishes([
__DIR__ . '/../../database/migrations' => database_path('migrations'),
__DIR__.'/../../database/migrations' => database_path('migrations'),
], 'laravel-cart-migrations');
}
}
7 changes: 2 additions & 5 deletions tests/Feature/CartDeleteTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php

use Binafy\LaravelCart\Models\Cart;
use Binafy\LaravelCart\Models\CartItem;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Tests\SetUp\Models\Product;
use Tests\SetUp\Models\User;

use function Pest\Laravel\assertDatabaseCount;
use function Pest\Laravel\assertDatabaseHas;
use function PHPUnit\Framework\assertInstanceOf;

/*
* Use `RefreshDatabase` for delete migration data for each test.
Expand Down Expand Up @@ -59,7 +56,7 @@
assertDatabaseCount('cart_items', 2);
});

test('can empty the cart', function() {
test('can empty the cart', function () {
$user = User::query()->create(['name' => 'Milwad', 'email' => 'milwad.dev@gmail.comd']);
$product1 = Product::query()->create(['title' => 'Product 1']);
$product2 = Product::query()->create(['title' => 'Product 2']);
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/CartStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Support\Facades\Artisan;
use Tests\SetUp\Models\Product;
use Tests\SetUp\Models\User;

use function Pest\Laravel\assertDatabaseCount;
use function Pest\Laravel\assertDatabaseHas;
use function PHPUnit\Framework\assertInstanceOf;
Expand Down
1 change: 0 additions & 1 deletion tests/SetUp/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Tests\SetUp\Models;


use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
/**
* Load package service provider.
*
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Foundation\Application $app
*/
protected function getPackageProviders($app): array
{
Expand All @@ -22,16 +22,16 @@ protected function getPackageProviders($app): array
/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
* @param \Illuminate\Foundation\Application $app
*/
protected function getEnvironmentSetUp($app): void
{
// Set default database to use sqlite :memory:
$app['config']->set('database.default', 'testing');
$app['config']->set('database.connections.testing', [
'driver' => 'sqlite',
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
'prefix' => '',
]);

// Set app key
Expand Down

0 comments on commit 75a233e

Please sign in to comment.