diff --git a/src/Tenant.php b/src/Tenant.php index cdf9f47e..8e6a900b 100644 --- a/src/Tenant.php +++ b/src/Tenant.php @@ -334,6 +334,8 @@ class Tenant implements ArrayAccess */ public function put($key, $value = null): self { + $this->manager->event('tenant.updating', $this); + if ($key === 'id') { throw new TenantStorageException("Tenant ids can't be changed."); } @@ -354,6 +356,8 @@ class Tenant implements ArrayAccess $this->data[$key] = $value; } + $this->manager->event('tenant.updated', $this); + return $this; } @@ -382,6 +386,8 @@ class Tenant implements ArrayAccess */ public function deleteKeys(array $keys): self { + $this->manager->event('tenant.updating', $this); + if (! $this->storage instanceof CanDeleteKeys) { throw new NotImplementedException(get_class($this->storage), 'deleteMany', 'This method was added to storage drivers provided by the package in 2.2.0 and will be part of the StorageDriver contract in 3.0.0.' @@ -393,6 +399,8 @@ class Tenant implements ArrayAccess } } + $this->manager->event('tenant.updated', $this); + return $this; } diff --git a/tests/Features/TenantConfigTest.php b/tests/Features/TenantConfigTest.php index b546ce21..4e2405be 100644 --- a/tests/Features/TenantConfigTest.php +++ b/tests/Features/TenantConfigTest.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace Stancl\Tenancy\Tests\Feature; +use Stancl\Tenancy\Tests\TestCase; + class TenantConfigTest extends TestCase { public $autoInitTenancy = false; diff --git a/tests/Features/TenantRedirectMacroTest.php b/tests/Features/TenantRedirectMacroTest.php index 5aeceb0b..8ae8cbe5 100644 --- a/tests/Features/TenantRedirectMacroTest.php +++ b/tests/Features/TenantRedirectMacroTest.php @@ -6,6 +6,7 @@ namespace Stancl\Tenancy\Tests\Feature; use Route; use Stancl\Tenancy\Tenant; +use Stancl\Tenancy\Tests\TestCase; class TenantRedirectMacroTest extends TestCase { diff --git a/tests/Features/TimestampTest.php b/tests/Features/TimestampTest.php index 1a75bb37..9592ed8a 100644 --- a/tests/Features/TimestampTest.php +++ b/tests/Features/TimestampTest.php @@ -26,7 +26,8 @@ class TimestampTest extends TestCase public function create_and_update_timestamps_are_added_on_create() { $tenant = Tenant::new()->save(); - $this->assertArraySubset(['created_at', 'updated_at'], $tenant->data); + $this->assertArrayHasKey('created_at', $tenant->data); + $this->assertArrayHasKey('updated_at', $tenant->data); } /** @test */ @@ -34,13 +35,22 @@ class TimestampTest extends TestCase { $tenant = Tenant::new()->save(); $this->assertSame($tenant->created_at, $tenant->updated_at); + $this->assertSame('string', gettype($tenant->created_at)); + + sleep(1); - $this->assert($tenant->updated_at > $tenant->created_at); + $tenant->put('abc', 'def'); + + $this->assertTrue($tenant->updated_at > $tenant->created_at); } /** @test */ public function softdelete_timestamps_are_added() { - $this->assertSame(); + $tenant = Tenant::new()->save(); + $this->assertNull($tenant->deleted_at); + + $tenant->softDelete(); + $this->assertNotNull($tenant->deleted_at); } }