This package is a simple wrapper for adding some L4 goodness to the existing codesleeve\fixture package that can be found here. I strongly encourage you to read over the documentation in that package, it goes in much more detail than I currently provide here. This package is pretty much just a Facade registration and some object bootstrapping via service provider.
Step 1 - Fixture setup
Inside your application test folder, create a folder named fixtures. Next, create a couple of fixture files inside this folder. Fixture files are written using native php array syntax. To create one, simply create a new file named after the table that the fixture corresponds to and have it return an array of data. As an example of this, let's create some fixture data for a hypothetical authentication system. In this system, we let's assume that we have both roles and users and that a user belongsToManyRoles (we're assumign the existance of a roles_users join table). To insert some user fixture data into our database, all we need to do is create a couple of fixture files:
For each of these fixture files we're simple returning a nested array containing our fixture data. Also, notice that each fixture record has a unique name; This is very important! Because each fixture has a unique name, we can easily populate our 'roles_users' join table simply by referencing the relationship in the users fixture and passing in a comma separated list of roles we want that user to have (note that we are assuming a belongsToMany relationship named 'roles' exists on the User model). We can also easily populate hasOne, hasMany, and belongsTo relationships in our fixtures as well. To show this, let's go ahead and extend our example authentications system to include the concept of profiles. We'll assume the existence of a profiles table and assume that a profile belongs to a user and that a user has one profile:
Notice that once again we simpley reference the name of the relationship ('user' in this case) inside the fixture. No need to add a 'user_id' field; Fixture is smart enough to look up the relationship ('belongsTo') via the user column and populate it with the correct foreign key value. No need to worry about juggling foreign keys, no need to worry about the order in which records are created.
Step 2 - Invoke Fixture::up() and Fixture::down() inside your tests.
Now that our fixtures have been created, all we need to do in order to load them into our database is to invoke the Fixture::up() method within our tests. Before this can happen though we need to make sure that the database tables themselves have been created (don't worry about seeding). Regardless of how your test database is configured (mysql, sqlite, sqlite in memory, etc) you're going to need to run migrations (at least once) in order to initialize your test database with tables. If you're using mysql, postresql, or sqlite, simple make a call to laravel's migrate command from the command line before running your tests. However, if you're running an in memory sqlite database (which you probably should be), you're going to need to do this right before your tests start running. One way of accomplishing this is to tap into the createApplication method of the base TestCase supplied with Laravel: