mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:54:05 +00:00
[2.2.0] Timestamps (#213)
* Timestamps * Apply fixes from StyleCI * Add void typehint * wip * Fix tests * Apply fixes from StyleCI
This commit is contained in:
parent
b0c8e92bb4
commit
31c9930c93
6 changed files with 124 additions and 4 deletions
40
tests/Features/TenantConfigTest.php
Normal file
40
tests/Features/TenantConfigTest.php
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Tests\Feature;
|
||||
|
||||
use Stancl\Tenancy\Tests\TestCase;
|
||||
|
||||
class TenantConfigTest extends TestCase
|
||||
{
|
||||
public $autoInitTenancy = false;
|
||||
public $autoCreateTenant = false;
|
||||
|
||||
/** @test */
|
||||
public function config_is_merged_and_removed()
|
||||
{
|
||||
$this->assertSame(null, config('services.paypal'));
|
||||
config([
|
||||
'tenancy.storage_to_config_map' => [
|
||||
'paypal_api_public' => 'services.paypal.public',
|
||||
'paypal_api_private' => 'services.paypal.private',
|
||||
],
|
||||
'tenancy.features' => ['Stancl\Tenancy\Features\TenantConfig'],
|
||||
]);
|
||||
|
||||
tenancy()->create('foo.localhost', [
|
||||
'paypal_api_public' => 'foo',
|
||||
'paypal_api_private' => 'bar',
|
||||
]);
|
||||
|
||||
tenancy()->init('foo.localhost');
|
||||
$this->assertSame(['public' => 'foo', 'private' => 'bar'], config('services.paypal'));
|
||||
|
||||
tenancy()->end();
|
||||
$this->assertSame([
|
||||
'public' => null,
|
||||
'private' => null,
|
||||
], config('services.paypal'));
|
||||
}
|
||||
}
|
||||
37
tests/Features/TenantRedirectMacroTest.php
Normal file
37
tests/Features/TenantRedirectMacroTest.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Tests\Feature;
|
||||
|
||||
use Route;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
use Stancl\Tenancy\Tests\TestCase;
|
||||
|
||||
class TenantRedirectMacroTest extends TestCase
|
||||
{
|
||||
public $autoCreateTenant = false;
|
||||
public $autoInitTenancy = false;
|
||||
|
||||
/** @test */
|
||||
public function tenant_redirect_macro_replaces_only_the_hostname()
|
||||
{
|
||||
config([
|
||||
'tenancy.features' => ['Stancl\Tenancy\Features\TenantRedirect'],
|
||||
]);
|
||||
|
||||
Route::get('/foobar', function () {
|
||||
return 'Foo';
|
||||
})->name('home');
|
||||
|
||||
Route::get('/redirect', function () {
|
||||
return redirect()->route('home')->tenant('abcd');
|
||||
});
|
||||
|
||||
Tenant::create('foo.localhost');
|
||||
tenancy()->init('foo.localhost');
|
||||
|
||||
$this->get('/redirect')
|
||||
->assertRedirect('http://abcd/foobar');
|
||||
}
|
||||
}
|
||||
56
tests/Features/TimestampTest.php
Normal file
56
tests/Features/TimestampTest.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Tests\Feature;
|
||||
|
||||
use Stancl\Tenancy\Features\Timestamps;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
use Stancl\Tenancy\Tests\TestCase;
|
||||
|
||||
class TimestampTest extends TestCase
|
||||
{
|
||||
public $autoCreateTenant = false;
|
||||
public $autoInitTenancy = false;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
config(['tenancy.features' => [
|
||||
Timestamps::class,
|
||||
]]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function create_and_update_timestamps_are_added_on_create()
|
||||
{
|
||||
$tenant = Tenant::new()->save();
|
||||
$this->assertArrayHasKey('created_at', $tenant->data);
|
||||
$this->assertArrayHasKey('updated_at', $tenant->data);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function update_timestamps_are_added()
|
||||
{
|
||||
$tenant = Tenant::new()->save();
|
||||
$this->assertSame($tenant->created_at, $tenant->updated_at);
|
||||
$this->assertSame('string', gettype($tenant->created_at));
|
||||
|
||||
sleep(1);
|
||||
|
||||
$tenant->put('abc', 'def');
|
||||
|
||||
$this->assertTrue($tenant->updated_at > $tenant->created_at);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function softdelete_timestamps_are_added()
|
||||
{
|
||||
$tenant = Tenant::new()->save();
|
||||
$this->assertNull($tenant->deleted_at);
|
||||
|
||||
$tenant->softDelete();
|
||||
$this->assertNotNull($tenant->deleted_at);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue