mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 09:34:04 +00:00
Merge branch '3.x' into merge-3.x
This commit is contained in:
commit
790d7ff12a
12 changed files with 108 additions and 122 deletions
111
.github/workflows/ci.yml
vendored
111
.github/workflows/ci.yml
vendored
|
|
@ -15,104 +15,17 @@ jobs:
|
|||
|
||||
strategy:
|
||||
matrix:
|
||||
laravel: ['^9.0']
|
||||
include:
|
||||
- laravel: 9
|
||||
php: "8.0"
|
||||
- laravel: 10
|
||||
php: "8.1"
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Composer dependencies
|
||||
run: |
|
||||
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
|
||||
composer update --prefer-dist --no-interaction
|
||||
- name: Run tests
|
||||
run: ./vendor/bin/pest
|
||||
env:
|
||||
DB_PASSWORD: password
|
||||
DB_USERNAME: root
|
||||
DB_DATABASE: main
|
||||
TENANCY_TEST_MYSQL_HOST: mysql
|
||||
TENANCY_TEST_PGSQL_HOST: postgres
|
||||
TENANCY_TEST_REDIS_HOST: redis
|
||||
TENANCY_TEST_SQLSRV_HOST: mssql
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v2
|
||||
with:
|
||||
token: 24382d15-84e7-4a55-bea4-c4df96a24a9b
|
||||
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:latest
|
||||
env:
|
||||
POSTGRES_PASSWORD: password
|
||||
POSTGRES_USER: root
|
||||
POSTGRES_DB: main
|
||||
ports:
|
||||
- 5432/tcp
|
||||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
|
||||
|
||||
mysql:
|
||||
image: mysql:5.7
|
||||
env:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: false
|
||||
MYSQL_ROOT_PASSWORD: password
|
||||
MYSQL_DATABASE: main
|
||||
ports:
|
||||
- 3306/tcp
|
||||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
||||
|
||||
mysql2:
|
||||
image: mysql:5.7
|
||||
env:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: false
|
||||
MYSQL_ROOT_PASSWORD: password
|
||||
MYSQL_DATABASE: main
|
||||
ports:
|
||||
- 3306/tcp
|
||||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
||||
|
||||
mssql:
|
||||
image: mcr.microsoft.com/mssql/server:2019-latest
|
||||
ports:
|
||||
- 1433/tcp
|
||||
env:
|
||||
ACCEPT_EULA: Y
|
||||
SA_PASSWORD: P@ssword
|
||||
options: --health-cmd "echo quit | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -l 1 -U sa -P P@ssword"
|
||||
|
||||
redis:
|
||||
image: redis
|
||||
ports:
|
||||
- 6379/tcp
|
||||
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
||||
|
||||
php-cs-fixer:
|
||||
name: Code style (php-cs-fixer)
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install php-cs-fixer
|
||||
run: composer global require friendsofphp/php-cs-fixer
|
||||
- name: Run php-cs-fixer
|
||||
run: $HOME/.composer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php
|
||||
- name: Commit changes from php-cs-fixer
|
||||
uses: EndBug/add-and-commit@v5
|
||||
with:
|
||||
author_name: "PHP CS Fixer"
|
||||
author_email: "phpcsfixer@example.com"
|
||||
message: Fix code style (php-cs-fixer)
|
||||
|
||||
phpstan:
|
||||
name: Static analysis (PHPStan)
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.2'
|
||||
- uses: actions/checkout@v2
|
||||
- name: Install composer dependencies
|
||||
run: composer install
|
||||
- name: Run phpstan
|
||||
run: vendor/bin/phpstan analyse
|
||||
- uses: actions/checkout@v2
|
||||
- name: Start docker containers
|
||||
run: PHP_VERSION=${{ matrix.php }} docker-compose up -d
|
||||
- name: Install dependencies
|
||||
run: docker-compose exec -T test composer require --no-interaction "laravel/framework:^${{ matrix.laravel }}.0"
|
||||
- name: Run tests
|
||||
run: ./test
|
||||
|
|
|
|||
|
|
@ -24,16 +24,4 @@ To fix this, simply delete the database memory by shutting down containers and s
|
|||
|
||||
Run `composer docker-m1` to symlink `docker-compose-m1.override.yml` to `docker-compose.override.yml`. This will reconfigure a few services in the docker compose config to be compatible with M1.
|
||||
|
||||
### Coverage reports
|
||||
|
||||
To run tests and generate coverage reports, use `composer test-full`.
|
||||
|
||||
To view the coverage reports in your browser, use `composer coverage` (works on macOS; on other operating systems you can manually open `coverage/phpunit/html/index.html` in your browser).
|
||||
|
||||
### Rebuilding containers
|
||||
|
||||
If you need to rebuild the container for any reason (e.g. a change in `Dockerfile`), you can use `composer docker-rebuild`.
|
||||
|
||||
## PHPStan
|
||||
|
||||
Use `composer phpstan` to run our phpstan suite.
|
||||
to `docker-compose.override.yml` to make `docker-compose up -d` work on M1.
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ return [
|
|||
],
|
||||
|
||||
/**
|
||||
* Redis tenancy config. Used by RedisTenancyBoostrapper.
|
||||
* Redis tenancy config. Used by RedisTenancyBootstrapper.
|
||||
*
|
||||
* Note: You need phpredis to use Redis tenancy.
|
||||
*
|
||||
|
|
@ -286,6 +286,7 @@ return [
|
|||
// Stancl\Tenancy\Features\TelescopeTags::class,
|
||||
// Stancl\Tenancy\Features\TenantConfig::class, // https://tenancyforlaravel.com/docs/v3/features/tenant-config
|
||||
// Stancl\Tenancy\Features\CrossDomainRedirect::class, // https://tenancyforlaravel.com/docs/v3/features/cross-domain-redirect
|
||||
// Stancl\Tenancy\Features\ViteBundler::class,
|
||||
],
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -33,9 +33,8 @@ class ImpersonationToken extends Model
|
|||
public $incrementing = false;
|
||||
|
||||
protected $table = 'tenant_user_impersonation_tokens';
|
||||
|
||||
protected $dates = [
|
||||
'created_at',
|
||||
protected $casts = [
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
|
||||
public static function booted(): void
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ class Tenant extends Model implements Contracts\Tenant
|
|||
Concerns\InitializationHelpers,
|
||||
Concerns\InvalidatesResolverCache;
|
||||
|
||||
protected static $modelsShouldPreventAccessingMissingAttributes = false;
|
||||
|
||||
protected $table = 'tenants';
|
||||
protected $primaryKey = 'id';
|
||||
protected $guarded = [];
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ class PermissionControlledMySQLDatabaseManager extends MySQLDatabaseManager impl
|
|||
|
||||
protected function isVersion8(): bool
|
||||
{
|
||||
$version = $this->database()->select($this->database()->raw('select version()'))[0]->{'version()'};
|
||||
$versionSelect = $this->database()->raw('select version()')->getValue($this->database()->getQueryGrammar());
|
||||
$version = $this->database()->select($versionSelect)[0]->{'version()'};
|
||||
|
||||
return version_compare($version, '8.0.0') >= 0;
|
||||
}
|
||||
|
|
|
|||
26
src/Features/ViteBundler.php
Normal file
26
src/Features/ViteBundler.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Features;
|
||||
|
||||
use Illuminate\Foundation\Application;
|
||||
use Stancl\Tenancy\Contracts\Feature;
|
||||
use Stancl\Tenancy\Tenancy;
|
||||
use Stancl\Tenancy\Vite;
|
||||
|
||||
class ViteBundler implements Feature
|
||||
{
|
||||
/** @var Application */
|
||||
protected $app;
|
||||
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
public function bootstrap(Tenancy $tenancy): void
|
||||
{
|
||||
$this->app->singleton(\Illuminate\Foundation\Vite::class, Vite::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -62,6 +62,7 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
$this->app->singleton(Commands\Rollback::class, function ($app) {
|
||||
return new Commands\Rollback($app['migrator']);
|
||||
});
|
||||
|
||||
$this->app->singleton(Commands\Seed::class, function ($app) {
|
||||
return new Commands\Seed($app['db']);
|
||||
});
|
||||
|
|
|
|||
20
src/Vite.php
Normal file
20
src/Vite.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy;
|
||||
|
||||
use Illuminate\Foundation\Vite as BaseVite;
|
||||
|
||||
class Vite extends BaseVite // todo move to a different directory in v4
|
||||
{
|
||||
/**
|
||||
* Generate an asset path for the application.
|
||||
*
|
||||
* @param string $path
|
||||
* @param bool|null $secure
|
||||
* @return string
|
||||
*/
|
||||
protected function assetPath($path, $secure = null)
|
||||
{
|
||||
return global_asset($path);
|
||||
}
|
||||
}
|
||||
|
|
@ -79,7 +79,7 @@ test('ing events can be used to cancel db creation', function () {
|
|||
});
|
||||
|
||||
$tenant = Tenant::create();
|
||||
dispatch_now(new CreateDatabase($tenant));
|
||||
dispatch_sync(new CreateDatabase($tenant));
|
||||
|
||||
pest()->assertFalse($tenant->database()->manager()->databaseExists(
|
||||
$tenant->database()->getName()
|
||||
|
|
@ -171,12 +171,13 @@ test('database is not migrated if creation is disabled', function () {
|
|||
})->toListener()
|
||||
);
|
||||
|
||||
Tenant::create([
|
||||
$tenant = Tenant::create([
|
||||
'tenancy_create_database' => false,
|
||||
'tenancy_db_name' => 'already_created',
|
||||
]);
|
||||
|
||||
expect(pest()->hasFailed())->toBeFalse();
|
||||
// assert test didn't fail
|
||||
$this->assertTrue($tenant->exists());
|
||||
});
|
||||
|
||||
class FooListener extends QueueableListener
|
||||
|
|
|
|||
34
tests/Features/ViteBundlerTest.php
Normal file
34
tests/Features/ViteBundlerTest.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Stancl\Tenancy\Features\ViteBundler;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use Stancl\Tenancy\Tests\TestCase;
|
||||
use Stancl\Tenancy\Vite as StanclVite;
|
||||
|
||||
class ViteBundlerTest extends TestCase
|
||||
{
|
||||
/** @test */
|
||||
public function the_vite_helper_uses_our_custom_class()
|
||||
{
|
||||
$vite = app(\Illuminate\Foundation\Vite::class);
|
||||
|
||||
$this->assertInstanceOf(\Illuminate\Foundation\Vite::class, $vite);
|
||||
$this->assertNotInstanceOf(StanclVite::class, $vite);
|
||||
|
||||
config([
|
||||
'tenancy.features' => [ViteBundler::class],
|
||||
]);
|
||||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
app()->forgetInstance(\Illuminate\Foundation\Vite::class);
|
||||
|
||||
$vite = app(\Illuminate\Foundation\Vite::class);
|
||||
|
||||
$this->assertInstanceOf(StanclVite::class, $vite);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue