mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:24:03 +00:00
Add more tests
This commit is contained in:
parent
18ce4577bf
commit
fceddb8c4d
5 changed files with 87 additions and 3 deletions
|
|
@ -326,7 +326,7 @@ Assuming the following tenancy config:
|
||||||
],
|
],
|
||||||
```
|
```
|
||||||
|
|
||||||
The `local` filesystem driver will be suffixed with a directory containing `tenant` and the tenant UUID.
|
The `local` filesystem driver will be suffixed with a directory named `tenant` + the tenant UUID.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
>>> Storage::disk('local')->getAdapter()->getPathPrefix()
|
>>> Storage::disk('local')->getAdapter()->getPathPrefix()
|
||||||
|
|
@ -431,3 +431,5 @@ However, you still need to reload nginx configuration to apply the changes to co
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
If you run the tests of this package, please make sure you don't store anything in Redis @ 127.0.0.1:6379 db#14. The contents of this database are flushed everytime the tests are run.
|
If you run the tests of this package, please make sure you don't store anything in Redis @ 127.0.0.1:6379 db#14. The contents of this database are flushed everytime the tests are run.
|
||||||
|
|
||||||
|
Some tests are run only if the `CI`, `TRAVIS` and `CONTINUOUS_INTEGRATION` environment variables are set to `true`. This is to avoid things like bloating your MySQL instance with test databases.
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ class CacheManager extends BaseCacheManager
|
||||||
$tags = [config('tenancy.cache.prefix_base') . tenant('uuid')];
|
$tags = [config('tenancy.cache.prefix_base') . tenant('uuid')];
|
||||||
|
|
||||||
if ($method === "tags") {
|
if ($method === "tags") {
|
||||||
|
if (count($parameters == 1) && is_array($parameters[0])) {
|
||||||
|
$parameters = [$parameters]; // cache()->tags('foo') https://laravel.com/docs/5.7/cache#removing-tagged-cache-items
|
||||||
|
}
|
||||||
|
|
||||||
return $this->store()->tags(array_merge($tags, ...$parameters));
|
return $this->store()->tags(array_merge($tags, ...$parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
50
tests/BootstrapsTenancyTest.php
Normal file
50
tests/BootstrapsTenancyTest.php
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
24
tests/CacheManagerTest.php
Normal file
24
tests/CacheManagerTest.php
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,8 @@ use Illuminate\Support\Facades\Redis;
|
||||||
|
|
||||||
class TestCase extends \Orchestra\Testbench\TestCase
|
class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
{
|
{
|
||||||
|
public $initTenancy = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup the test environment
|
* Setup the test environment
|
||||||
*
|
*
|
||||||
|
|
@ -14,12 +16,14 @@ class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
Redis::connection('tenancy')->flushdb();
|
Redis::connection('tenancy')->flushdb();
|
||||||
|
|
||||||
tenant()->create('localhost');
|
tenant()->create('localhost');
|
||||||
|
|
||||||
tenancy()->init('localhost');
|
if ($this->initTenancy) {
|
||||||
|
tenancy()->init('localhost');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue