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

Fix first test

This commit is contained in:
Samuel Štancl 2019-09-15 21:53:03 +02:00
parent 359766ccfa
commit a7bb709bd4
10 changed files with 29 additions and 39 deletions

View file

@ -60,7 +60,7 @@ return [
'cache' => 'Stancl\Tenancy\TenancyBootstrappers\CacheTenancyBootstrapper',
'filesystem' => 'Stancl\Tenancy\TenancyBootstrappers\FilesystemTenancyBootstrapper',
'redis' => 'Stancl\Tenancy\TenancyBootstrappers\RedisTenancyBootstrapper',
'queue' => 'Stancl\Tenancy\TenancyBoostrappers\QueueTenancyBootstrapper',
'queue' => 'Stancl\Tenancy\TenancyBootstrappers\QueueTenancyBootstrapper',
],
'features' => [
// Features are classes that provide additional functionality

View file

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Exceptions;
class CannotChangeUuidOrDomainException extends \Exception
{
protected $message = 'Uuid and domain cannot be changed.';
}

View file

@ -25,7 +25,7 @@ class TelescopeTags implements Feature
if (in_array('tenancy', optional(request()->route())->middleware() ?? [])) {
$tags = array_merge($tags, [
'tenant:' . tenant('uuid'),
'tenant:' . tenant('id'),
'domain:' . tenant('domain'),
]);
}

View file

@ -2,16 +2,26 @@
declare(strict_types=1);
namespace Stancl\Tenancy\TenancyBoostrappers;
namespace Stancl\Tenancy\TenancyBootstrappers;
use Illuminate\Cache\CacheManager;
use Illuminate\Contracts\Foundation\Application;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Tenant;
class CacheTenancyBoostrapper implements TenancyBootstrapper
class CacheTenancyBootstrapper implements TenancyBootstrapper
{
/** @var \Illuminate\Cache\CacheManager */
/** @var CacheManager */
protected $originalCache;
/** @var Application */
protected $app;
public function __construct(Application $app)
{
$this->app = $app;
}
public function start(Tenant $tenant)
{
$this->originalCache = $this->originalCache ?? $this->app['cache'];

View file

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Stancl\Tenancy\TenancyBoostrappers;
namespace Stancl\Tenancy\TenancyBootstrappers;
use Illuminate\Foundation\Application;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;

View file

@ -2,8 +2,10 @@
declare(strict_types=1);
namespace Stancl\Tenancy\TenancyBoostrappers;
namespace Stancl\Tenancy\TenancyBootstrappers;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Facades\Storage;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Tenant;
@ -28,7 +30,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
public function start(Tenant $tenant)
{
// todo revisit this
$suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . tenant('uuid');
$suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . $tenant->id;
// storage_path()
$this->app->useStoragePath($this->originalPaths['path'] . "/{$suffix}");

View file

@ -2,8 +2,9 @@
declare(strict_types=1);
namespace Stancl\Tenancy\TenancyBoostrappers;
namespace Stancl\Tenancy\TenancyBootstrappers;
use Illuminate\Contracts\Foundation\Application;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Tenant;

View file

@ -2,8 +2,10 @@
declare(strict_types=1);
namespace Stancl\Tenancy\TenantDatabaseManagers;
namespace Stancl\Tenancy\TenancyBootstrappers;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Facades\Redis;
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Tenant;
@ -23,7 +25,7 @@ class RedisTenancyBootstrapper implements TenancyBootstrapper
public function start(Tenant $tenant)
{
foreach ($this->prefixedConnections() as $connection) {
$prefix = $this->app['config']['tenancy.redis.prefix_base'] . $this->tenant['uuid'];
$prefix = $this->app['config']['tenancy.redis.prefix_base'] . $tenant['id'];
$client = Redis::connection($connection)->client();
$this->originalPrefixes[$connection] = $client->getOption($client::OPT_PREFIX);

View file

@ -219,7 +219,7 @@ class TenantManager
}
/**
* Return a list of TenancyBoostrappers.
* Return a list of TenancyBootstrappers.
*
* @param string[] $except
* @return Contracts\TenancyBootstrapper[]

View file

@ -6,7 +6,6 @@ namespace Stancl\Tenancy\Tests;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Stancl\Tenancy\Exceptions\CannotChangeUuidOrDomainException;
class TenantManagerTest extends TestCase
{
@ -228,22 +227,8 @@ class TenantManagerTest extends TestCase
}
/** @test */
public function uuid_and_domain_cannot_be_changed()
public function id_cannot_be_changed()
{
$tenant = tenant()->create('foo.localhost');
$this->expectException(CannotChangeUuidOrDomainException::class);
tenant()->put('uuid', 'foo', $tenant['uuid']);
$this->expectException(CannotChangeUuidOrDomainException::class);
tenant()->put(['uuid' => 'foo'], null, $tenant['uuid']);
tenancy()->init('foo.localhost');
$this->expectException(CannotChangeUuidOrDomainException::class);
tenant()->put('uuid', 'foo');
$this->expectException(CannotChangeUuidOrDomainException::class);
tenant()->put(['uuid' => 'foo']);
// todo
}
}