Overview
The project uses:- PHPUnit - Unit and integration testing for PHP code
- Playwright - End-to-end browser testing
- PHPStan - Static analysis for PHP code
- PHPCS - Code style checking and fixing
docker-compose.tools.yml.
Running All Quality Checks
To run all code quality tools at once:- Hadolint - Dockerfile linting
- PHPCBF - PHP Code Beautifier and Fixer (auto-fixes style issues)
- PHPCS - PHP_CodeSniffer (checks for style issues)
- PHPStan - Static analysis
PHPUnit
Running PHPUnit Tests
To run all PHPUnit tests:PHPUnit Configuration
The PHPUnit container:- Uses the
phpunitbuild target fromdocker/app/Dockerfile - Mounts the
app/directory as a volume - Copies Composer dependencies to
/var/www/tools/phpunit/ - Runs the
phpunitcommand
PHPUnit test files and configuration are defined in the application code. The exact test structure depends on your project setup.
Playwright
Playwright runs end-to-end tests in real browsers to verify application functionality.Installing Playwright
Before running tests for the first time, install Playwright dependencies:- Creates an empty
playwright/.envfile if it doesn’t exist - Runs
npm cito install Node.js dependencies - Automatically detects if Node.js is available locally or uses Docker
Running Playwright Tests
To run the Playwright test suite:https://cfbmarblegame.test by default.
Requirements:
- Your local development environment must be running (
docker compose up) - The application must be accessible at the configured URL
Viewing Test Reports
To view the HTML test report:- Test results and status
- Screenshots and videos of failures
- Detailed trace information
- Performance metrics
Playwright Configuration
The test configuration is defined inplaywright/playwright.config.ts:
Example Test
Here’s a basic test fromplaywright/tests/basic.spec.ts:
- Page titles and content visibility
- HTTP status codes (404, 405, 200)
- Route parameters and query strings
- JSON response bodies
Writing New Tests
Create test files inplaywright/tests/ with the .spec.ts extension:
PHPStan
PHPStan performs static analysis to catch bugs without running the code.Running PHPStan
- Analyze all PHP files according to your configuration
- Report type errors, undefined variables, and other issues
- Return a non-zero exit code if errors are found
PHPStan Configuration
The PHPStan container:- Uses the official
ghcr.io/phpstan/phpstan:2.0.4-php8.4image - Mounts the
app/directory to/app - Copies the PHPStan binary to
/app/tools/phpstan/ - Runs analysis based on
phpstan.neonorphpstan.neon.dist
PHPCS and PHPCBF
PHP_CodeSniffer (PHPCS) checks code style, while PHP Code Beautifier and Fixer (PHPCBF) automatically fixes style issues.Automatically Fix Style Issues
- Scan your PHP files for style violations
- Automatically fix issues it can (indentation, spacing, etc.)
- Report any issues that require manual fixing
Check for Style Issues
- Check code against the configured coding standard
- Report violations without modifying files
- Return a non-zero exit code if violations are found
Workflow Recommendation
Hadolint
Hadolint lints Dockerfiles to ensure best practices.Running Hadolint
- Best practices for Dockerfile instructions
- Security issues
- Common mistakes
- Optimization opportunities
Continuous Integration
All these tools should be run in your CI/CD pipeline to ensure code quality:Test Environment Variables
Playwright
Createplaywright/.env from playwright/.env.example to configure:
PW_BASE_URL- Base URL for tests (default:http://localhost:9000)- Other Playwright-specific settings
Application
Ensure yourapp/.env is configured for testing:
Troubleshooting
Playwright tests fail to connect
- Ensure the development server is running:
docker compose ps - Verify the URL is accessible:
curl https://cfbmarblegame.test - Check the
PW_BASE_URLenvironment variable
PHPUnit tests can’t find classes
- Ensure Composer dependencies are installed
- Verify the autoloader is configured correctly
- Check that the
app/directory is mounted properly
PHPCS/PHPCBF changes aren’t persisted
- Ensure you have write permissions on the
app/directory - Check that the volume mount is working:
docker compose ps - Verify the files aren’t read-only
PHPStan reports memory errors
- Increase Docker memory allocation
- Reduce the scope of analysis in
phpstan.neon - Use PHPStan’s
--memory-limitflag if needed