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

add RandomIntGenerator

This commit is contained in:
Samuel Štancl 2025-01-17 13:42:50 +01:00
parent 8b131ed647
commit 4525e0f941
7 changed files with 44 additions and 4 deletions

View file

@ -20,6 +20,7 @@ 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;
test('created event is dispatched', function () {
@ -87,6 +88,23 @@ test('hex ids are supported', function () {
RandomHexGenerator::$bytes = 6; // reset
});
test('random ints are supported', function () {
app()->bind(UniqueIdentifierGenerator::class, RandomIntGenerator::class);
// No good way to test this besides asserting that at least one of two ids
// should statistically be above 1 billion.
try {
$tenant1 = Tenant::create();
expect($tenant1->id)->toBeString();
assert((int) $tenant1->id > 10**9);
} catch (\AssertionError) {
// retry
$tenant1 = Tenant::create();
expect($tenant1->id)->toBeString();
assert((int) $tenant1->id > 10**9);
}
});
test('random string ids are supported', function () {
app()->bind(UniqueIdentifierGenerator::class, RandomStringGenerator::class);