Weave 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

Smoke Tests Playground Laravel Package

controleonline/smoke-tests-playground

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require controleonline/smoke-tests-playground
    

    Add the service provider to config/app.php:

    'providers' => [
        // ...
        ControleOnline\SmokeTestsPlayground\SmokeTestsPlaygroundServiceProvider::class,
    ],
    
  2. First Use Case: Running Basic Smoke Tests Publish the config file (if needed) and define a test route:

    use ControleOnline\SmokeTestsPlayground\Facades\SmokeTestsPlayground;
    
    Route::get('/run-smoke-tests', function () {
        $results = SmokeTestsPlayground::run([
            'homepage' => 'GET /',
            'login'    => 'POST /login',
        ]);
        return response()->json($results);
    });
    
  3. Where to Look First

    • Documentation: Check the README.md for basic examples.
    • Facade: Explore SmokeTestsPlayground facade methods in src/Facades/SmokeTestsPlayground.php.
    • Test Definitions: Review src/Contracts/SmokeTestContract.php for expected test structures.

Implementation Patterns

Workflows

  1. Defining Tests Use associative arrays to define tests:

    $tests = [
        'homepage' => [
            'method' => 'GET',
            'url'    => '/',
            'assert' => [
                'status' => 200,
                'contains' => ['Welcome', 'Home'],
            ],
        ],
        'login' => [
            'method' => 'POST',
            'url'    => '/login',
            'data'   => ['email' => '[email protected]', 'password' => 'password'],
            'assert' => [
                'status' => 302,
            ],
        ],
    ];
    
  2. Integration with Laravel Testing Use the package alongside Laravel’s built-in testing tools:

    public function testSmokeTests()
    {
        $results = SmokeTestsPlayground::run($this->smokeTests);
        $this->assertTrue($results['all_passed']);
    }
    
  3. Dynamic Test Generation Fetch test configurations from a database or API:

    $tests = TestConfig::all()->pluck('config')->toArray();
    $results = SmokeTestsPlayground::run($tests);
    
  4. Parallel Execution For large test suites, leverage Laravel queues or parallel processing:

    foreach ($testGroups as $group) {
        dispatch(new RunSmokeTestsJob($group))->onQueue('smoke-tests');
    }
    

Gotchas and Tips

Pitfalls

  1. Assertion Mismatches

    • Ensure assert keys match supported assertions (e.g., status, contains, equals).
    • Debug failed tests with:
      $results['failed_tests']['homepage']['error'];
      
  2. Session Handling

    • POST requests may require session handling. Use middleware or withHeaders:
      'login' => [
          'method' => 'POST',
          'url'    => '/login',
          'headers' => ['X-CSRF-TOKEN' => csrf_token()],
      ],
      
  3. Rate Limiting

    • Rapid test execution may trigger rate limits. Add delays:
      SmokeTestsPlayground::run($tests, ['delay' => 1000]); // 1-second delay
      
  4. Environment-Specific URLs

    • Use Laravel’s .env for dynamic URLs:
      'url' => env('APP_URL') . '/api/endpoint',
      

Tips

  1. Custom Assertions Extend functionality by adding custom assertions via service provider:

    SmokeTestsPlayground::extend('custom_assert', function ($response, $expected) {
        return $response->getContent() === $expected;
    });
    
  2. Logging Results Log test outcomes for debugging:

    \Log::info('Smoke Tests Results', $results);
    
  3. CI/CD Integration Fail builds on test failures:

    php artisan smoke-tests:run --fail-on-failure
    
  4. Mocking Dependencies Use Laravel’s mocking tools for isolated testing:

    $this->mock(\Http::class)->shouldReceive('post')->andReturnResponse();
    
  5. Performance Metrics Track test execution time:

    $start = microtime(true);
    $results = SmokeTestsPlayground::run($tests);
    $time = microtime(true) - $start;
    
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.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast