Installation Add the package via Composer:
composer require cmoclyn/symfony-test-manager
Publish the config (if needed):
php artisan vendor:publish --provider="Cmoclyn\TestManager\TestManagerServiceProvider"
First Use Case
Register a test suite in config/test-manager.php:
'suites' => [
'unit' => [
'path' => base_path('tests/Unit'),
'bootstrap' => base_path('tests/Unit/bootstrap.php'),
],
'feature' => [
'path' => base_path('tests/Feature'),
'bootstrap' => base_path('tests/Feature/bootstrap.php'),
],
],
Run tests via Artisan:
php artisan test:run unit
Key Files to Review
config/test-manager.php (configuration)app/Providers/TestManagerServiceProvider.php (customization)routes/test-manager.php (if exposing API endpoints)Test Suite Registration
Dynamically register suites in TestManagerServiceProvider:
public function register()
{
$this->app->singleton('test-manager', function ($app) {
return new TestManager([
'unit' => base_path('tests/Unit'),
'feature' => base_path('tests/Feature'),
]);
});
}
Custom Test Execution
Extend the TestManager class to add pre/post hooks:
use Cmoclyn\TestManager\TestManager as BaseTestManager;
class CustomTestManager extends BaseTestManager
{
protected function beforeRun(string $suite): void
{
// Pre-run logic (e.g., DB setup)
}
protected function afterRun(string $suite): void
{
// Post-run logic (e.g., cleanup)
}
}
Artisan Command Overrides
Override default commands in app/Console/Kernel.php:
protected $commands = [
\Cmoclyn\TestManager\Console\RunTests::class,
// Custom commands...
];
API Endpoints (Optional) Expose test results via Laravel routes:
Route::get('/test-results/{suite}', [TestManagerController::class, 'show']);
Configuration Overrides
config/test-manager.php paths are absolute (use base_path()).Bootstrap Files
bootstrap.php includes:
require __DIR__.'/../../../vendor/autoload.php';
$app = require __DIR__.'/../../../bootstrap/app.php';
Parallel Testing
php-parallel-lint or Laravel’s pest for parallelism.Caching Issues
php artisan config:clear
--verbose to Artisan commands:
php artisan test:run unit --verbose
TestManager to log execution:
protected function logRun(string $suite, string $status): void
{
\Log::info("Suite [$suite] status: [$status]");
}
Custom Test Filters
Add filters in TestManager:
public function getFilteredTests(string $suite, array $filters = []): array
{
return array_filter($this->suites[$suite]['tests'], function ($test) use ($filters) {
return !isset($filters['group']) || in_array($test['group'], $filters['group']);
});
}
Plugin System Use Laravel’s service providers to inject custom test runners:
$this->app->bind('test-runner', function () {
return new CustomTestRunner();
});
Database Transactions Wrap test suites in transactions (if not using Laravel’s built-in support):
protected function beforeRun(string $suite): void
{
DB::beginTransaction();
}
protected function afterRun(string $suite): void
{
DB::rollBack();
}
How can I help you explore Laravel packages today?