1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 16:54:05 +00:00
tenancy/source/docs/application-testing.md
Samuel Štancl ac4cb3c34a wip
2019-08-23 22:52:03 +02:00

1.2 KiB

title description extends section
Application Testing Application Testing with stancl/tenancy — A Laravel multi-database tenancy package that respects your code.. _layouts.documentation content

Application Testing

To test your application with this package installed, you can create tenants in the setUp() method of your test case:

protected function setUp(): void
{
    parent::setUp();

    tenant()->create('test.localhost');
    tenancy()->init('test.localhost');
}

If you're using the database storage driver, you will also need to run the create_tenants_table migration:

protected function setUp(): void
{
    parent::setUp();

    $this->call('migrate', [
        '--path' => database_path('migrations'),
        '--database' => 'sqlite',
    ]);

    tenant()->create('test.localhost');
    tenancy()->init('test.localhost');
}

If you're using the Redis storage driver, flush the database in setUp():

protected function setUp(): void
{
    parent::setUp();

    // make sure you're using a different connection for testing to avoid losing data
    Redis::connection('tenancyTesting')->flushdb();

    tenant()->create('test.localhost');
    tenancy()->init('test.localhost');
}