Files
agent-unit-testing/templates/setup-dependencies.sh
T
Pham-Tan-Thien 2045c856e9 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>
2026-09-07 16:41:37 +07:00

108 lines
3.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# ==============================================================================
# Smart Dependency Installer for Laravel Testing
# Tự động phát hiện gói còn thiếu và cài đặt qua Docker (Sail / Compose) hoặc Local Composer
# ==============================================================================
set -e
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${BLUE}===================================================================${NC}"
echo -e "${BLUE} Tự Động Cài Đặt Thư Viện Cần Thiết Cho Unit Test Laravel${NC}"
echo -e "${BLUE}===================================================================${NC}"
if [ ! -f "composer.json" ]; then
echo -e "${RED}❌ Lỗi: Không tìm thấy file composer.json trong thư mục hiện tại!${NC}"
exit 1
fi
# 1. Xác định môi trường thực thi lệnh composer
COMPOSER_CMD=""
if [ -f "./vendor/bin/sail" ] && docker info >/dev/null 2>&1 && docker ps --format '{{.Names}}' | grep -q "laravel.test"; then
echo -e "${GREEN}✓ Môi trường: Laravel Sail đang hoạt động.${NC}"
COMPOSER_CMD="./vendor/bin/sail composer"
elif [ -f "docker-compose.yml" ] || [ -f "compose.yaml" ]; then
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}✓ Môi trường: Docker Compose (service: ${svc}).${NC}"
COMPOSER_CMD="docker compose exec -T ${svc} composer"
break
fi
done
fi
if [ -z "$COMPOSER_CMD" ]; then
if command -v composer >/dev/null 2>&1; then
echo -e "${YELLOW}ℹ Môi trường: Composer trên máy cục bộ (Local).${NC}"
COMPOSER_CMD="composer"
else
echo -e "${RED}❌ Lỗi: Không tìm thấy Composer trên máy hoặc trong container Docker!${NC}"
exit 1
fi
fi
# 2. Phân tích composer.json xem thiếu gói nào
echo -e "\n${YELLOW}🔍 Đang kiểm tra dependencies hiện có...${NC}"
PACKAGES_TO_INSTALL=()
# Kiểm tra Mockery
if ! grep -q '"mockery/mockery"' composer.json; then
PACKAGES_TO_INSTALL+=("mockery/mockery")
fi
# Kiểm tra Faker
if ! grep -q '"fakerphp/faker"' composer.json; then
PACKAGES_TO_INSTALL+=("fakerphp/faker")
fi
# Kiểm tra Test Runner (Pest vs PHPUnit)
IS_PEST=false
if grep -q '"pestphp/pest"' composer.json; then
IS_PEST=true
fi
if [ "$IS_PEST" = true ]; then
if ! grep -q '"pestphp/pest-plugin-laravel"' composer.json; then
PACKAGES_TO_INSTALL+=("pestphp/pest-plugin-laravel")
fi
fi
# Kiểm tra công cụ chạy song song (Paratest)
if ! grep -q '"brianium/paratest"' composer.json; then
PACKAGES_TO_INSTALL+=("brianium/paratest")
fi
# Kiểm tra Collision
if ! grep -q '"nunomaduro/collision"' composer.json; then
PACKAGES_TO_INSTALL+=("nunomaduro/collision")
fi
# 3. Tiến hành cài đặt
if [ ${#PACKAGES_TO_INSTALL[@]} -eq 0 ]; then
echo -e "${GREEN}🎉 Tuyệt vời! Dự án đã có đầy đủ các thư viện kiểm thử cần thiết!${NC}"
exit 0
fi
echo -e "${YELLOW}📦 Các gói cần cài đặt bổ sung:${NC}"
for pkg in "${PACKAGES_TO_INSTALL[@]}"; do
echo -e " - ${BLUE}$pkg${NC}"
done
INSTALL_COMMAND="$COMPOSER_CMD require --dev ${PACKAGES_TO_INSTALL[*]} --with-all-dependencies"
echo -e "\n${YELLOW}🚀 Đang thực thi lệnh cài đặt:${NC}"
echo -e " $INSTALL_COMMAND\n"
eval "$INSTALL_COMMAND"
echo -e "\n${GREEN}✅ Đã cài đặt hoàn tất các thư viện test cho dự án!${NC}"