---
title: "Testing — Package Toolkit for Laravel | Roundly"
description: "Load your package’s migrations explicitly in its TestCase, then test config guards, macros and directives through the public API."
url: https://roundly-consulting.com/open-source/docs/package-toolkit-for-laravel/testing
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Package Toolkit for Laravel](https://roundly-consulting.com/open-source/docs/package-toolkit-for-laravel.md)

# Testing

Because migrations are publish-only, a package built on the toolkit must run its own migrations explicitly in its test suite — for example in an Orchestra Testbench TestCase:

```php
use Orchestra\Testbench\TestCase as Orchestra;

abstract class TestCase extends Orchestra
{
    protected function getPackageProviders($app): array
    {
        return [CommentsServiceProvider::class];
    }

    protected function defineDatabaseMigrations(): void
    {
        // Migrations are publish-only — the package's own suite loads them explicitly.
        $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
    }
}
```

Register your provider there too, so the builder, macros and directives boot exactly as they do in a host application. Then assert through the public API — config guards throw, the LIKE macro treats wildcards literally, Blade conditionals render the right branch:

```php
use Illuminate\Support\Facades\Blade;
use RoundlyConsulting\PackageToolkit\Exceptions\InvalidConfigurationException;
use RoundlyConsulting\PackageToolkit\Support\Config;

it('rejects an out-of-range page size', function (): void {
    config()->set('comments.per_page', 500);

    Config::integer('comments.per_page', 20, min: 1, max: 100);
})->throws(InvalidConfigurationException::class, 'between 1 and 100');

it('treats user wildcards literally', function (): void {
    Comment::query()->create(['body' => 'hello world']);
    Comment::query()->create(['body' => 'he%lo there']);

    expect(Comment::query()->whereLikeEscaped('body', '%lo')->pluck('body')->all())
        ->toBe(['he%lo there']);
});

it('renders the else branch of the conditional directive', function (): void {
    $output = Blade::render('@commentsEnabled($flag) on @else off @endcommentsEnabled', ['flag' => false]);

    expect(trim($output))->toBe('off');
});
```

The toolkit’s own suite runs with composer test, against a fixture package that exercises every builder method and opt-in trait.

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/package-toolkit-for-laravel.md)
