-
Notifications
You must be signed in to change notification settings - Fork 3
Consolidate documentation and optimize CI with Composer caching #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d7848b9
Initial plan
Copilot d1dc89f
Consolidate documentation and optimize GitHub Actions with Composer c…
Copilot 7c2554a
Improve documentation clarity and composite action parameter descript…
Copilot 66af3e5
Fix documentation clarity and relative links per review feedback
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,235 @@ | ||
| # Running Tests in InvoicePlane v2 | ||
|
|
||
| This guide covers how to run tests in InvoicePlane v2, including full test suites, smoke tests, and specific test groups. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| ```bash | ||
| composer install | ||
| cp .env.testing.example .env.testing | ||
| php artisan key:generate --env=testing | ||
| ``` | ||
|
|
||
| ## Quick Reference | ||
|
|
||
| ### Run All Tests | ||
| ```bash | ||
| # Using Laravel Artisan (recommended) | ||
| php artisan test | ||
|
|
||
| # Using PHPUnit directly | ||
| ./vendor/bin/phpunit | ||
| ``` | ||
|
|
||
| ### Run Test Suites | ||
| ```bash | ||
| # Run only Unit tests | ||
| php artisan test --testsuite=Unit | ||
|
|
||
| # Run only Feature tests | ||
| php artisan test --testsuite=Feature | ||
| ``` | ||
|
|
||
| ### Run Smoke Tests | ||
| Smoke tests are fast, critical tests that verify core functionality. They use the `#[Group('smoke')]` attribute. | ||
|
|
||
| ```bash | ||
| # Using PHPUnit with smoke configuration | ||
| php artisan test --configuration=phpunit.smoke.xml | ||
|
|
||
| # Using --group flag | ||
| php artisan test --group=smoke | ||
|
|
||
| # Run smoke tests for a specific module | ||
| ./vendor/bin/phpunit Modules/Clients/Tests/Feature/ --group=smoke | ||
| ``` | ||
|
|
||
| ### Run Tests with Coverage | ||
| ```bash | ||
| # Generate coverage report | ||
| php artisan test --coverage | ||
|
|
||
| # Generate HTML coverage report | ||
| php artisan test --coverage-html coverage/ | ||
|
|
||
| # View coverage in browser | ||
| open coverage/index.html # macOS | ||
| xdg-open coverage/index.html # Linux | ||
| ``` | ||
|
|
||
| ## Test Groups | ||
|
|
||
| InvoicePlane v2 uses PHPUnit groups to organize tests: | ||
|
|
||
| - `smoke` - Fast, critical tests (runs in ~10-30 seconds) | ||
| - `crud` - Create, Read, Update, Delete operation tests | ||
| - `peppol` - Peppol e-invoicing integration tests | ||
| - `integration` - Integration tests with external services | ||
|
|
||
| ### Run Specific Groups | ||
| ```bash | ||
| # Smoke tests only | ||
| php artisan test --group=smoke | ||
|
|
||
| # CRUD tests only | ||
| php artisan test --group=crud | ||
|
|
||
| # Peppol tests only | ||
| php artisan test --group=peppol | ||
|
|
||
| # Multiple groups | ||
| php artisan test --group=smoke,crud | ||
| ``` | ||
|
|
||
| ## Module-Specific Tests | ||
|
|
||
| ### Run Tests for a Specific Module | ||
| ```bash | ||
| # All tests for a module | ||
| ./vendor/bin/phpunit Modules/Clients/Tests/ | ||
|
|
||
| # Only Feature tests for a module | ||
| ./vendor/bin/phpunit Modules/Clients/Tests/Feature/ | ||
|
|
||
| # Only Unit tests for a module | ||
| ./vendor/bin/phpunit Modules/Clients/Tests/Unit/ | ||
| ``` | ||
|
|
||
| ### Examples | ||
| ```bash | ||
| # Clients module | ||
| ./vendor/bin/phpunit Modules/Clients/Tests/ | ||
|
|
||
| # Invoices module | ||
| ./vendor/bin/phpunit Modules/Invoices/Tests/ | ||
|
|
||
| # Peppol-specific tests | ||
| ./vendor/bin/phpunit Modules/Invoices/Tests/Unit/Peppol/ | ||
| ``` | ||
|
|
||
| ## Individual Test Files | ||
|
|
||
| ```bash | ||
| # Run a specific test file | ||
| ./vendor/bin/phpunit Modules/Clients/Tests/Feature/ContactsTest.php | ||
|
|
||
| # Run a specific test method | ||
| ./vendor/bin/phpunit --filter it_lists_contacts Modules/Clients/Tests/Feature/ContactsTest.php | ||
| ``` | ||
|
|
||
| ## Debugging Tests | ||
|
|
||
| ### Stop on First Failure | ||
| ```bash | ||
| php artisan test --stop-on-failure | ||
| ``` | ||
|
|
||
| ### Verbose Output | ||
| ```bash | ||
| php artisan test --verbose | ||
| ``` | ||
|
|
||
| ### Run with Debug Mode | ||
| ```bash | ||
| ./vendor/bin/phpunit --debug | ||
| ``` | ||
|
|
||
| ### Run Specific Test Method | ||
| ```bash | ||
| # Using --filter | ||
| php artisan test --filter it_creates_invoice | ||
|
|
||
| # Pattern matching | ||
| php artisan test --filter ".*creates.*" | ||
| ``` | ||
|
|
||
| ## Parallel Testing | ||
|
|
||
| For faster test execution, ParaTest can be used (if installed in the project): | ||
|
|
||
| ```bash | ||
| # Run tests in parallel (if ParaTest is available) | ||
| ./vendor/bin/paratest | ||
|
|
||
| # Run with specific number of processes | ||
| ./vendor/bin/paratest --processes=4 | ||
| ``` | ||
|
|
||
| **Note:** ParaTest should be added to `composer.json` as a dev dependency if parallel testing is needed: | ||
|
|
||
| ```bash | ||
| composer require --dev brianium/paratest | ||
| ``` | ||
|
|
||
| ## Configuration Files | ||
|
|
||
| InvoicePlane v2 uses two PHPUnit configuration files: | ||
|
|
||
| - `phpunit.xml` - Default configuration for all tests | ||
| - `phpunit.smoke.xml` - Configuration for smoke tests only | ||
|
|
||
| ### phpunit.xml | ||
| - Runs all Unit and Feature test suites | ||
| - Uses SQLite in-memory database | ||
| - Includes all test directories | ||
|
|
||
| ### phpunit.smoke.xml | ||
| - Filters tests by `#[Group('smoke')]` attribute | ||
| - Faster execution (~10-30 seconds) | ||
| - Ideal for CI/CD pipelines and post-deployment checks | ||
|
|
||
| ## Continuous Integration | ||
|
|
||
| ### GitHub Actions Workflows | ||
|
|
||
| Smoke tests run automatically after Composer dependency updates: | ||
|
|
||
| ```bash | ||
| # See .github/workflows/composer-update.yml | ||
| ``` | ||
|
|
||
| Full test suite runs manually: | ||
|
|
||
| ```bash | ||
| # See .github/workflows/phpunit.yml | ||
| ``` | ||
|
|
||
| ## Best Practices | ||
|
|
||
| 1. **Run smoke tests frequently** - They catch critical issues quickly | ||
| 2. **Use `--stop-on-failure`** - When debugging to save time | ||
| 3. **Run full suite before committing** - Ensure no regressions | ||
| 4. **Use coverage reports** - To identify untested code | ||
| 5. **Group tests logically** - Use `#[Group()]` for better organization | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Tests Failing Due to Database Issues | ||
| ```bash | ||
| # Ensure .env.testing is configured | ||
| cp .env.testing.example .env.testing | ||
| php artisan key:generate --env=testing | ||
|
|
||
| # Check database connection | ||
| php artisan test --env=testing | ||
| ``` | ||
|
|
||
| ### Memory Limit Issues | ||
| ```bash | ||
| # Increase PHP memory limit | ||
| php -d memory_limit=512M artisan test | ||
| ``` | ||
|
|
||
| ### Cache Issues | ||
| ```bash | ||
| # Clear all caches | ||
| php artisan cache:clear | ||
| php artisan config:clear | ||
| php artisan view:clear | ||
| ``` | ||
|
|
||
| ## See Also | ||
|
|
||
| - [CONTRIBUTING.md](CONTRIBUTING.md) - Guidelines for contributing tests | ||
| - [TEST_GENERATION_SUMMARY.md](TEST_GENERATION_SUMMARY.md) - Test generation documentation | ||
| - [PEPPOL_TESTS_SUMMARY.md](PEPPOL_TESTS_SUMMARY.md) - Peppol-specific test documentation |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| name: 'Setup PHP with Composer Caching' | ||
| description: 'Set up PHP environment and install Composer dependencies with intelligent caching' | ||
| inputs: | ||
| php-version: | ||
| description: 'PHP version to use' | ||
| required: false | ||
| default: '8.2' | ||
| php-extensions: | ||
| description: 'PHP extensions to install (comma-separated)' | ||
| required: false | ||
| default: 'mbstring, xml, ctype, json, fileinfo, pdo, sqlite, mysql, bcmath' | ||
| composer-flags: | ||
| description: 'Flags appended to the composer install command (e.g., --no-dev --optimize-autoloader). Used only when composer-args is empty.' | ||
| required: false | ||
| default: '--no-interaction --prefer-dist --optimize-autoloader' | ||
| composer-args: | ||
| description: 'Complete argument list passed directly to composer install. When non-empty, this overrides composer-flags and is used as-is.' | ||
| required: false | ||
| default: '' | ||
| working-directory: | ||
| description: 'Working directory for composer commands' | ||
| required: false | ||
| default: '.' | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: Set up PHP | ||
| uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: ${{ inputs.php-version }} | ||
| extensions: ${{ inputs.php-extensions }} | ||
| coverage: none | ||
|
|
||
| - name: Get Composer Cache Directory | ||
| id: composer-cache | ||
| shell: bash | ||
| working-directory: ${{ inputs.working-directory }} | ||
| run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Cache Composer dependencies | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ${{ steps.composer-cache.outputs.dir }} | ||
| key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-composer- | ||
|
|
||
| - name: Install Composer dependencies | ||
| shell: bash | ||
| working-directory: ${{ inputs.working-directory }} | ||
| run: | | ||
| if [ -n "${{ inputs.composer-args }}" ]; then | ||
| composer install ${{ inputs.composer-args }} | ||
| else | ||
| composer install ${{ inputs.composer-flags }} | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation states that the composite action is "Used by" these workflows, but
release.ymlis not listed and it doesn't actually use the composite action - it only adds caching directly. Eitherrelease.ymlshould be updated to use the composite action, or this list is accurate and doesn't need changing. However, the PR description mentions "Added caching to release.yml" which confirms it doesn't use the composite action.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feedback was already addressed in commit 66af3e5. The note has been added on line 34 explaining that
release.ymluses manual Composer caching instead of the composite action due to its custom production build flags (--no-dev).