Tests on asset tags that are maximum integers and *almost* maximum...

This commit is contained in:
Brady Wetherington 2024-06-03 17:31:56 +01:00
parent 90818bb147
commit e827bc9a07

View file

@ -6,6 +6,7 @@ use App\Models\AssetModel;
use App\Models\Category;
use Carbon\Carbon;
use Tests\TestCase;
use App\Models\Setting;
class AssetTest extends TestCase
{
@ -135,6 +136,40 @@ class AssetTest extends TestCase
$this->assertEquals($final->asset_tag, $final_result);
}
public function testAutoIncrementBIG()
{
$this->settings->enableAutoIncrement();
// we have to do this by hand to 'simulate' two web pages being open at the same time
$a = Asset::factory()->make(['asset_tag' => Asset::autoincrement_asset()]);
$b = Asset::factory()->make(['asset_tag' => 'ABCD' . (PHP_INT_MAX - 1)]);
$this->assertTrue($a->save());
$this->assertTrue($b->save());
\Log::error("A asset tag is: " . $a->asset_tag);
$matches = [];
preg_match('/\d+/', $a->asset_tag, $matches);
\Log::error("digits are: " . $matches[0]);
$this->assertEquals(Setting::getSettings()->next_auto_tag_base, $matches[0] + 1, "Next auto increment number should be the last normally-saved one plus one, but isn't");
}
public function testAutoIncrementAlmostBIG()
{
// TODO: this looks pretty close to the one above, could we maybe squish them together?
$this->settings->enableAutoIncrement();
// we have to do this by hand to 'simulate' two web pages being open at the same time
$a = Asset::factory()->make(['asset_tag' => Asset::autoincrement_asset()]);
$b = Asset::factory()->make(['asset_tag' => 'ABCD' . (PHP_INT_MAX - 2)]);
$this->assertTrue($a->save());
$this->assertTrue($b->save());
$matches = [];
preg_match('/\d+/', $b->asset_tag, $matches); //this is *b*, not *a* - slight difference from above test
$this->assertEquals(Setting::getSettings()->next_auto_tag_base, $matches[0] + 1, "Next auto increment number should be the last normally-saved one plus one, but isn't");
}
public function testWarrantyExpiresAttribute()
{