- Implemented SecurityTest to validate token generation, CSRF protection, input sanitization, and rate limiting. - Created UserModelTest to ensure correct database operations for user management, including creation, updating, banning, and fetching active users. - Developed ValidationTest to verify input validation and sanitization for user IDs, nicknames, messages, and API requests. - Introduced Security and Validation utility classes with methods for secure token generation, input sanitization, and comprehensive validation rules.
206 lines
6.3 KiB
Makefile
206 lines
6.3 KiB
Makefile
# Dodgers IPTV - Development Makefile
|
|
|
|
.PHONY: help install test test-unit test-coverage lint clean setup db migrate
|
|
|
|
# Default target
|
|
help:
|
|
@echo "Dodgers IPTV Development Commands:"
|
|
@echo ""
|
|
@echo "Setup & Installation:"
|
|
@echo " make install - Install PHP dependencies via Composer"
|
|
@echo " make setup - Complete setup (install + migrate)"
|
|
@echo ""
|
|
@echo "Database:"
|
|
@echo " make db - Run database migrations"
|
|
@echo " make migrate - Alias for db"
|
|
@echo ""
|
|
@echo "Testing:"
|
|
@echo " make test - Run all tests"
|
|
@echo " make test-unit - Run unit tests only"
|
|
@echo " make test-coverage - Run tests with coverage report"
|
|
@echo ""
|
|
@echo "Code Quality:"
|
|
@echo " make lint - Run PHPStan static analysis"
|
|
@echo " make check - Run both tests and linting"
|
|
@echo ""
|
|
@echo "Maintenance:"
|
|
@echo " make clean - Clean up test artifacts and logs"
|
|
@echo " make docs - Generate API documentation (placeholder)"
|
|
@echo ""
|
|
@echo "Examples:"
|
|
@echo " make install && make test # Install deps and run tests"
|
|
@echo " make setup && make check # Full setup and quality check"
|
|
|
|
# Installation
|
|
install:
|
|
@echo "Installing PHP dependencies..."
|
|
composer install --no-interaction --optimize-autoloader
|
|
@echo "Installation complete!"
|
|
|
|
setup: install db
|
|
@echo "Setup complete!"
|
|
@echo "Run 'make test' to verify everything works"
|
|
|
|
# Database operations
|
|
db: migrate
|
|
|
|
migrate:
|
|
@echo "Running database migrations..."
|
|
@php -r "
|
|
require_once 'bootstrap.php';
|
|
require_once 'includes/Database.php';
|
|
|
|
try {
|
|
\$db = Database::getInstance();
|
|
\$sql = file_get_contents('migrations/001_create_tables.sql');
|
|
\$db->getConnection()->exec(\$sql);
|
|
echo 'Database migration completed successfully!';
|
|
} catch (Exception \$e) {
|
|
echo 'Migration failed: ' . \$e->getMessage();
|
|
exit(1);
|
|
}
|
|
"
|
|
|
|
# Testing
|
|
test:
|
|
@echo "Running PHPUnit tests..."
|
|
vendor/bin/phpunit --configuration=phpunit.xml
|
|
|
|
test-unit:
|
|
@echo "Running unit tests only..."
|
|
vendor/bin/phpunit --configuration=phpunit.xml --testsuite="Unit Tests"
|
|
|
|
test-integration:
|
|
@echo "Running integration tests only..."
|
|
vendor/bin/phpunit --configuration=phpunit.xml --testsuite="Integration Tests"
|
|
|
|
test-coverage:
|
|
@echo "Running tests with coverage..."
|
|
vendor/bin/phpunit --configuration=phpunit.xml --coverage-html=tests/coverage
|
|
@echo "Coverage report generated in tests/coverage/"
|
|
|
|
test-watch:
|
|
@echo "Watching for changes and running tests..."
|
|
@while true; do \
|
|
inotifywait -qre modify . --exclude="vendor/|\.git/|tests/coverage/"; \
|
|
make test-unit; \
|
|
done
|
|
|
|
# Code quality
|
|
lint:
|
|
@echo "Running PHPStan static analysis..."
|
|
vendor/bin/phpstan analyse --configuration=phpstan.neon --level=8 src/
|
|
|
|
phpstan-setup:
|
|
@echo "Setting up PHPStan configuration..."
|
|
@if [ ! -f phpstan.neon ]; then \
|
|
cat > phpstan.neon << EOF
|
|
parameters:
|
|
level: 8
|
|
paths:
|
|
- models
|
|
- controllers
|
|
- services
|
|
- utils
|
|
- includes
|
|
excludes_analyse:
|
|
- vendor/
|
|
- tests/
|
|
- assets/
|
|
- static/
|
|
- migrations/
|
|
ignoreErrors:
|
|
- '#Function config not found#' # For Config::get calls
|
|
EOF
|
|
fi
|
|
|
|
check: test lint
|
|
|
|
# Development helpers
|
|
docker-build:
|
|
@echo "Building Docker container..."
|
|
docker build -t dodgers-iptv .
|
|
|
|
docker-run:
|
|
@echo "Running Docker container..."
|
|
docker run -p 8000:80 -v $(PWD):/var/www/html dodgers-iptv
|
|
|
|
server-start:
|
|
@echo "Starting PHP development server..."
|
|
php -S localhost:8000 -t .
|
|
|
|
# Maintenance
|
|
clean:
|
|
@echo "Cleaning up artifacts..."
|
|
rm -rf tests/coverage/
|
|
rm -rf tests/results/
|
|
rm -rf logs/
|
|
rm -f phpunit.xml.bak
|
|
find . -name "*.log" -not -name ".git*" -delete
|
|
find . -name "*~" -delete
|
|
find . -name "*.tmp" -delete
|
|
|
|
deep-clean: clean
|
|
@echo "Deep cleaning (removes vendor and composer.lock)..."
|
|
rm -rf vendor/
|
|
rm -rf node_modules/
|
|
rm -f composer.lock
|
|
rm -f package-lock.json
|
|
|
|
# Documentation (placeholder for future API docs)
|
|
docs:
|
|
@echo "Generating API documentation..."
|
|
@echo "API Documentation generation not yet implemented."
|
|
@echo "Consider using OpenAPI/Swagger for API documentation."
|
|
|
|
# Security audit
|
|
audit:
|
|
@echo "Running security audit..."
|
|
vendor/bin/security-checker security:check composer.lock
|
|
@echo "Consider running 'composer audit' for official vulnerability scan"
|
|
|
|
# Performance profiling
|
|
profile:
|
|
@echo "Performance profiling..."
|
|
@echo "Install Blackfire or Xdebug for PHP profiling"
|
|
@echo "Example: php -d xdebug.profiler_enable=On index.php"
|
|
@echo "Then analyze cachegrind files with tools like QCacheGrind"
|
|
|
|
# Deployment preparation
|
|
build:
|
|
@echo "Building for production..."
|
|
@echo "Optimizing autoloader..."
|
|
composer install --no-dev --optimize-autoloader
|
|
@echo "Clearing caches..."
|
|
rm -rf tests/coverage/
|
|
@echo "Setting correct permissions..."
|
|
find . -type f -name "*.php" -exec chmod 644 {} \;
|
|
find . -type d -exec chmod 755 {} \;
|
|
@echo "Build complete. Ready for deployment!"
|
|
|
|
# Utility commands
|
|
status:
|
|
@echo "=== Project Status ==="
|
|
@echo "PHP Version: $$(php --version | head -1)"
|
|
@echo "Composer: $$(composer --version)"
|
|
@if [ -f vendor/autoload.php ]; then echo "✓ Dependencies installed"; else echo "✗ Dependencies missing"; fi
|
|
@echo "Environment: $$(php -r "echo getenv('APP_ENV') ?: 'not set';")"
|
|
@if [ -f logs/app.log ]; then echo "Log file size: $$(du -h logs/app.log | cut -f1)"; else echo "No log file"; fi
|
|
|
|
# PHPDoc generation
|
|
phpdoc:
|
|
@echo "Generating PHPDoc..."
|
|
vendor/bin/phpdoc run --directory=models,controllers,services,utils,includes --target=docs/phpdoc
|
|
|
|
# Version management
|
|
version:
|
|
@echo "Current version info:"
|
|
@php -r "
|
|
\$composer = json_decode(file_get_contents('composer.json'), true);
|
|
echo 'Package: ' . (\$composer['name'] ?? 'unknown') . PHP_EOL;
|
|
echo 'Version: ' . (\$composer['version'] ?? 'dev') . PHP_EOL;
|
|
echo 'PHP: ' . PHP_VERSION . PHP_EOL;
|
|
echo 'OS: ' . PHP_OS . PHP_EOL;
|
|
"
|
|
|
|
.PHONY: help install setup db migrate test test-unit test-coverage lint clean deep-clean docs audit profile build status phpdoc version docker-build docker-run server-start test-integration test-watch phpstan-setup check
|