mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 19:24:02 +00:00
Add testing section
This commit is contained in:
parent
5569054e49
commit
93740b358b
2 changed files with 52 additions and 0 deletions
|
|
@ -29,6 +29,7 @@ return [
|
|||
'Jobs & Queues' => 'docs/jobs-queues',
|
||||
'Event System' => 'docs/event-system',
|
||||
'Tenancy Initialization' => 'docs/tenancy-initialization',
|
||||
'Application Testing' => 'docs/application-testing',
|
||||
'Writing Storage Drivers' => 'docs/writing-storage-drivers',
|
||||
'Development' => 'docs/development',
|
||||
],
|
||||
|
|
|
|||
51
source/docs/application-testing.md
Normal file
51
source/docs/application-testing.md
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
---
|
||||
title: Application Testing
|
||||
description: Application Testing with stancl/tenancy — A Laravel multi-database tenancy package that respects your code..
|
||||
extends: _layouts.documentation
|
||||
section: content
|
||||
---
|
||||
|
||||
# Testing {#testing}
|
||||
|
||||
To test your application with this package installed, you can create tenants in the `setUp()` method of your test case:
|
||||
|
||||
```php
|
||||
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:
|
||||
```php
|
||||
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()`:
|
||||
|
||||
```php
|
||||
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');
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue