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

add husk #18

Merged
merged 4 commits into from
Nov 6, 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
5 changes: 5 additions & 0 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,25 @@ jobs:
run: |
mkdir -p database
touch database/database.sqlite
- name: Clean Node Modules and Lock File
run: |
rm -rf node_modules package-lock.json
- name: Installing Package.json
run: npm install

- name: Build Assets
run: npm run build

- name: Execute tests (Unit and Feature tests) via Pest
env:
DB_CONNECTION: sqlite
DB_DATABASE: database/database.sqlite
run: php artisan test --parallel

- name: Execute Larastan
run: vendor/bin/phpstan analyse

- name: Execute Pint
run: vendor/bin/pint --test
35 changes: 35 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Executa o PHPStan para análise estática do código
echo "Executando PHPStan para análise estática..."
./vendor/bin/phpstan analyse --memory-limit=512M

# Verifica o status de saída do PHPStan
if [ $? -ne 0 ]; then
echo "hehe Deu ruim cumpadi.... Erros encontrados pelo PHPStan. Corrija-os antes de realizar o commit."
exit 1
fi

# Executa o PHPUnit para testes automatizados em parallel
echo "Executando textes em paralelo..."
php artisan test --parallel
if [ $? -ne 0 ]; then
echo "hehe Deu ruim cumpadi.... 1 ou mais testes deram errado. Corrija-os antes de realizar o commit."
exit 1
fi

# Executa o Laravel Pint com correção automática
echo "Executando Laravel Pint para corrigir o código..."
./vendor/bin/pint

# Verifica se houve alterações após a execução do Pint
if [ -n "$(git status --porcelain)" ]; then
echo "O Laravel Pint corrigiu os seguintes arquivos:"
git status --porcelain

# Adiciona as alterações corrigidas ao commit
git add -u
echo "As alterações corrigidas foram adicionadas ao commit."
else
echo "Laravel Pint executado com sucesso, sem alterações necessárias!"
fi
10 changes: 9 additions & 1 deletion app/Http/Controllers/QuestionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ public function store(Request $request): RedirectResponse
{

$atributes = request()->validate([
'question' => ['required', 'min:10'],
'question' => [
'required',
'min:10',
function (string $atribute, mixed $value, callable $fail) {
if ($value[strlen($value) - 1] !== '?') {
$fail('Are you sure it is a question? It should end with a question mark in the end.');
}
},
],
]);

Question::query()->create($atributes);
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 18 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.2",
"alpinejs": "^3.4.2",
"autoprefixer": "^10.4.2",
"axios": "^1.7.4",
"laravel-vite-plugin": "^1.0.5",
"postcss": "^8.4.31",
"tailwindcss": "^3.1.0",
"vite": "^5.0"
}
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"prepare": "husky"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.2",
"alpinejs": "^3.4.2",
"autoprefixer": "^10.4.2",
"axios": "^1.7.4",
"husky": "^9.1.6",
"laravel-vite-plugin": "^1.0.5",
"postcss": "^8.4.31",
"tailwindcss": "^3.1.0",
"vite": "^5.0"
}
}
13 changes: 13 additions & 0 deletions tests/Feature/CreateAQuestionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@

it('shold check if ends with question mark?', function () {

//Arrange::preparar
$user = User::factory()->create();
actingAs($user);

//Act::agir
$request = post(route('questions.store'), [
'question' => str_repeat('#', 10),
]);

//Assert::verificar
$request->assertSessionHasErrors(['question' => 'Are you sure it is a question? It should end with a question mark in the end.']);
assertDatabaseCount('questions', 0);

});

it('should have at least 10 characters', function () {
Expand Down
Loading