Package Verification
The test-isolated.sh script includes automatic package verification to ensure that only the correct framework packages are installed for each test variant.
Introduction
Section titled “Introduction”Package verification prevents version conflicts and ensures test isolation by automatically checking that:
- Plain PHP - No framework packages are installed
- Laravel Tests - Only Laravel packages of the correct version
- Symfony Tests - Only Symfony packages of the correct version
- Doctrine Tests - Only Doctrine packages of the correct version
How It Works
Section titled “How It Works”After installing dependencies, the script automatically verifies installed packages before running tests.
Verification Process
Section titled “Verification Process”- Gets list of installed packages using
composer show --format=json - Checks for forbidden packages based on test type
- For framework tests, verifies that installed framework packages match the expected version
- Exits with error code 1 if any forbidden packages are found
- Prints detailed error messages showing which packages are problematic
Verification Rules
Section titled “Verification Rules”Plain PHP (--plain)
Section titled “Plain PHP (--plain)”Forbidden packages:
- All
illuminate/*packages symfony/validator,symfony/http-kernel,symfony/http-foundationdoctrine/orm,doctrine/dbal
Example:
./scripts/test-isolated.sh --plain --php 8.4Laravel Tests (--laravel VERSION)
Section titled “Laravel Tests (--laravel VERSION)”Allowed packages:
illuminate/support,illuminate/validation,illuminate/database(matching version)- Other
illuminate/*packages as dependencies (matching version)
Forbidden packages:
illuminate/*packages with wrong versionsymfony/validator,symfony/http-kernel,symfony/http-foundationdoctrine/orm,doctrine/dbal
Note: Some Symfony components (like symfony/console, symfony/process) are allowed as they are dependencies of Laravel.
Examples:
./scripts/test-isolated.sh --laravel 10 --php 8.3./scripts/test-isolated.sh --laravel 11 --php 8.4Symfony Tests (--symfony VERSION)
Section titled “Symfony Tests (--symfony VERSION)”Allowed packages:
symfony/validator,symfony/http-kernel,symfony/http-foundation(matching version)- Other
symfony/*packages as dependencies (matching version)
Forbidden packages:
- Symfony framework packages with wrong version
- All
illuminate/*packages doctrine/orm,doctrine/dbal
Example:
./scripts/test-isolated.sh --symfony 7 --php 8.4Doctrine Tests (--doctrine VERSION)
Section titled “Doctrine Tests (--doctrine VERSION)”Allowed packages:
doctrine/orm,doctrine/dbal(matching version)- Other
doctrine/*packages as dependencies (matching version)
Forbidden packages:
- Doctrine packages with wrong version
- All
illuminate/*packages symfony/validator,symfony/http-kernel,symfony/http-foundation
Note: Some Symfony components are allowed as they are dependencies of Doctrine.
Example:
./scripts/test-isolated.sh --doctrine 3 --php 8.4Example Output
Section titled “Example Output”Successful Verification
Section titled “Successful Verification”→ Verifying installed packages...✓ Package verification passedFailed Verification
Section titled “Failed Verification”→ Verifying installed packages...✗ Found forbidden Laravel packages in Symfony setup: ✗ illuminate/support ✗ illuminate/validation
✗ Package verification failed!Testing Package Verification
Section titled “Testing Package Verification”Automatic Verification
Section titled “Automatic Verification”Package verification runs automatically during:
# Matrix teststask test:matrix
# Individual framework teststask test:laravel11task test:symfony7task test:doctrine3Manual Verification
Section titled “Manual Verification”To manually verify packages without running tests:
# Run with --no-tests to skip test execution./scripts/test-isolated.sh --laravel 10 --php 8.2 --no-tests
# Check the output for "Package verification passed"Test All Variants
Section titled “Test All Variants”# Test all four variants (Plain PHP, Laravel, Symfony, Doctrine)./scripts/test-package-verification.shBenefits
Section titled “Benefits”Prevents Version Conflicts
Section titled “Prevents Version Conflicts”Ensures only one framework version is installed at a time, preventing dependency conflicts.
Example:
# ❌ Without verification: Laravel 11 + Symfony 7 installed together# ✅ With verification: Only Laravel 11 installedTest Isolation
Section titled “Test Isolation”Guarantees that tests run in the correct environment, mimicking real-world usage.
Example:
# ❌ Without verification: Tests might pass due to other frameworks# ✅ With verification: Tests only pass if they work with the target frameworkEarly Detection
Section titled “Early Detection”Catches dependency issues before running tests, saving time and providing clear feedback.
Example:
# ❌ Without verification: Tests fail with cryptic errors# ✅ With verification: Clear error message about forbidden packagesClear Error Messages
Section titled “Clear Error Messages”Shows exactly which packages are problematic, making it easy to fix issues.
Example:
✗ Found forbidden Laravel packages in Symfony setup: ✗ illuminate/support v11.0.0 ✗ illuminate/validation v11.0.0Implementation Details
Section titled “Implementation Details”Verification Function
Section titled “Verification Function”The verify_installed_packages function in scripts/test-isolated.sh:
verify_installed_packages() { local test_type=$1 local version=$2
# Get installed packages local packages=$(composer show --format=json)
# Check for forbidden packages case $test_type in plain) check_no_frameworks ;; laravel) check_only_laravel "$version" ;; symfony) check_only_symfony "$version" ;; doctrine) check_only_doctrine "$version" ;; esac}Package Detection
Section titled “Package Detection”# Check if package is installedif echo "$packages" | jq -e '.installed[] | select(.name == "illuminate/support")' > /dev/null; then echo "✗ illuminate/support found" exit 1fi
# Check package versionlocal version=$(echo "$packages" | jq -r '.installed[] | select(.name == "illuminate/support") | .version')if [[ ! "$version" =~ ^$expected_version ]]; then echo "✗ Wrong version: $version (expected: $expected_version)" exit 1fiTroubleshooting
Section titled “Troubleshooting”Verification Fails
Section titled “Verification Fails”If package verification fails:
- Check the error message - It shows which packages are problematic
- Clean composer cache:
Terminal window task dev:clean - Rebuild environment:
Terminal window task dev:reset
Wrong Packages Installed
Section titled “Wrong Packages Installed”If wrong packages are installed:
- Remove vendor and lock file:
Terminal window rm -rf vendor composer.lock - Reinstall dependencies:
Terminal window task install
Verification Too Strict
Section titled “Verification Too Strict”If verification is too strict for your use case:
- Check if the package is a dependency - Some Symfony components are allowed as Laravel dependencies
- Update verification rules - Edit
scripts/test-isolated.shif needed - Report an issue - If you think the rules are incorrect
Summary
Section titled “Summary”Package verification provides:
- ✅ Prevents version conflicts - Only one framework at a time
- ✅ Test isolation - Guarantees correct environment
- ✅ Early detection - Catches issues before tests
- ✅ Clear error messages - Shows exactly what’s wrong
- ✅ Automatic - Runs during all matrix tests
Next Steps
Section titled “Next Steps”- Test Matrix - Learn about the test matrix
- Development Setup - Setup your environment
- Testing Guide - Learn about testing DTOs