feat: complete Smartgift AI Laravel unit testing toolkit

- Add 10 core testing guides (setup, AAA principles, PHPUnit/Pest, mocking, anti-patterns, PHP 8.4+, debugging, data factories, advanced edge cases)
- Add 13 component testing guides covering all Laravel layers
- Add standard templates for PHPUnit 10/11 and Pest v2/v3 including ArchitectureTest
- Add Docker smart test runner, dependency installer, and CI/CD templates (GitHub Actions, GitLab CI)
- Add 4 Claude Code skills (laravel-test-setup, laravel-unit-test with --all mode, laravel-test-review, laravel-mock-helper)
- Add single unified installer script (sg-install-unit-testing.sh) with global support, CLI runners, and 1-click updater (sg-test-update)
- Add comprehensive documentation (README.md, USAGE-GUIDE.md)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-07 16:41:37 +07:00
commit 2045c856e9
60 changed files with 5248 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
services:
test-runner:
image: php:8.3-cli-alpine
container_name: laravel_unit_tester
working_dir: /var/www/html
volumes:
- ./:/var/www/html
environment:
- APP_ENV=testing
- DB_CONNECTION=sqlite
- DB_DATABASE=:memory:
- BCRYPT_ROUNDS=4
- CACHE_STORE=array
- QUEUE_CONNECTION=sync
- MAIL_MAILER=array
command: >
sh -c "
apk add --no-cache sqlite-libs libzip-dev zip unzip git &&
docker-php-ext-install pdo pdo_sqlite zip &&
php artisan test
"
+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
# ==============================================================================
# Smart Test Runner for Laravel
# Tự động nhận diện môi trường: Laravel Sail -> Docker Compose -> Local PHP
# ==============================================================================
set -e
# Màu sắc thông báo
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${YELLOW}🔍 Đang phát hiện môi trường chạy test...${NC}"
# Hàm chạy test
run_test() {
local runner="$1"
shift
echo -e "${GREEN}🚀 Chạy test bằng: ${runner} $*${NC}"
$runner "$@"
}
# 1. Kiểm tra Laravel Sail
if [ -f "./vendor/bin/sail" ] && docker info >/dev/null 2>&1; then
if docker ps --format '{{.Names}}' | grep -q "laravel.test"; then
echo -e "${GREEN}✓ Phát hiện Laravel Sail đang hoạt động.${NC}"
run_test "./vendor/bin/sail test" "$@"
exit 0
fi
fi
# 2. Kiểm tra Docker Compose tự cấu hình
if [ -f "docker-compose.yml" ] || [ -f "compose.yaml" ]; then
if docker info >/dev/null 2>&1; then
# Tìm container service chạy php
SERVICES=("app" "php" "php-fpm" "backend" "workspace" "web")
for svc in "${SERVICES[@]}"; do
if docker compose ps --services --filter "status=running" 2>/dev/null | grep -q "^${svc}$"; then
echo -e "${GREEN}✓ Phát hiện Docker Compose với service: '${svc}'${NC}"
run_test "docker compose exec -T ${svc} php artisan test" "$@"
exit 0
fi
done
fi
fi
# 3. Fallback về PHP CLI cục bộ
if command -v php >/dev/null 2>&1; then
echo -e "${YELLOW}ℹ Không tìm thấy container Docker đang chạy. Chuyển về PHP CLI máy local.${NC}"
# Kiểm tra extension pdo_sqlite
if ! php -m | grep -q -i sqlite; then
echo -e "${RED}⚠️ Cảnh báo: PHP CLI hiện tại chưa bật extension pdo_sqlite. Unit test dùng In-memory SQLite có thể bị lỗi!${NC}"
fi
run_test "php artisan test" "$@"
exit 0
fi
echo -e "${RED}❌ Không tìm thấy môi trường phù hợp (Sail, Docker Compose hoặc PHP CLI) để chạy test!${NC}"
exit 1