Replies: 3 comments 2 replies
-
Hiya, Laravel doesn't throw errors by default, but handles em nicely for you. Turn off exception handling in your test: You're creating an empty model and haven't added any attributes to your models fillable array. Read more here: https://laravel.com/docs/9.x/eloquent#inserting-and-updating-models |
Beta Was this translation helpful? Give feedback.
-
You can implement |
Beta Was this translation helpful? Give feedback.
-
Just stumbled upon this. The problem is that Since you're referencing it in a variable, it isn't being destructed prior to your DB assertion. Just don't assign it to a variable and you should be good to go. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
When my Artisan command is run, it creates a model record in the database. die & dumping the table
count()
after the create show one record, but asserting table count in the test gives zero.Tried with mysql and sqlite : in mysql I could workaround the problem with adding a DB::commit() just after the create (the assert then passes), but in sqlite, it had no effect.
Steps To Reproduce:
Create a simple artisan command, that tries to
Create
a model :Create the model and the migration with
php artisan make:model -mf RegisteredApplication
Create a test that runs this command :
Run the test : the
assertDatabaseCount
fails.Github repo to illustrate the issue :
https://github.com/Adesin-fr/LaravelArtisanTest
PS : as I suspect, it seems to be artisan "mockery" : replacing the line
$artisan = $this->artisan("register:application");
withArtisan::call("register:application");
makes the test pass, but I can't interact with inputs...Beta Was this translation helpful? Give feedback.
All reactions