-
-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper to reset the test Firebase project
- Loading branch information
1 parent
48fedd7
commit 1ef4b1e
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
use Kreait\Firebase\Auth\UserRecord; | ||
use Kreait\Firebase\Database\RuleSet; | ||
use Kreait\Firebase\Factory; | ||
use Kreait\Firebase\Util; | ||
|
||
// Unsafe is needed because google/auth uses getenv/putenv to determine the Application Credentials | ||
$dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__.'/..'); | ||
$dotenv->safeLoad(); | ||
$dotenv->required('GOOGLE_APPLICATION_CREDENTIALS'); | ||
|
||
$factory = (new Factory())->withDatabaseUri(Util::getenv('TEST_FIREBASE_RTDB_URI')); | ||
|
||
$auth = $factory->createAuth(); | ||
$db = $factory->createDatabase(); | ||
|
||
echo 'Resetting database rules... '; | ||
$factory->createDatabase()->updateRules(RuleSet::private()); | ||
echo 'DONE'.PHP_EOL; | ||
|
||
echo 'Purging database... '; | ||
$factory->createDatabase()->getReference('/')->remove(); | ||
echo 'DONE'.PHP_EOL; | ||
|
||
echo 'Purging auth users... '; | ||
do { | ||
$users = iterator_to_array($auth->listUsers()); | ||
$uids = array_map(fn(UserRecord $record) => $record->uid, $users); | ||
|
||
if (count($uids) > 0) { | ||
$auth->deleteUsers($uids, true); | ||
} | ||
} while (count($uids) > 0); | ||
echo 'DONE'.PHP_EOL; |