Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Phpunit Double Colon Syntax Laravel Package

sanmai/phpunit-double-colon-syntax

PHPUnit extension that adds support for “double colon” syntax in tests, improving readability when referencing classes and methods. Lightweight and focused, it helps you write clearer PHPUnit test code with a familiar static-style notation.

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer:

composer require --dev sanmai/phpunit-double-colon-syntax

No configuration is required—just require the autoloader ( Composer handles this automatically). Begin by replacing string-based method references (e.g., 'TestClass::testMethod') with the native ::class . '::method' pattern or using the provided DoubleColon::from() helper if available. The package’s main entrypoint is typically a trait like DoubleColonSyntax that can be imported into your test cases or helper classes to enable the syntax in assertions or data providers.

Implementation Patterns

  • Explicit test filtering: Use Class::class . '::methodName' in @depends, @group, or custom annotations to avoid brittle string concatenation and enable refactoring safety (IDE support, rename-safe).
  • Data provider clarity: In data providers, return ClassName::method-style callables using the package’s helper (e.g., DoubleColon::from(Foo::class, 'bar')) to make test cases self-documenting and editable.
  • Custom test runners or test suites: Integrate with TestResult or custom extensions to parse ::class . '::method' references for dynamic test discovery or reporting.
  • Legacy compatibility: Gradually migrate from raw strings (e.g., 'MyTest::testUserLogin') to typed double-colon references—especially useful when upgrading large suites where test method renaming is common.

Gotchas and Tips

  • Autoloading matters: Ensure your ClassLoader correctly resolves all referenced classes; the package doesn’t handle missing classes—PHPSpec will fail if a class/method doesn’t exist at reference time.
  • No built-in helper method (per docs): If the README doesn’t mention a specific function (e.g., DoubleColon::from()), you may need to implement your own small helper or use ReflectionClass::getMethod() to verify references exist before runtime.
  • IDE autocomplete won’t infer dynamically: Even with explicit syntax, static analysis tools may not resolve Class::class . '::method' as a test method—add PHPDoc hints (@test, @depends) for tooling support.
  • Test dependencies via @depends still string-based: PHPUnit itself doesn’t natively interpret double-colon callables—use the package to generate dependency strings (e.g., $this->doubleColonString(Foo::class, 'bar')) in test factories.
  • Extension point: The package likely exposes a small utility trait—override or extend it with custom validation (e.g., assert method is public, or belongs to the same namespace) in your base TestCase.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation
uri-template/tests