farshadf's avatar

how to test app to insert user into database

hi , i want to make a test that in my application i want to insert like 100k users the porpuse from that is to see if i face any problems or not and see how much is my system is capable of handling in case of usernames slugs and other things i am wondring to see if i should do it in dusk or maybe in using seeders but the thing is that i want to test the application too not only the database that it can successfully create like 200k users and like 20k invoices .how usually people does that kind of tests . thanks in advance

0 likes
3 replies
bugsysha's avatar
bugsysha
Best Answer
Level 61

The hardest thing to read. Use capital letters, commas, new sentences, etc...

foreach(range(1, 200000) as $i) {
    $data[] = [
        'name' => sprintf('Name %s', $i),
        'email' => sprintf('user%[email protected]', $i),
        // and so on...
    ];
}

$chunks = array_chunk($data, 1000);
foreach($chunks as $chunk) {
    User::query()->insert($chunk);
}

You can also use following:

DB::unprepared();

foreach(range(1, 200000) as $i) {
    $data[] = [
        'name' => sprintf('Name %s', $i),
        'email' => sprintf('user%[email protected]', $i),
        // and so on...
    ];
}

User::query()->insert($data);
farshadf's avatar

Never noticed that before , i am really sorry for that and thanks for your help :)

bugsysha's avatar

I did the same thing before so we all learn at some point :)

1 like

Please or to participate in this conversation.