pamil/phpspec-skip-example-extension
PhpSpec extension to skip examples via annotations. Add @require ClassOrInterface to a spec to skip all its examples when that dependency isn’t available—useful for optional integrations and version-dependent code. Compatible with PhpSpec 4 and 5.
Installation Add the package via Composer:
composer require --dev pamil/phpspec-skip-example-extension
Register the extension in your phpspec.yml:
extensions:
PhpSpecSkipExampleExtension: ~
First Use Case
Annotate a spec method with @skip to exclude it from execution:
use PhpSpecSkipExampleExtension\Annotation\Skip;
class MySpec extends ObjectBehavior
{
/**
* @skip
*/
public function it_should_be_skipped()
{
// This spec will not run
}
}
Where to Look First
src/Annotation/Skip.php for annotation syntax.phpspec.yml for extension settings.phpspec run to see skipped specs marked in output.Conditional Skipping Use annotations for temporary exclusions (e.g., flaky tests, WIP features):
/**
* @skip("Database connection issues")
*/
public function it_queries_the_database()
{
// ...
}
Group Skipping
Skip entire spec classes with @skip on the class docblock:
/**
* @skip("Deprecated API")
*/
class DeprecatedSpec extends ObjectBehavior
{
// All methods skipped
}
CI/CD Integration
Combine with --filter to run only non-skipped specs:
phpspec run --filter="~@skip"
@skip("Needs refactor")).phpspec.yml or a dedicated file (e.g., SKIPPED_SPEC.md).phpspec run --format=pretty | grep -E "@skip"
Annotation Parsing
@skip("reason with spaces").phpspec run -v) to check parsing.Caching
phpspec clear-cache) or run with --no-cache.IDE Support
@skip as a valid annotation.
Fix: Add @mixin or @method annotations for IDE compatibility:
/**
* @skip
* @mixin
*/
phpspec.yml and not overridden.phpspec run -d) to inspect extension behavior.phpspec run --spec=path/to/SpecWithSkip
Custom Annotations
Extend the package by creating a subclass of Skip (e.g., @wip, @todo) and register it in phpspec.yml:
extensions:
App\CustomSkipExtension: ~
Dynamic Skipping Override the extension’s logic to skip specs programmatically (e.g., based on environment variables):
// In a custom extension class
public function skipExample(Example $example)
{
if (getenv('SKIP_DB_TESTS')) {
return true;
}
return parent::skipExample($example);
}
Integration with Other Tools
phpunit-polyfills to bridge skipped specs between PhpSpec and PHPUnit.skip: true).How can I help you explore Laravel packages today?