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

Gherkin Laravel Package

behat/gherkin

behat/gherkin is a PHP library for parsing the Gherkin language used in BDD. Read and tokenize feature files, build an AST, and integrate with Behat or other test runners to execute human-readable scenarios in your test suite.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • BDD/Testing Framework Integration: The package is a core dependency for Behat, a PHP BDD framework, and is designed to parse Gherkin syntax (.feature files). It fits seamlessly into test automation pipelines, specification-driven development, or documentation-as-code workflows.
  • Language Agnostic: Supports 40+ languages (via i18n.php), making it ideal for multilingual projects or localized test suites.
  • AST Generation: Produces a structured AST (Abstract Syntax Tree) from Gherkin files, enabling programmatic analysis (e.g., validation, transformation, or integration with other tools like Cucumber).
  • Compatibility Modes: Offers legacy and gherkin-32 modes for alignment with Cucumber’s parser, reducing friction in cross-tool ecosystems.

Integration Feasibility

  • Laravel Compatibility: Works natively in PHP 7.2+ (Laravel 5.8+), with PHP 8.5 support. No Laravel-specific dependencies, but can integrate via:
    • Service Provider: Register the parser as a Laravel binding (e.g., GherkinParser) for dependency injection.
    • Artisan Commands: Parse .feature files during migrations, deployments, or CI pipelines.
    • Testing Libraries: Use alongside PestPHP, PHPUnit, or Behat for hybrid test scenarios.
  • File Parsing: Can process .feature files, strings, or streams, enabling:
    • Dynamic test generation (e.g., from API specs).
    • Real-time validation (e.g., during PR reviews via GitHub Actions).
  • AST Manipulation: The generated FeatureNode objects can be traversed/modified, enabling:
    • Custom preprocessors (e.g., inject metadata, transform steps).
    • Integration with ORMs (e.g., generate database tests from Gherkin).

Technical Risk

Risk Area Mitigation Strategy
Parser Quirks Use legacy mode for stability; gherkin-32 for Cucumber parity (but test thoroughly).
Deprecations Avoid extending Lexer, Parser, or Node classes (use ParserInterface instead).
Tag Filtering Deprecated syntax (e.g., @wip&&~slow) may break; enforce @-prefixed tags in CI.
Performance Cache parsed ASTs (Laravel’s file cache or Redis) to avoid reprocessing.
Language Support Validate unsupported languages early (e.g., via NoSuchLanguageException).
PHP Version Laravel 10+ (PHP 8.1+) is fully supported; drop PHP 7.2 if using newer Laravel.

Key Questions for the TPM

  1. Use Case Clarity:
    • Is this for Behat integration, standalone Gherkin parsing, or hybrid testing?
    • Will parsed ASTs be consumed programmatically (e.g., generate tests) or just validated?
  2. Compatibility Needs:
    • Should we enforce gherkin-32 mode for Cucumber alignment, or stick with legacy for stability?
    • Are multilingual feature files required, or is English-only sufficient?
  3. Performance Requirements:
    • Will parsing happen once (e.g., during build) or per-request (e.g., dynamic tests)?
    • Should we cache parsed ASTs (and if so, where: filesystem, Redis, database)?
  4. Toolchain Integration:
    • Will this integrate with Behat, PestPHP, or a custom test runner?
    • Should we add Artisan commands for parsing (e.g., php artisan gherkin:parse)?
  5. Maintenance:
    • Who will handle updates (e.g., new Cucumber parity features)?
    • Should we fork if upstream changes break compatibility?

Integration Approach

Stack Fit

  • PHP/Laravel: Native PHP package with no Laravel-specific dependencies; integrates via Composer and Service Container.
  • Testing Ecosystem:
    • Behat: Direct integration (this is the package’s primary use case).
    • PestPHP/PHPUnit: Use parsed ASTs to dynamically generate tests (e.g., from API specs).
    • Custom Tools: Parse Gherkin to generate documentation, validate specs, or sync with other systems (e.g., Jira, Confluence).
  • CI/CD:
    • Run parsing in GitHub Actions/GitLab CI to validate .feature files before merging.
    • Use as a pre-commit hook (via Laravel Forge or Laravel Envoyer).

Migration Path

  1. Composer Installation:
    composer require behat/gherkin
    
  2. Basic Parsing:
    use Behat\Gherkin\Parser;
    use Behat\Gherkin\Lexer;
    use Behat\Gherkin\Keywords\ArrayKeywords;
    
    $keywords = new ArrayKeywords(['en' => [...]]); // Load from package
    $lexer = new Lexer($keywords);
    $parser = new Parser($lexer);
    
    $feature = $parser->parse(file_get_contents('path/to/features/login.feature'));
    
  3. Laravel Integration:
    • Service Provider:
      $this->app->singleton(Parser::class, fn() => new Parser(new Lexer(new ArrayKeywords(['en' => [...])))));
      
    • Facade (Optional):
      // app/Facades/Gherkin.php
      public static function parse(string $file): FeatureNode { ... }
      
  4. Advanced Use Cases:
    • AST Traversal: Use FeatureNode methods (getChildren(), getSteps(), etc.) to transform or validate specs.
    • Caching: Store parsed ASTs in Laravel’s cache or Redis to avoid reprocessing.
    • Custom Dialects: Extend DialectProviderInterface for domain-specific keywords.

Compatibility

Component Compatibility Notes
Laravel Works with Laravel 5.8+ (PHP 7.2+); PHP 8.5 fully supported.
Behat Native integration; no additional setup needed if using Behat.
Cucumber gherkin-32 mode aligns with Cucumber’s parser (but test thoroughly).
PHP Extensions No hard dependencies, but YAML support (for NDJSON) may require yaml extension.
File Formats Supports .feature files, strings, and streams; can extend for NDJSON.

Sequencing

  1. Phase 1: Core Parsing
    • Implement basic parsing in a Service Provider.
    • Add Artisan command for ad-hoc parsing (e.g., php artisan gherkin:parse features/login.feature).
  2. Phase 2: AST Integration
    • Build AST traversal logic (e.g., validate steps, extract metadata).
    • Integrate with testing frameworks (e.g., generate PestPHP tests from Gherkin).
  3. Phase 3: Advanced Features
    • Add caching layer (filesystem/Redis).
    • Implement custom dialects or preprocessors.
  4. Phase 4: CI/CD
    • Add GitHub Actions to validate .feature files on PR.
    • Explore dynamic test generation in CI.

Operational Impact

Maintenance

  • Dependencies:
    • Minimal: Only PHP and Composer; no Laravel-specific dependencies.
    • Updates: Monitor Behat/Gherkin releases for breaking changes (e.g., gherkin-32 mode).
  • Deprecations:
    • Avoid extending Lexer/Parser (use ParserInterface).
    • Tag filtering syntax (@wip&&~slow) is deprecated; enforce @-prefixed tags in CI.
  • Community Support:
    • Active maintainers (acoulton, stof, carlos-granados); MIT license (low legal risk).
    • Open to contributions (documentation, testing, sponsorship).

Support

  • Debugging:
    • ParserExceptions provide detailed error messages (e.g., invalid syntax, missing @ in tags).
    • AST structure is well-d
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.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle