sanmai/phpunit-double-colon-syntax
Run individual PHPUnit test methods using the familiar file::method syntax: vendor/bin/phpunit tests/FooTest.php::testBar. Supports multiple methods, no config, works with PHPUnit 6+. Translates to --filter under the hood (not compatible with --filter).
Install the package via Composer in your Laravel project's root directory:
composer require --dev sanmai/phpunit-double-colon-syntax
First use case: Run a single test method using pytest-style syntax:
vendor/bin/phpunit tests/Feature/UserTest.php::testLogin
This replaces the native PHPUnit --filter syntax while maintaining identical functionality.
Where to look first:
php artisan test) remain unaffected—this only modifies vendor/bin/phpunit commands.Replace --filter with :: syntax:
# Before (native PHPUnit)
vendor/bin/phpunit --filter testLogin tests/Feature/UserTest.php
# After (with package)
vendor/bin/phpunit tests/Feature/UserTest.php::testLogin
Run multiple tests:
vendor/bin/phpunit tests/Feature/UserTest.php::testLogin tests/Feature/UserTest.php::testLogout
Combine with other flags (except --filter):
vendor/bin/phpunit --coverage tests/Feature/UserTest.php::testLogin
Test Suite Organization: Leverage Laravel’s test structure (e.g., tests/Feature/, tests/Unit/) directly in commands:
vendor/bin/phpunit tests/Feature/Auth/LoginTest.php::testGuestLogin
CI/CD Integration: Use the syntax in GitHub Actions, GitLab CI, or Laravel Forge pipelines:
# .github/workflows/tests.yml
- run: vendor/bin/phpunit tests/Unit/UserTest.php::testCreate
Package Development: Standardize test commands across published packages:
vendor/bin/phpunit tests/Integration/PaymentTest.php::testWebhook
file::method syntax as valid PHPUnit commands.alias run-test='vendor/bin/phpunit'
run-test tests/Feature/UserTest.php::testProfileUpdate
CONTRIBUTING.md to reduce ramp-up time for new contributors.Exclusive Syntax: The package does not support mixing file::method and --filter in the same command. Choose one syntax per invocation.
vendor/bin/phpunit --filter testLogin tests/UserTest.php::testCreatevendor/bin/phpunit tests/UserTest.php::testCreateGlobal Scope: Only affects vendor/bin/phpunit commands. Other PHPUnit executables (e.g., global phpunit) remain unchanged.
Static Analysis Tools: Tools like PHPStan or Psalm may flag file::method as invalid syntax. Configure them to ignore these patterns or use runtime checks.
Legacy PHPUnit: While the package supports PHPUnit 6+, Laravel’s minimum PHP 8.0+ ensures compatibility with modern versions.
Command Not Working?:
dev dependencies (composer.json).vendor/bin/phpunit, not a globally installed version.Error: "Test file not found":
vendor/bin/phpunit /full/path/to/tests/UserTest.php::testLogin
vendor/bin/phpunit and transforms arguments at runtime. No phpunit.xml or environment variables are required.phpunit binary (e.g., ./vendor/bin/phpunit-custom), the package won’t intercept it. Stick to vendor/bin/phpunit.namespace::class::method) if needed.file::method syntax in test commands before commits:
grep -E 'phpunit.*::' your-script.sh && echo "Use file::method syntax" && exit 1
*Test.php) to avoid path-related issues.php artisan test. Use vendor/bin/phpunit for file::method syntax.test('description'))—this package won’t interfere but won’t be needed.How can I help you explore Laravel packages today?