I recently discovered that you can test an artisan console command very easily in Laravel 8 with PHPUnit Tests and make assertions on the output. We need to create a console command using artisan. The console command expects a file location as an argument. It also has a confirm to ensure the user wants to run the command.
I recently discovered that you can test an artisan console command very easily in Laravel 8 and make assertions on the output. 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.
First we need to create a console command using artisan.
php artisan make:command ImportProducts
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.
The console command expects a file location as an argument. It also has a confirm to ensure the user wants to run the command. After each product is added it will output the message Imported and then the product code.
As a top **PHP Web Application Development Company in USA**[https://www.dataeximit.com/php-development-services/](https://www.dataeximit.com/php-development-services/ "https://www.dataeximit.com/php-development-services/"), we at Data EximIT have...
Skenix Infotech is a leading PHP Web Development Company that helps companies get results with industry best practices. Get affordable PHP Development Services.
Skenix Infotech is a top Laravel Website Development Company with Expert Laravel Developers that provides robust Laravel Development Services at fair costs.
Are you looking for a php web development company? ValueCoders is a leading software company with 16+ years of experience offering PHP website development services to global clients. 4200+ projects | 2500+ Clients| 450+ Experts.
Looking to hire affordable yet experienced PHP developers? **[Hire Dedicated PHP Developer](https://hourlydeveloper.io/hire-dedicated-php-developer/ "Hire Dedicated PHP Developer")**, who can convert your idea to reality, within the stipulated...