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

Fix some tests

This commit is contained in:
Samuel Štancl 2019-09-16 16:57:55 +02:00
parent a632b545b7
commit 1532ccf019
15 changed files with 121 additions and 118 deletions

View file

@ -6,8 +6,8 @@ namespace Stancl\Tenancy;
use Illuminate\Contracts\Console\Kernel as ConsoleKernel;
use Illuminate\Foundation\Application;
use Illuminate\Support\Collection;
use Stancl\Tenancy\Contracts\TenantCannotBeCreatedException;
use Stancl\Tenancy\Exceptions\NoTenantIdentifiedException;
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
/**
@ -34,9 +34,12 @@ class TenantManager
/** @var DatabaseManager */
protected $database;
/** @var callable[][] */
/** @var callable[][] Event listeners */
protected $listeners = [];
/** @var bool Has tenancy been initialized. */
public $initialized;
public function __construct(Application $app, ConsoleKernel $artisan, Contracts\StorageDriver $storage, DatabaseManager $database)
{
$this->app = $app;
@ -136,25 +139,32 @@ class TenantManager
* Get all tenants.
*
* @param Tenant[]|string[] $only
* @return Tenant[]
* @return Collection<Tenant>
*/
public function all($only = []): array
public function all($only = []): Collection
{
$only = array_map(function ($item) {
return $item instanceof Tenant ? $item->id : $item;
}, $only);
}, (array) $only);
return $this->storage->all($only);
return collect($this->storage->all($only));
}
public function initializeTenancy(Tenant $tenant): self
{
$this->bootstrapTenancy($tenant);
$this->setTenant($tenant);
$this->initialized = true;
return $this;
}
/** @alias initializeTenancy */
public function initialize(Tenant $tenant): self
{
return $this->initializeTenancy($tenant);
}
public function bootstrapTenancy(Tenant $tenant): self
{
$prevented = $this->event('bootstrapping');
@ -176,22 +186,30 @@ class TenantManager
$this->app[$bootstrapper]->end();
}
$this->initialized = false;
$this->tenant = null;
$this->event('ended');
return $this;
}
/** @alias endTenancy */
public function end(): self
{
return $this->endTenancy();
}
/**
* Get the current tenant.
*
* @param string $key
* @return Tenant|mixed
* @throws NoTenantIdentifiedException
* @return Tenant|null|mixed
*/
public function getTenant(string $key = null)
{
if (! $this->tenant) {
throw new NoTenantIdentifiedException;
return null;
}
if (! is_null($key)) {