Show the test and askEmail()
Oct 22, 2022
9
Level 4
Odd problem testing using in-memory Sqlite database
Hello peeps. I hope you can help me solve this odd little problem.
I have PhpUnit configued to use an in-memory SqlLite database.
<env name="DB_CONNECTION" value="sqlite" />
<env name="DB_DATABASE" value=":memory:" />
I'm testing a custom artisan command which creates a super user that checks if an email already exists in the users table.
while (User::where('email', $email)->exists()) {
$this->error('Email is alreay registered');
$email = $this->askEmail();
}
But the test fails with this error.
Question "Super user's password" was not asked.
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:709
705▕ */
706▕ protected function run($query, $bindings, Closure $callback)
707▕ {
708▕ foreach ($this->beforeExecutingCallbacks as $beforeExecutingCallback) {
➜ 709▕ $beforeExecutingCallback($query, $bindings, $this);
710▕ }
711▕
712▕ $this->reconnectIfMissingConnection();
713▕
+3 vendor frames
4 app/Console/Commands/Veellas/SuperUser.php:54
Illuminate\Database\Eloquent\Builder::__call()
5 app/Console/Commands/Veellas/SuperUser.php:19
App\Console\Commands\Veellas\SuperUser::askEmail()
Howver if I temporarely comment out the email check the user is stored in the database.
Can anybody shed any light on what moght ne going wrong?
Please or to participate in this conversation.