mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-12 18:24:03 +00:00
improve testing docs (fix #35)
This commit is contained in:
parent
a607b35f16
commit
90545f715e
1 changed files with 17 additions and 1 deletions
|
|
@ -7,6 +7,8 @@ section: content
|
||||||
|
|
||||||
# Application Testing {#application-testing}
|
# Application Testing {#application-testing}
|
||||||
|
|
||||||
|
> Note: You cannot use `:memory:` SQLite databases or the `RefreshDatabase` trait due to the switching of default database.
|
||||||
|
|
||||||
To test your application with this package installed, you can create tenants in the `setUp()` method of your test case:
|
To test your application with this package installed, you can create tenants in the `setUp()` method of your test case:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
|
@ -19,13 +21,27 @@ protected function setUp(): void
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
And to delete tenants & their databases after tests:
|
||||||
|
```php
|
||||||
|
public function tearDown(): void
|
||||||
|
{
|
||||||
|
config([
|
||||||
|
'tenancy.queue_database_deletion' => false,
|
||||||
|
'tenancy.delete_database_after_tenant_deletion' => true,
|
||||||
|
]);
|
||||||
|
tenancy()->all()->each->delete();
|
||||||
|
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
If you're using the database storage driver, you will also need to run the migrations:
|
If you're using the database storage driver, you will also need to run the migrations:
|
||||||
```php
|
```php
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->artisan('migrate');
|
$this->artisan('migrate:fresh');
|
||||||
|
|
||||||
tenancy()->create('test.localhost');
|
tenancy()->create('test.localhost');
|
||||||
tenancy()->init('test.localhost');
|
tenancy()->init('test.localhost');
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue