Set up Pest testing with Orchestra Testbench for Laravel packages
This skill is limited to using the following tools:
scripts/setup_pest_testing.pyAdds complete PestPHP testing infrastructure to an existing Laravel package.
When the user wants to add testing to an existing package:
python3 ${SKILL_DIR}/scripts/setup_pest_testing.py <vendor/package-name> [options]
--filament - Include Filament/Livewire testing utilities--with-coverage - Add code coverage configuration--with-ci - Add GitHub Actions CI workflowpython3 ${SKILL_DIR}/scripts/setup_pest_testing.py mwguerra/my-package
python3 ${SKILL_DIR}/scripts/setup_pest_testing.py mwguerra/filament-blog --filament
python3 ${SKILL_DIR}/scripts/setup_pest_testing.py mwguerra/my-package --with-coverage --with-ci
phpunit.xml - PHPUnit configuration
src/ directorytests/Pest.php - PestPHP configuration
tests/TestCase.php - Orchestra TestCase
tests/Unit/ExampleTest.php - Sample unit test
tests/Feature/.gitkeep - Feature tests directory
.github/workflows/tests.yml (if --with-ci)
{
"require-dev": {
"orchestra/testbench": "^10.0",
"pestphp/pest": "^3.8",
"pestphp/pest-plugin-laravel": "^3.1"
},
"autoload-dev": {
"psr-4": {
"Vendor\\PackageName\\Tests\\": "tests/"
}
},
"scripts": {
"test": "pest",
"test-coverage": "pest --coverage"
}
}
Note: Uses latest versions for Laravel 11/12 compatibility:
After setup:
# Navigate to package
cd packages/vendor/package-name
# Install dependencies (including dev)
composer install
# Run all tests
./vendor/bin/pest
# Run with coverage
./vendor/bin/pest --coverage
# Run specific test file
./vendor/bin/pest tests/Unit/ExampleTest.php
# Run filtered tests
./vendor/bin/pest --filter="service provider"
# Run in parallel
./vendor/bin/pest --parallel
test('it does something', function () {
// Arrange
$data = ['key' => 'value'];
// Act
$result = processData($data);
// Assert
expect($result)->toBeTrue();
});
test('service is registered', function () {
expect($this->app->bound('my-service'))->toBeTrue();
});
test('command runs successfully', function () {
$this->artisan('my-package:command')
->expectsOutput('Success!')
->assertSuccessful();
});
uses(RefreshDatabase::class);
test('it creates model', function () {
$model = MyModel::create(['name' => 'Test']);
expect($model)->toBeInstanceOf(MyModel::class);
$this->assertDatabaseHas('my_models', ['name' => 'Test']);
});
use Livewire\Livewire;
test('component renders', function () {
Livewire::test(MyComponent::class)
->assertSee('Expected text')
->assertStatus(200);
});
When --filament is enabled, tests should follow Filament’s guidance:
livewire() / Livewire::test().