In this example we are going to make a console command to import some products into our database from a csv file and then test they are all added as expected.
In this newly created class, we are going to use the Spatie Simple Excel package to read the csv file and then import the products. We are going to use the product_code as the unique identifier and we are going to update or create the product name and description.
To run the console command manually we can run the following: Next we can create a test using artisan.
Now we have tested without a file and cancelling the command, we can test running the command from start to finish and ensure that it outputs all the messages we expect to see and returns the correct exit code.