1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 08:24:04 +00:00

Fix assert: run createDatabase() outside assert()

assert() calls, including assert(foo()), can be entirely compiled out
depending on the INI settings described here:
https://www.php.net/manual/en/function.assert.php

That in turn means even side effects of foo() can be entirely compiled
out.

Therefore, to ensure the call actually runs, we need to run it before
the assert(), store its return value, and only then make assertions
about the return value.
This commit is contained in:
Samuel Štancl 2025-10-16 01:09:53 +02:00
parent 6049ade20e
commit 91f6c61fcd
No known key found for this signature in database
GPG key ID: BA146259A1E16C57

View file

@ -40,7 +40,8 @@ class CreateDatabase implements ShouldQueue
try {
$databaseManager->ensureTenantCanBeCreated($this->tenant);
assert($this->tenant->database()->manager()->createDatabase($this->tenant) === true);
$databaseCreated = $this->tenant->database()->manager()->createDatabase($this->tenant);
assert($databaseCreated);
event(new DatabaseCreated($this->tenant));
} catch (TenantDatabaseAlreadyExistsException | TenantDatabaseUserAlreadyExistsException $e) {