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

Add more tests

This commit is contained in:
Samuel Štancl 2019-02-07 21:44:47 +01:00
parent 18ce4577bf
commit fceddb8c4d
5 changed files with 87 additions and 3 deletions

View file

@ -0,0 +1,50 @@
<?php
namespace Stancl\Tenancy\Tests;
use Illuminate\Support\Facades\Redis;
class BootstrapsTenancyTest extends TestCase
{
public $initTenancy = false;
/** @test */
public function database_connection_is_switched()
{
$old_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName();
tenancy()->init('localhost');
$new_connection_name = app(\Illuminate\Database\DatabaseManager::class)->connection()->getName();
$this->assertNotEquals($old_connection_name, $new_connection_name);
$this->assertEquals('tenant', $new_connection_name);
}
/** @test */
public function redis_is_prefixed()
{
tenancy()->init('localhost');
foreach (config('tenancy.redis.prefixed_connections', ['default']) as $connection) {
$prefix = config('tenancy.redis.prefix_base') . tenant('uuid');
$client = Redis::connection($connection)->client();
$this->assertEquals($prefix, $client->getOption($client::OPT_PREFIX));
}
}
/** @test */
public function filesystem_is_suffixed()
{
$old_storage_path = storage_path();
tenancy()->init();
$new_storage_path = storage_path();
$this->assertEquals($old_storage_path . "/" . config('tenancy.filesystem.suffix_base') . tenant('uuid'), $new_storage_path);
}
/** @test */
public function cache_is_tagged()
{
$this->markTestIncomplete('see BootstrapsTenancyTest@cache_is_tagged');
// todo check that tags are set
// doesn't seem to be possible right now? can't find a way to get TaggedCache's tags
}
}

View file

@ -0,0 +1,24 @@
<?php
namespace Stancl\Tenancy\Tests;
class CacheManagerTest extends TestCase
{
/** @test */
public function default_tag_is_automatically_applied()
{
$this->markTestIncomplete('see BootstrapsTenancyTest@cache_is_tagged');
}
/** @test */
public function tags_are_merged_when_array_is_passed()
{
$this->markTestIncomplete('see BootstrapsTenancyTest@cache_is_tagged');
}
/** @test */
public function tags_are_merged_when_string_is_passed()
{
$this->markTestIncomplete('see BootstrapsTenancyTest@cache_is_tagged');
}
}

View file

@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Redis;
class TestCase extends \Orchestra\Testbench\TestCase
{
public $initTenancy = true;
/**
* Setup the test environment
*
@ -14,12 +16,14 @@ class TestCase extends \Orchestra\Testbench\TestCase
protected function setUp()
{
parent::setUp();
Redis::connection('tenancy')->flushdb();
tenant()->create('localhost');
tenancy()->init('localhost');
if ($this->initTenancy) {
tenancy()->init('localhost');
}
}
/**