Skip to content

Commit

Permalink
update test to use min & max
Browse files Browse the repository at this point in the history
  • Loading branch information
stancl committed Jan 21, 2025
1 parent 8f7b8e9 commit 760db83
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions tests/TenantModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
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]);

Expand Down Expand Up @@ -90,17 +95,12 @@

test('random ints are supported', function () {
app()->bind(UniqueIdentifierGenerator::class, RandomIntGenerator::class);
RandomIntGenerator::$min = 200;
RandomIntGenerator::$max = 1000;

// 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();
assert((int) $tenant1->id > 10**9);
} catch (\AssertionError) {
// retry
$tenant1 = Tenant::create();
assert((int) $tenant1->id > 10**9);
}
$tenant1 = Tenant::create();
expect($tenant1->id >= 200)->toBeTrue();
expect($tenant1->id <= 1000)->toBeTrue();
});

test('random string ids are supported', function () {
Expand Down

0 comments on commit 760db83

Please sign in to comment.