mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:54:05 +00:00
[4.x] Improve id generators (#1300)
* add RandomIntGenerator * remove string assertions * make int ranges configurable * update test to use min & max
This commit is contained in:
parent
7ce7629864
commit
25360f6b6a
7 changed files with 43 additions and 4 deletions
|
|
@ -20,8 +20,14 @@ use Stancl\Tenancy\Tests\Etc\Tenant;
|
|||
use Stancl\Tenancy\UniqueIdentifierGenerators\UUIDGenerator;
|
||||
use Stancl\Tenancy\Exceptions\TenancyNotInitializedException;
|
||||
use Stancl\Tenancy\UniqueIdentifierGenerators\RandomHexGenerator;
|
||||
use Stancl\Tenancy\UniqueIdentifierGenerators\RandomIntGenerator;
|
||||
use Stancl\Tenancy\UniqueIdentifierGenerators\RandomStringGenerator;
|
||||
|
||||
afterEach(function () {
|
||||
RandomIntGenerator::$min = 0;
|
||||
RandomIntGenerator::$max = PHP_INT_MAX;
|
||||
});
|
||||
|
||||
test('created event is dispatched', function () {
|
||||
Event::fake([TenantCreated::class]);
|
||||
|
||||
|
|
@ -87,6 +93,16 @@ test('hex ids are supported', function () {
|
|||
RandomHexGenerator::$bytes = 6; // reset
|
||||
});
|
||||
|
||||
test('random ints are supported', function () {
|
||||
app()->bind(UniqueIdentifierGenerator::class, RandomIntGenerator::class);
|
||||
RandomIntGenerator::$min = 200;
|
||||
RandomIntGenerator::$max = 1000;
|
||||
|
||||
$tenant1 = Tenant::create();
|
||||
expect($tenant1->id >= 200)->toBeTrue();
|
||||
expect($tenant1->id <= 1000)->toBeTrue();
|
||||
});
|
||||
|
||||
test('random string ids are supported', function () {
|
||||
app()->bind(UniqueIdentifierGenerator::class, RandomStringGenerator::class);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue