feat: add comprehensive unit testing support for CakePHP
- Add 4 CakePHP Claude Code skills: cakephp-unit-test, cakephp-test-setup, cakephp-test-review, cakephp-mock-helper - Add 11 CakePHP PHPUnit component templates (Table, Entity, Controller, Service, Command, Component, Middleware, Mailer, Form, Behavior, Helper) - Add CakePHP configs (phpunit.xml.dist, app_local.test.php for SQLite in-memory) - Add comprehensive CakePHP documentation and component guides - Update test-runner.sh and installer to auto-detect Laravel and CakePHP - Add CakePHP CI/CD templates for GitHub Actions and GitLab CI - Update system prompt, verification checklist, and README with dedicated guides
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#!/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
|
||||
# Smart Dependency Installer for Laravel & CakePHP Testing
|
||||
# Tự động phát hiện gói còn thiếu và cài đặt qua Docker hoặc Local Composer
|
||||
# ==============================================================================
|
||||
|
||||
set -e
|
||||
@@ -11,10 +11,11 @@ GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
RED='\033[0;31m'
|
||||
CYAN='\033[0;36m'
|
||||
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 "${CYAN} Tự Động Cài Đặt Thư Viện Cần Thiết Cho Unit Test (Laravel & CakePHP)${NC}"
|
||||
echo -e "${BLUE}===================================================================${NC}"
|
||||
|
||||
if [ ! -f "composer.json" ]; then
|
||||
@@ -22,14 +23,24 @@ if [ ! -f "composer.json" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 1. Xác định môi trường thực thi lệnh composer
|
||||
# 1. Xác định Framework
|
||||
FRAMEWORK="generic"
|
||||
if [ -f "bin/cake" ] || grep -q '"cakephp/cakephp"' composer.json; then
|
||||
FRAMEWORK="cakephp"
|
||||
echo -e "${GREEN}✓ Dự án: CakePHP${NC}"
|
||||
elif [ -f "artisan" ] || grep -q '"laravel/framework"' composer.json; then
|
||||
FRAMEWORK="laravel"
|
||||
echo -e "${GREEN}✓ Dự án: Laravel${NC}"
|
||||
fi
|
||||
|
||||
# 2. 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")
|
||||
SERVICES=("app" "web" "php" "php-fpm" "backend" "workspace")
|
||||
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}"
|
||||
@@ -43,17 +54,27 @@ 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"
|
||||
elif [ -f "composer.phar" ]; then
|
||||
echo -e "${YELLOW}ℹ Môi trường: Sử dụng composer.phar cục bộ.${NC}"
|
||||
COMPOSER_CMD="php composer.phar"
|
||||
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
|
||||
# 3. 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 PHPUnit nếu là CakePHP
|
||||
if [ "$FRAMEWORK" = "cakephp" ]; then
|
||||
if ! grep -q '"phpunit/phpunit"' composer.json; then
|
||||
PACKAGES_TO_INSTALL+=("phpunit/phpunit")
|
||||
fi
|
||||
fi
|
||||
|
||||
# Kiểm tra Mockery
|
||||
if ! grep -q '"mockery/mockery"' composer.json; then
|
||||
PACKAGES_TO_INSTALL+=("mockery/mockery")
|
||||
@@ -64,29 +85,31 @@ 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 [ "$FRAMEWORK" = "laravel" ]; then
|
||||
# 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")
|
||||
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
|
||||
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
|
||||
# 4. 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
|
||||
|
||||
Reference in New Issue
Block a user