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

Bridge Symfony Console Laravel Package

testo/bridge-symfony-console

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require --dev testo/bridge-symfony-console
    

    This adds the bin/testo executable to your project root.

  2. First Run:

    ./bin/testo run
    
    • Executes tests in your project (default: tests/ directory).
    • Outputs results in a Symfony Console-compatible format.
  3. Key Files:

    • Entry Point: vendor/bin/testo (symlink to bin/testo).
    • Configuration: Look for testo.php in your project root (auto-generated if missing).
    • Test Discovery: Defaults to tests/; override via --path flag or config.

First Use Case: Running Tests

# Basic test run (discover tests in `tests/`):
./bin/testo run

# Run tests in a custom directory:
./bin/testo run --path=custom/tests

# Generate JUnit XML for CI/CD:
./bin/testo run --log-junit=tests/junit.xml

Implementation Patterns

1. Embedding Testo in Custom Commands

Extend Testo\Bridge\SymfonyConsole\Command\TestoCommand to integrate Testo into your own Symfony Console commands:

use Testo\Bridge\SymfonyConsole\Command\TestoCommand;

class MyCustomTestCommand extends TestoCommand {
    protected function configure() {
        $this->setName('app:test-custom')
             ->setDescription('Run custom test suite');
    }

    protected function execute(InputInterface $input, OutputInterface $output) {
        $this->runTests(['--path' => 'custom/tests'], $output);
    }
}

2. Configuration Management

  • Auto-Generated Config: testo.php is created at first run in the project root.
    return [
        'paths' => [
            'tests' => 'tests/',
            'custom' => 'custom/tests',
        ],
        'default_path' => 'tests',
    ];
    
  • Override via CLI:
    ./bin/testo run --path=custom/tests --filter=MyTest
    

3. Integration with Laravel

  • Service Provider: Register the bin/testo command globally:
    // In AppServiceProvider@boot()
    if (file_exists($this->app->basePath('bin/testo'))) {
        $this->app->bind('command.testo', function () {
            return new \Testo\Bridge\SymfonyConsole\Command\RunCommand();
        });
        $this->commands(['command.testo']);
    }
    
  • Artisan Alias: Add to app/Console/Kernel.php:
    protected $commands = [
        \Testo\Bridge\SymfonyConsole\Command\RunCommand::class,
    ];
    

4. Test Filtering and Grouping

Leverage Testo’s filtering flags:

# Run tests matching a pattern:
./bin/testo run --filter="*UserTest"

# Run specific test groups:
./bin/testo run --groups="unit,integration"

5. CI/CD Integration

  • JUnit Output:
    ./bin/testo run --log-junit=build/logs/junit.xml
    
  • Exit Codes: Testo returns:
    • 0: All tests passed.
    • 1: Some tests failed.
    • 2: Test execution error.

Gotchas and Tips

Pitfalls

  1. Path Resolution:

    • The --path flag is treated as an absolute path to the project root (not the tests directory).
    • Example: --path=/var/www/project (not --path=/var/www/project/tests).
    • Fix: Use ./bin/testo run --path=$(pwd) for relative paths.
  2. Symfony 8+ Compatibility:

    • The init command may fail if your Symfony app uses newer container syntax (e.g., add()addService()).
    • Fix: Manually create testo.php or patch the init command logic.
  3. Configuration Overrides:

    • CLI flags override testo.php settings. Explicitly set defaults in config to avoid surprises:
      return [
          'default_path' => 'tests',
          'filter' => null, // Explicitly disable filtering
      ];
      
  4. Test Discovery Quirks:

    • Testo uses file globbing (*.php). Ensure your test files follow this pattern.
    • Debug: Use --verbose to see discovered test files:
      ./bin/testo run --verbose
      

Debugging Tips

  1. Dry Run:

    ./bin/testo run --dry-run
    

    Lists tests without executing them.

  2. Verbose Output:

    ./bin/testo run --verbose
    

    Shows test discovery and execution details.

  3. Log Levels:

    • Use --log-level=debug for granular logs (requires Testo’s debug configuration).

Extension Points

  1. Custom Testo Configuration:

    • Extend the Testo\Bridge\SymfonyConsole\TestoConfig class to add project-specific settings:
      class CustomTestoConfig extends TestoConfig {
          public function getCustomSetting() {
              return $this->config['custom_setting'] ?? null;
          }
      }
      
    • Bind it in your service container:
      $this->app->bind(TestoConfig::class, CustomTestoConfig::class);
      
  2. Pre/Post-Test Hooks:

    • Override TestoCommand::runTests() to inject setup/teardown:
      protected function runTests(array $args, OutputInterface $output) {
          $this->setupEnvironment();
          parent::runTests($args, $output);
          $this->teardownEnvironment();
      }
      
  3. Parallel Test Execution:

    • Use Testo’s --parallel flag (if supported) for faster runs:
      ./bin/testo run --parallel=4
      

Performance Tips

  1. Cache Test Discovery:

    • Testo caches discovered tests by default. Clear cache with:
      ./bin/testo init --force
      
  2. Filter Aggressively:

    • Narrow test scope with --filter to reduce execution time:
      ./bin/testo run --filter="*PerformanceTest"
      
  3. Avoid JUnit Overhead:

    • Skip --log-junit in local development unless needed for CI/CD.

Laravel-Specific Quirks

  1. Artisan Command Conflicts:

    • If you have a custom test Artisan command, alias the Testo command to avoid conflicts:
      // In app/Console/Kernel.php
      protected $commands = [
          \Testo\Bridge\SymfonyConsole\Command\RunCommand::class => 'testo:run',
      ];
      
    • Run with:
      php artisan testo:run
      
  2. Environment-Specific Config:

    • Load Testo config from Laravel’s environment files:
      // In testo.php
      return [
          'paths' => [
              'tests' => env('TEST_PATH', 'tests'),
          ],
      ];
      
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.
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views
spatie/ignition-contracts
earls/stork-command-queue-bundle