1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 09:34:05 +00:00

Add compatability for commands in Laravel 7

This commit is contained in:
Devon Mather 2020-03-20 19:47:56 +01:00
parent 30bab68b6a
commit d2df9a9866
3 changed files with 68 additions and 0 deletions

View file

@ -26,6 +26,8 @@ trait TenantAwareCommand
$this->laravel->call([$this, 'handle']);
});
}
return 1;
}
/**

View 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 = [];
}

View 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()
}
}