1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-06 01:34:02 +00:00

Convert test cases

This commit is contained in:
Shift 2022-06-28 20:56:04 +00:00
parent 405b91085e
commit a8dcd0dfc9
No known key found for this signature in database
GPG key ID: 5A96F038425C5A1C
27 changed files with 3059 additions and 3658 deletions

View file

@ -2,64 +2,51 @@
declare(strict_types=1);
namespace Stancl\Tenancy\Tests;
use Illuminate\Support\Facades\Route;
use Stancl\Tenancy\Middleware\InitializeTenancyByRequestData;
use Stancl\Tenancy\Tests\Etc\Tenant;
class RequestDataIdentificationTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
uses(Stancl\Tenancy\Tests\TestCase::class);
config([
'tenancy.central_domains' => [
'localhost',
],
]);
beforeEach(function () {
config([
'tenancy.central_domains' => [
'localhost',
],
]);
Route::middleware(InitializeTenancyByRequestData::class)->get('/test', function () {
return 'Tenant id: ' . tenant('id');
});
}
Route::middleware(InitializeTenancyByRequestData::class)->get('/test', function () {
return 'Tenant id: ' . tenant('id');
});
});
public function tearDown(): void
{
InitializeTenancyByRequestData::$header = 'X-Tenant';
InitializeTenancyByRequestData::$queryParameter = 'tenant';
afterEach(function () {
InitializeTenancyByRequestData::$header = 'X-Tenant';
InitializeTenancyByRequestData::$queryParameter = 'tenant';
});
parent::tearDown();
}
test('header identification works', function () {
InitializeTenancyByRequestData::$header = 'X-Tenant';
$tenant = Tenant::create();
$tenant2 = Tenant::create();
/** @test */
public function header_identification_works()
{
InitializeTenancyByRequestData::$header = 'X-Tenant';
$tenant = Tenant::create();
$tenant2 = Tenant::create();
$this
->withoutExceptionHandling()
->get('test', [
'X-Tenant' => $tenant->id,
])
->assertSee($tenant->id);
});
$this
->withoutExceptionHandling()
->get('test', [
'X-Tenant' => $tenant->id,
])
->assertSee($tenant->id);
}
test('query parameter identification works', function () {
InitializeTenancyByRequestData::$header = null;
InitializeTenancyByRequestData::$queryParameter = 'tenant';
/** @test */
public function query_parameter_identification_works()
{
InitializeTenancyByRequestData::$header = null;
InitializeTenancyByRequestData::$queryParameter = 'tenant';
$tenant = Tenant::create();
$tenant2 = Tenant::create();
$tenant = Tenant::create();
$tenant2 = Tenant::create();
$this
->withoutExceptionHandling()
->get('test?tenant=' . $tenant->id)
->assertSee($tenant->id);
}
}
$this
->withoutExceptionHandling()
->get('test?tenant=' . $tenant->id)
->assertSee($tenant->id);
});