coders-tm/laravel-core / .agents/skills/testbench-docs
testbench-package-testing
VerifiedDevelops and tests Laravel packages using Orchestra Testbench. Activates when writing package tests, configuring testbench.yaml, managing migrations, defining routes/environment for tests, using Testbench Dusk for browser tests, or working with Workbench for package preview.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 7.2 KB |
| api-examples.md | markdown | 907 B |
| getting-started.md | markdown | 3.2 KB |
| getting-started/configuration.md | markdown | 5.2 KB |
| markdown-examples.md | markdown | 1.0 KB |
| testbench-dusk.md | markdown | 3.3 KB |
| testbench-dusk/the-basic.md | markdown | 3.3 KB |
| testbench-dusk/troubleshooting.md | markdown | 1.7 KB |
| testbench.md | markdown | 2.7 KB |
| testbench/cli.md | markdown | 1.9 KB |
| testbench/integrations.md | markdown | 2.0 KB |
| testbench/the-basic.md | markdown | 6.4 KB |
| testbench/the-basic/databases.md | markdown | 5.0 KB |
| testbench/the-basic/environment.md | markdown | 4.9 KB |
| testbench/the-basic/routes.md | markdown | 2.3 KB |
| testbench/troubleshooting.md | markdown | 3.5 KB |
| workbench.md | markdown | 1.2 KB |
testbench-dusk/the-basic.md
View on GitHub# The Basic
[[toc]]
## Custom Host and Port
By default, Testbench Dusk will start its own PHP server at `http://127.0.0.1:8001`.
You can customize this by replacing the `$baseServeHost` and `$baseServePort` such as below:
```php
class DuskTestCase extends \Orchestra\Testbench\Dusk\TestCase
{
/**
* The base serve host URL to use while testing the application.
*
* @var string
*/
protected static $baseServeHost = '127.0.0.1'; # [!code ++] # [!code focus]
/**
* The base serve port to use while testing the application.
*
* @var int
*/
protected static $baseServePort = 9000; # [!code ++] # [!code focus]
}
```
## Running with or without UI
Dusk offers the ability to run Dusk tests without UI (the browser window), and this is the default and is normally slightly quicker. You can switch the behavior with the following calls:
```php
use Orchestra\Testbench\Dusk\Options; # [!code ++]
class DuskTestCase extends \Orchestra\Testbench\Dusk\TestCase
{
/**
* Prepare the testing environment web driver options.
*
* @api
*
* @return void
*/
public static function defineWebDriverOptions() # [!code ++:8] # [!code focus:8]
{
// To show the UI during testing
Options::withUI();
// To hide the UI during testing
Options::withoutUI();
}
}
```
## Supported Database
By default, you can either use `sqlite`, `mysql`, `pgsql`, or `sqlsrv` with Testbench Dusk. However, do note that it is impossible to use `sqlite` using `:memory:` database as you would with **Testbench** or **Testbench BrowserKit**.
If you opt to use SQLite, you might want to set the default database connection to `sqlite` either using `phpunit` configuration or setting it up on `defineEnvironment()` method.
```php
class DuskTestCase extends \Orchestra\Testbench\Dusk\TestCase
{
/**
* Define environment setup.
*
* @param Illuminate\Foundation\Application $app
*
* @return void
*/
protected function defineEnvironment($app) # [!code ++:4] # [!code focus:4]
{
$this->app['config']->set('database.default', 'sqlite');
}
}
```
> **Note**: In contradiction with laravel documentation you **should not** use `Illuminate\Foundation\Testing\DatabaseMigrations` trait, as testbench-dusk handles rollbacks by its self
To create the SQLite database you just need to run the following code:
```bash
vendor/bin/testbench-dusk package:create-sqlite-db
```
## Customising the Laravel served instance used during a test
With Testbench Dusk, it executes a separate process to serve the application and any changes made within the TestCase don't get executed in the served instance.
As an example, sometimes you will want to make a minor change to the application for a single test such as changing a config item, etc. This is made possible by using the `beforeServingApplication` method on the test and passing in a closure to apply.
```php
use Laravel\Dusk\Browser;
use PHPUnit\Framework\Attributes\Test;
// ...
#[Test]
public function it_can_send_email()
{
$this->beforeServingApplication(function ($app, $config) { # [!code ++:3] # [!code focus:4]
$config->set('mail.default', 'log');
});
$this->browse(function (Browser $browser) {
});
}
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |