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

Get multiple envs (redis/db) to run correctly

This commit is contained in:
Samuel Štancl 2019-09-17 19:39:57 +02:00
parent 9c9858e97e
commit 8565cc7acc
19 changed files with 31 additions and 35 deletions

View file

@ -56,7 +56,7 @@ class Migrate extends MigrateCommand
// See Illuminate\Database\Migrations\DatabaseMigrationRepository::getConnection.
// Database connections are cached by Illuminate\Database\ConnectionResolver.
$this->input->setOption('database', 'tenant');
tenancy()->initialize($tenant); // todo test that this works with multiple tenants with MySQL
tenancy()->initialize($tenant); // todo2 test that this works with multiple tenants with MySQL
// Migrate
parent::handle();

View file

@ -8,7 +8,7 @@ use Stancl\Tenancy\Tenant;
interface TenancyBootstrapper
{
public function start(Tenant $tenant); // todo TenantManager instead of Tenant
public function start(Tenant $tenant); // todo2 TenantManager instead of Tenant
public function end();
}

View file

@ -129,7 +129,7 @@ class DatabaseManager
protected function getTenantDatabaseManager(Tenant $tenant): TenantDatabaseManager
{
// todo this shouldn't have to create a connection
// todo2 this shouldn't have to create a connection
$this->createTenantConnection($tenant->getDatabaseName(), $tenant->getConnectionName());
$driver = $this->getDriver($tenant->getConnectionName());

View file

@ -7,7 +7,7 @@ namespace Stancl\Tenancy\Facades;
use Illuminate\Support\Facades\Facade;
use Stancl\Tenancy\Tenant as Tenant;
// todo rename to CurrentTenant?
// todo2 rename to CurrentTenant?
class TenantFacade extends Facade
{
protected static function getFacadeAccessor()

View file

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

View file

@ -16,7 +16,7 @@ use Stancl\Tenancy\Tenant;
class DatabaseStorageDriver implements StorageDriver
{
// todo write tests verifying that data is decoded and added to the array
// todo2 write tests verifying that data is decoded and added to the array
/** @var Application */
protected $app;
@ -47,7 +47,7 @@ class DatabaseStorageDriver implements StorageDriver
public function ensureTenantCanBeCreated(Tenant $tenant): void
{
// todo test this
// todo2 test this
if (Tenants::find($tenant->id)) {
throw new TenantWithThisIdAlreadyExistsException($tenant->id);
}
@ -85,7 +85,7 @@ class DatabaseStorageDriver implements StorageDriver
public function updateTenant(Tenant $tenant): void
{
Tenant::find($tenant->id)->putMany($tenant->data);
// todo update domains
// todo1 update domains
}
public function deleteTenant(Tenant $tenant): void

View file

@ -10,10 +10,10 @@ use Stancl\Tenancy\Contracts\StorageDriver;
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedException;
use Stancl\Tenancy\Tenant;
// todo transactions instead of pipelines?
// todo2 transactions instead of pipelines?
class RedisStorageDriver implements StorageDriver
{
// todo json encoding?
// todo2 json encoding?
/** @var Application */
protected $app;
@ -49,7 +49,7 @@ class RedisStorageDriver implements StorageDriver
public function ensureTenantCanBeCreated(Tenant $tenant): void
{
// todo
// todo2
}
public function findByDomain(string $domain): Tenant
@ -76,7 +76,7 @@ class RedisStorageDriver implements StorageDriver
}
$data = array_combine($keys, $values);
$domains = []; // todo
$domains = []; // todo2
return Tenant::fromStorage($data)->withDomains($domains);
}
@ -107,7 +107,7 @@ class RedisStorageDriver implements StorageDriver
$pipe->hmset("domains:$domain", 'tenant_id', $tenant->id);
}
// todo deleted domains
// todo2 deleted domains
});
}
@ -124,7 +124,7 @@ class RedisStorageDriver implements StorageDriver
public function all(array $ids = []): array
{
// todo $this->redis->pipeline() - return?
// todo2 $this->redis->pipeline()
$hashes = array_map(function ($hash) {
return "tenants:{$hash}";
}, $ids);

View file

@ -29,7 +29,7 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
public function start(Tenant $tenant)
{
// todo revisit this
// todo2 revisit this
$suffix = $this->app['config']['tenancy.filesystem.suffix_base'] . $tenant->id;
// storage_path()

View file

@ -50,7 +50,7 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
'tenant_id' => $id,
'tags' => [
"tenant:$id",
// todo domain?
// todo2 domain
],
];
}

View file

@ -52,7 +52,9 @@ class TenancyServiceProvider extends ServiceProvider
{
$this->mergeConfigFrom(__DIR__ . '/../assets/config.php', 'tenancy');
$this->app->bind(Contracts\StorageDriver::class, $this->app['config']['tenancy.storage_driver']);
$this->app->bind(Contracts\StorageDriver::class, function ($app) {
return $app->make($app['config']['tenancy.storage_driver']);
});
$this->app->bind(Contracts\UniqueIdentifierGenerator::class, $this->app['config']['tenancy.unique_id_generator']);
$this->app->singleton(DatabaseManager::class);
$this->app->singleton(TenantManager::class);

View file

@ -240,7 +240,7 @@ class Tenant implements ArrayAccess
public function put($key, $value = null): self
{
if ($key === 'id') {
throw new TenantStorageException("The tenant's id can't be changed.");
throw new TenantStorageException("Tenant ids can't be changed.");
}
if (is_array($key)) {

View file

@ -29,7 +29,7 @@ class TenantManager
protected $artisan;
/** @var Contracts\StorageDriver */
protected $storage;
public $storage;
/** @var DatabaseManager */
public $database;
@ -229,7 +229,7 @@ class TenantManager
protected function bootstrapFeatures(): self
{
// todo this doesn't work
// todo1 this doesn't work
// foreach ($this->app['config']['tenancy.features'] as $feature) {
// $this->app[$feature]->bootstrap($this);
// }

View file

@ -6,7 +6,7 @@ namespace Stancl\Tenancy\Tests;
use Illuminate\Support\Facades\Redis;
// todo rename
// todo2 rename
class BootstrapsTenancyTest extends TestCase
{
public $autoInitTenancy = false;

View file

@ -117,7 +117,7 @@ class CommandsTest extends TestCase
->expectsOutput('xyz');
}
// todo check that multiple tenants can be migrated at once using all database engines
// todo2 check that multiple tenants can be migrated at once using all database engines
/** @test */
public function install_command_works()
@ -129,7 +129,7 @@ class CommandsTest extends TestCase
\mkdir($dir, 0777, true);
}
// todo move this to a file
// todo2 move this to a file
\file_put_contents(app_path('Http/Kernel.php'), "<?php
namespace App\Http;

View file

@ -17,7 +17,7 @@ class QueueTest extends TestCase
/** @test */
public function queues_use_non_tenant_db_connection()
{
// todo finish this test. requires using the db driver
// todo2 finish this test. requires using the db driver
$this->markTestIncomplete();
}

View file

@ -15,14 +15,14 @@ class TenantAssetTest extends TestCase
// response()->file() returns BinaryFileResponse whose content is
// inaccessible via getContent, so ->assertSee() can't be used
// $this->get(tenant_asset($filename))->assertSuccessful(); // TODO COMMENTED ASSERTIONS
// $this->assertFileExists($path); // TODO COMMENTED ASSERTIONS
// $this->get(tenant_asset($filename))->assertSuccessful(); // TODO2 COMMENTED ASSERTIONS
// $this->assertFileExists($path); // TODO2 COMMENTED ASSERTIONS
$f = \fopen($path, 'r');
$content = \fread($f, \filesize($path));
\fclose($f);
// $this->assertSame('bar', $content); // TODO COMMENTED ASSERTIONS
$this->assertTrue(true); // TODO COMMENTED ASSERTIONS
// $this->assertSame('bar', $content); // TODO2 COMMENTED ASSERTIONS
$this->assertTrue(true); // TODO2 COMMENTED ASSERTIONS
}
}

View file

@ -14,8 +14,6 @@ use Stancl\Tenancy\TenantDatabaseManagers\SQLiteDatabaseManager;
class TenantDatabaseManagerTest extends TestCase
{
// todo use data providers and TenantDatabaseManager::databaseExists()
/**
* @test
* @dataProvider database_manager_provider

View file

@ -205,6 +205,6 @@ class TenantManagerTest extends TestCase
/** @test */
public function id_cannot_be_changed()
{
// todo
// todo1
}
}

View file

@ -105,14 +105,10 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
$app['config']->set([
'tenancy.storage_driver' => RedisStorageDriver::class,
]);
// tenancy()->storage = $app->make(RedisStorageDriver::class); // TODO this shouldn't be necessary but is necessary
} elseif (env('TENANCY_TEST_STORAGE_DRIVER', 'redis') === 'db') {
$app['config']->set([
'tenancy.storage_driver' => DatabaseStorageDriver::class,
]);
// tenancy()->storage = $app->make(DatabaseStorageDriver::class); // TODO this shouldn't be necessary but is necessary
}
}