phpro/grumphp-shim
Provides a bundled GrumPHP PHAR so you can run GrumPHP without installing all its dependencies. Install via Composer and run vendor/bin/grumphp.phar run. Links to the main phpro/grumphp repo for options and release notes.
composer require --dev phpro/grumphp-shim
.grumphp.yml config file in your project root. Use the GrumPHP docs for reference.
# Example minimal config
parameters:
tasks:
phpcs:
standard: PSR12
phpunit: ~
vendor/bin/grumphp.phar run
Or add it to your composer.json scripts for easier access:
"scripts": {
"grumphp": "vendor/bin/grumphp.phar run"
}
Then execute with:
composer grumphp
To enforce checks before commits, add a Git hook or use a Composer script:
# Add to your .git/hooks/pre-commit (or use a tool like husky)
#!/bin/sh
composer grumphp
Now, GrumPHP will run automatically on git commit.
Laravel-Specific Tasks
Leverage Laravel’s ecosystem by configuring GrumPHP tasks in .grumphp.yml:
tasks:
laravel-pint: ~
pest: ~
phpstan:
level: 5
configuration: phpstan.neon
This ensures code formatting, testing, and static analysis align with Laravel’s standards.
CI/CD Pipeline Use the shim in CI to fail fast on quality issues:
# GitHub Actions example
jobs:
grumphp:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-php@v3
with:
php-version: '8.2'
- run: composer install --dev
- run: vendor/bin/grumphp.phar run
Custom Tasks Extend GrumPHP with custom tasks (e.g., security checks):
tasks:
custom:
command: ./vendor/bin/security-checker security:check
ignore_failure: false
Cache Results Speed up local runs by caching results:
vendor/bin/grumphp.phar run --cache
Add this to your composer.json scripts for convenience:
"scripts": {
"grumphp": "vendor/bin/grumphp.phar run --cache"
}
Parallel Execution Run tasks in parallel to reduce execution time:
parameters:
parallel:
enabled: true
tasks:
- phpcs
- phpunit
Environment-Specific Configs
Use multiple config files for different environments (e.g., grumphp.ci.yml):
vendor/bin/grumphp.phar run --config=grumphp.ci.yml
Pest Integration Configure Pest tasks in GrumPHP to run alongside PHPUnit:
tasks:
pest: ~
phpunit: ~
Ensure your pest.php config is compatible with GrumPHP’s execution environment.
Artisan Commands Use GrumPHP to validate Artisan commands or migrations:
tasks:
custom:
command: php artisan migrate:status
ignore_failure: false
PHAR Execution Issues
vendor/bin/grumphp.phar fails with "PHAR error" or permission issues.chmod +x vendor/bin/grumphp.phar
--verbose to diagnose:
vendor/bin/grumphp.phar run --verbose
Dependency Conflicts
phpunit) fail due to version mismatches with Laravel’s dependencies..grumphp.yml:
tasks:
phpunit:
config_file: phpunit.xml
group: []
test_class: []
bootstrap: tests/bootstrap.php
configuration: []
colors: true
process_isolation: false
stop_on_failure: false
test_suffix: Test
test_loader_class: PHPUnit\TextUI\TestRunner
test_loader_options: []
group_by_test_class: false
Git Hook Conflicts
.env).#!/bin/sh
cp .env.testing .env
composer grumphp
Performance Overhead
--cache).phpstan) from pre-commit hooks.Verbose Output
Use --verbose to diagnose issues:
vendor/bin/grumphp.phar run --verbose
Dry Runs Test configurations without executing tasks:
vendor/bin/grumphp.phar run --dry-run
Task-Specific Debugging Run individual tasks to isolate failures:
vendor/bin/grumphp.phar phpcs
vendor/bin/grumphp.phar phpunit
Path Handling
.grumphp.yml are relative. Use absolute paths or ~ for project root:
tasks:
phpcs:
standard: PSR12
paths:
- ~
PHP Version Mismatches
php -v # Check your project's PHP version
Task Ordering
.grumphp.yml. Reorder for dependencies (e.g., phpcs before phpstan).Custom Tasks Extend GrumPHP with custom tasks. Example:
tasks:
custom:
command: ./vendor/bin/your-custom-script.sh
ignore_failure: false
Pre/Post Hooks Use GrumPHP’s hooks to run scripts before/after tasks:
parameters:
hooks:
before:
- ./scripts/pre-check.sh
after:
- ./scripts/post-check.sh
Dynamic Configs Load configs dynamically based on environment variables:
parameters:
config:
- .grumphp.yml
- .grumphp.${ENV}.yml
Environment Variables
GrumPHP may not load .env automatically. Use a wrapper script or set variables explicitly:
#!/bin/sh
export APP_ENV=testing
composer grumphp
Artisan Commands
Avoid running Artisan commands directly in GrumPHP if they rely on Laravel’s service provider bootstrapping. Use php artisan with a full Laravel bootstrap:
tasks:
custom:
command: php artisan your:command
ignore_failure: false
How can I help you explore Laravel packages today?