mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-12 18:24:03 +00:00
1.1 KiB
1.1 KiB
| title | description | extends | section |
|---|---|---|---|
| Application Testing | Application Testing.. | _layouts.documentation_v2 | 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();
tenancy()->create('test.localhost');
tenancy()->init('test.localhost');
}
If you're using the database storage driver, you will also need to run the migrations:
protected function setUp(): void
{
parent::setUp();
$this->call('migrate', [
'--path' => database_path('migrations'),
'--database' => 'sqlite',
]);
tenancy()->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');
}