1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 14:14:03 +00:00

Fix tests

This commit is contained in:
Samuel Štancl 2019-11-04 17:18:31 +01:00
parent 6ed68dfd7f
commit e67ce1a3d9
4 changed files with 24 additions and 3 deletions

View file

@ -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;
}

View file

@ -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;

View file

@ -6,6 +6,7 @@ namespace Stancl\Tenancy\Tests\Feature;
use Route;
use Stancl\Tenancy\Tenant;
use Stancl\Tenancy\Tests\TestCase;
class TenantRedirectMacroTest extends TestCase
{

View file

@ -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);
}
}