Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflows #1

Merged
merged 9 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .github/workflows/php-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Laravel Tests
on: push

jobs:
laravel-tests:
runs-on: ubuntu-latest
# Service container Mysql mysql
services:
# Label used to access the service container
mysql:
# Docker Hub image (also with version)
image: mysql:8
env:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: testing
## map the "external" 33306 port with the "internal" 3306
ports:
- 33306:3306
# Set health checks to wait until mysql database has started (it takes some seconds to start)
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3

strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: [ '8.2' ]
dependency-stability: [ prefer-stable ]

name: P${{ matrix.php-versions }} - L${{ matrix.laravel }} - ${{ matrix.dependency-stability }} - ${{ matrix.operating-system}}

steps:
- uses: actions/checkout@v2
- name: Install PHP versions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
- name: Get Composer Cache Directory 2
working-directory: ./src
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
id: actions-cache
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Cache PHP dependencies
uses: actions/cache@v2
id: vendor-cache
with:
path: ./src/vendor
key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }}
- name: Copy .env
working-directory: ./src
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
working-directory: ./src
run: composer install --no-interaction --prefer-dist --optimize-autoloader

- name: Create storage folders
working-directory: ./src
run: mkdir -p storage/framework/{sessions,views,cache}
- name: Directory Permissions
working-directory: ./src
run: chmod -R 777 storage bootstrap/cache

- name: Show dir
working-directory: ./src
run: pwd
- name: PHP Version
run: php --version

# Code quality
- name: Execute tests (Unit and Feature tests) via PestPHP
working-directory: ./src
# Set environment
env:
DB_CONNECTION: mysql
DB_HOST: 127.0.0.1
DB_DATABASE: testing
DB_PORT: 33306
DB_USERNAME: root
DB_PASSWORD: secret
run: |
php artisan key:generate
php artisan migrate
php artisan test

- name: Run Pint
working-directory: ./src
run: vendor/bin/pint
24 changes: 24 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: PHPStan

on: push

jobs:
phpstan:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'

- name: Install Dependencies
working-directory: ./src
run: composer install

- name: Run PHPStan
working-directory: ./src
run: vendor/bin/phpstan analyze app
66 changes: 0 additions & 66 deletions src/README.md

This file was deleted.

6 changes: 2 additions & 4 deletions src/app/Http/Controllers/BookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Http\Controllers;


use App\Http\Requests\BookDestroyRequest;
use App\Http\Requests\BookStoreRequest;
use App\Http\Requests\BookUpdateRequest;
use App\Http\Resources\BookCollection;
Expand All @@ -30,7 +28,7 @@ public function store(BookStoreRequest $request)
'title' => $request->title,
'author' => $request->author,
'published_at' => $request->published_at,
'isbn' => $request->isbn
'isbn' => $request->isbn,
]);

return new BookResource($bookModel);
Expand Down Expand Up @@ -72,4 +70,4 @@ public function delete(int $id)
'company' => new BookResource($book),
]);
}
}
}
3 changes: 1 addition & 2 deletions src/app/Http/Requests/BookStoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class BookStoreRequest extends FormRequest
{

public function authorize(): bool
{
return true;
Expand All @@ -20,7 +19,7 @@ public function rules(): array
'title' => $requiredString,
'author' => $requiredString,
'published_at' => 'required|date_format:Y-m-d',
'isbn' => 'required|string|max:13|min:13'
'isbn' => 'required|string|max:13|min:13',
];
}
}
3 changes: 1 addition & 2 deletions src/app/Http/Requests/BookUpdateRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class BookUpdateRequest extends FormRequest
{

public function authorize(): bool
{
return true;
Expand All @@ -20,7 +19,7 @@ public function rules(): array
'title' => $requiredString,
'author' => $requiredString,
'published_at' => 'required|date_format:Y-m-d',
'isbn' => 'required|string|max:13|min:13'
'isbn' => 'required|string|max:13|min:13',
];
}
}
4 changes: 2 additions & 2 deletions src/app/Http/Resources/BookResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function toArray(Request $request): array
'title' => $this->title,
'author' => $this->author,
'published_at' => $this->published_at->format('Y-m-d'),
'isbn' => $this->isbn
'isbn' => $this->isbn,
];
}
}
}
3 changes: 1 addition & 2 deletions src/app/Interfaces/BookRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ public function find(int $id);
public function delete(int $id);

public function update(int $id, array $data);

}
}
7 changes: 3 additions & 4 deletions src/app/Models/Book.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Book extends Model
Expand All @@ -16,10 +15,10 @@ class Book extends Model
'title',
'author',
'published_at',
'isbn'
'isbn',
];

protected $casts = [
'published_at' => 'date'
'published_at' => 'date',
];
}
}
2 changes: 0 additions & 2 deletions src/app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Providers;

use Dedoc\Scramble\Scramble;
use Dedoc\Scramble\Support\Generator\OpenApi;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
Expand Down
2 changes: 1 addition & 1 deletion src/app/Repositories/BookRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public function update(int $id, array $data)

return $book;
}
}
}
2 changes: 2 additions & 0 deletions src/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"laravel/sail": "^1.18",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"pestphp/pest": "^2.34",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^10.1",
"spatie/laravel-ignition": "^2.0"
},
Expand Down
Loading
Loading