Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Laravel News:
Introduction to Seeding Data in Testing
Apr 10, 2017 @ 15:42:26

On the Laravel News site they've posted an introduction to seeding data in testing to help make your Laravel application testing easier and see "more correct" results.

Since seeding was released in Laravel 5.1, testing has become easier and quicker.

You can have ten users with each having a post or 1000 users with one or more posts inserted before the testing begins. In this tutorial, you will create a test case to test the user model and a seeder to seed ten users, and each is following one user into the database.

The tutorial starts with a migration to create a "users" table including a "follow user ID" field that tracks which user another is following. Next up is the creation of the User model with the methods to create the "follow" links between users. The make:seeder command is then used with this model to generate the seeder class and make 10 users with faked information. The db:seed command is used to execute the seeder and populate the data. Finally an example test case is created, first just testing that 10 users were created then refactored to test links between the users and the follow/unfollow functionality.

tagged: laravel seed data testing migration tutorial unittest model

Link: https://laravel-news.com/seeding-data-testing


Trending Topics: