mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 14:14:03 +00:00
Add compatability for commands in Laravel 7
This commit is contained in:
parent
30bab68b6a
commit
d2df9a9866
3 changed files with 68 additions and 0 deletions
|
|
@ -26,6 +26,8 @@ trait TenantAwareCommand
|
||||||
$this->laravel->call([$this, 'handle']);
|
$this->laravel->call([$this, 'handle']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
35
tests/Etc/AddUserCommand.php
Normal file
35
tests/Etc/AddUserCommand.php
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Tests\Etc;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Stancl\Tenancy\Traits\TenantAwareCommand;
|
||||||
|
|
||||||
|
class AddUserCommand extends Command
|
||||||
|
{
|
||||||
|
use TenantAwareCommand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'user:add';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
User::create();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class User extends \Illuminate\Database\Eloquent\Model
|
||||||
|
{
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
31
tests/Traits/TenantAwareCommandTest.php
Normal file
31
tests/Traits/TenantAwareCommandTest.php
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Tests\Traits;
|
||||||
|
|
||||||
|
use Stancl\Tenancy\Tenant;
|
||||||
|
use Stancl\Tenancy\Tests\TestCase;
|
||||||
|
|
||||||
|
class TenantAwareCommandTest extends TestCase
|
||||||
|
{
|
||||||
|
public $autoCreateTenant = false;
|
||||||
|
public $autoInitTenancy = false;
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function commands_run_globally_are_tenant_aware()
|
||||||
|
{
|
||||||
|
$tenant1 = Tenant::new()->save();
|
||||||
|
$tenant2 = Tenant::new()->save();
|
||||||
|
|
||||||
|
$this->artisan('user:add')->assertExitCode(1);
|
||||||
|
|
||||||
|
tenancy()->initializeTenancy($tenant1);
|
||||||
|
$this->assertNotEmpty(User::all());
|
||||||
|
tenancy()->endTenancy()
|
||||||
|
|
||||||
|
tenancy()->initializeTenancy($tenant2);
|
||||||
|
$this->assertNotEmpty(User::all());
|
||||||
|
tenancy()->endTenancy()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue