Skip to content

coders-tm/laravel-core / .agents/skills/testbench-docs

testbench-package-testing

Verified

Develops 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.

testbench/the-basic/routes.md

View on GitHub
# Define Routes

It is recommended for a package to use defined routes similar to Laravel such as `routes/web.php` etc.

## `defineRoutes()` Method

If you need to add something early in the application bootstrapping process (which is executed between registering service providers and booting service providers) you could use the `defineRoute()` method:

```php
class TestCase extends \Orchestra\Testbench\TestCase
{
    /**
     * Define routes setup.
     *
     * @param  \Illuminate\Routing\Router  $router
     * @return void
     */
    protected function defineRoutes($router) # [!code ++:4] # [!code focus:4]
    {
        // Define routes.
    }
}
```

### Using Attribute

You can also use `Orchestra\Testbench\Attributes\DefineRoute` attribute to customize the use of `defineRoutes()` for specific tests.

```php
use Orchestra\Testbench\Attributes\DefineRoute; # [!code ++] # [!code focus]
use PHPUnit\Framework\Attributes\Test;

class TestCase extends \Orchestra\Testbench\TestCase
{
    /**
     * Define routes setup.
     *
     * @param  \Illuminate\Routing\Router  $router
     * @return void
     */
    protected function usesAuthRoutes($router) # [!code hl:4] # [!code focus:4] 
    {
        // Load auth routes.
    }

    #[Test]
    #[DefineRoute('usesAuthRoutes')] # [!code ++] # [!code focus]
    public function it_does_load_auth_routes()
    {
        // 
    }

    #[Test]
    public function it_doesnt_load_auth_routes()
    {
        //
    }
}
```

### Using Annotation

::: warning Deprecated

Annotation usage with PHPUnit has been mark as deprecated and will be removed in future versions.
:::

You can also use `@define-route` annotation to customize the use of `defineRoutes()` for specific tests.

```php
class TestCase extends \Orchestra\Testbench\TestCase
{
    /**
     * Define routes setup.
     *
     * @param  \Illuminate\Routing\Router  $router
     * @return void
     */
    protected function usesAuthRoutes($router) # [!code hl:4] # [!code focus:4] 
    {
        // Load auth routes.
    }

    /**
     * @test
     * @define-route usesAuthRoutes # [!code ++] # [!code focus]
     */
    public function it_does_load_auth_routes()
    {
        // 
    }

    /**
     * @test
     */
    public function it_doesnt_load_auth_routes()
    {
        //
    }
}
```
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 321kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 321kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 321kUpdated Claude CodeCodexVerifiedInstall
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: 197kUpdated Claude CodeCodexVerifiedInstall