controleonline/smoke-tests-playground
Installation
composer require controleonline/smoke-tests-playground
Add the service provider to config/app.php:
'providers' => [
// ...
ControleOnline\SmokeTestsPlayground\SmokeTestsPlaygroundServiceProvider::class,
],
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);
});
Where to Look First
README.md for basic examples.SmokeTestsPlayground facade methods in src/Facades/SmokeTestsPlayground.php.src/Contracts/SmokeTestContract.php for expected test structures.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,
],
],
];
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']);
}
Dynamic Test Generation Fetch test configurations from a database or API:
$tests = TestConfig::all()->pluck('config')->toArray();
$results = SmokeTestsPlayground::run($tests);
Parallel Execution For large test suites, leverage Laravel queues or parallel processing:
foreach ($testGroups as $group) {
dispatch(new RunSmokeTestsJob($group))->onQueue('smoke-tests');
}
Assertion Mismatches
assert keys match supported assertions (e.g., status, contains, equals).$results['failed_tests']['homepage']['error'];
Session Handling
withHeaders:
'login' => [
'method' => 'POST',
'url' => '/login',
'headers' => ['X-CSRF-TOKEN' => csrf_token()],
],
Rate Limiting
SmokeTestsPlayground::run($tests, ['delay' => 1000]); // 1-second delay
Environment-Specific URLs
.env for dynamic URLs:
'url' => env('APP_URL') . '/api/endpoint',
Custom Assertions Extend functionality by adding custom assertions via service provider:
SmokeTestsPlayground::extend('custom_assert', function ($response, $expected) {
return $response->getContent() === $expected;
});
Logging Results Log test outcomes for debugging:
\Log::info('Smoke Tests Results', $results);
CI/CD Integration Fail builds on test failures:
php artisan smoke-tests:run --fail-on-failure
Mocking Dependencies Use Laravel’s mocking tools for isolated testing:
$this->mock(\Http::class)->shouldReceive('post')->andReturnResponse();
Performance Metrics Track test execution time:
$start = microtime(true);
$results = SmokeTestsPlayground::run($tests);
$time = microtime(true) - $start;
How can I help you explore Laravel packages today?