Download the PHP package codesleeve/fixture without Composer

On this page you can find all versions of the php package codesleeve/fixture. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package fixture

Fixture

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

A framework agnostic, simple (yet elegant) fixture library for php.

Fixture was created by Travis Bennett.

Requirements

Installation

Fixture is distributed as a composer package, which is how it should be used in your app.

Install the package using Composer. Edit your project's composer.json file to require codesleeve/fixture.

Overview

In order to create good tests for database specific application logic, it's often necessary to seed a test database with dummy data before tests are ran. This package allows you to achieve this through the use of database fixtures (fixtures are just another way of saying 'test data'). Fixtures can be created using native php array syntax and are not dependendent on any specific relational DBMS. In a nutshell, this package allows you to turn this:

into this:

Drivers

Fixture currently supports two drivers:

Setup

In order to use fixture, you're going to first need to initialize it. A good place to do this is inside your bootstrap file (configured via your phpunit.xml), but you're certainly welcome to do this where it makes the most sense for you:

Examples

For our examples, let's assume that we have the following bleach-themed system:

Standard Driver

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 our 'soul_reapers' table:

in tests/fixtures/soul_reapers.php

Here we're simple returning a nested array containing our fixture data. Notice that there are two fixtures and that they each have a unique name (this is very important as you'll see shortly we can easily reference loaded fixture data from within our tests). Now, we can't have soul reapers without zanpakutos, so let's seed our zanpakutos table with the following fixture:

in tests/fixtures/zanpakutos.php

Because a zanpakuto must belong to a soul reaper (it's part of their soul after all) we know that our 'zanpakutos' table will contain a column named 'soul_reaper_id'. In order to tie a zanpakuto to it's owner, we can simply set this foreign key to the name of the corresponding soul reaper it belongs to. There's no need to worry about specific id's, insertion order, etc. It's pretty simple. Moving forward, we've so far been able to easily express our parent/child (1 to 1) relationship between 'soul_reapers' and 'zanpakutos', but what about many to many (join table) relationships? As an example of how this might work, let's look at two more tables; 'ranks' and 'ranks_soul_reapers'. Our ranks table fixture will look like this:

in tests/fixtures/ranks.php

The 'ranks_soul_reapers' (many to many) join table fixture will look like this:

in tests/fixtures/ranks_soul_reapers.php

Notice that we have both a 'CommanderYammamoto' and a 'CaptainYammamoto' entry inside our ranks_soul_reapers join table; That's because Genryusai Yammamoto was the Captain Commander (he had both the commander role and was also captain level as well) of the Gotei 13.

Step 2 - Initialize an instance of the fixture class.

Now that the fixture files have been created, the next step is to create an instance of the fixture library inside of our tests. Consider the following test (we're using PHPUnit here, but the testing framework doesn't matter; SimpleTest would work just as well):

in tests/exampleTest.php

What's going on here? A few things:

As an aded benefit, seeded database records can be accessed (if needed) as php standard objects directly from the fixture object itself:

Eloquent Driver

Step 1 - Model setup

Inside your models folder (or wherever you currently store your models at), create both a SoulReaper and a Zanpakuto model:

Step 2 - 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 we did with our previous example, let's create some fixture data for our soule reapers system:

in tests/fixtures/soul_reapers.php

in tests/fixtures/zanpakutos.php

in tests/fixtures/ranks.php

In each of our files, we're simple returning a nested array containing our fixture data. In this array, we create records (using array syntax) to populate our database tables.

Because we know that a Zanpakto has a 'belongsTo' relationship with a SoulReaper, we can now use this relationship to easily create foreign keys for our fixture data. There's no need to worry about specific id's, insertion order, etc. All we need to do is assign the relationship a value (from the belongsTo side) within the fixture and it will be populated automatically. It's very simple:

Many to many (N to N) join table relationships can also be populated. In our running example, soul reapers have a many to many (belongsToMany) relationship with ranks. In essence, a soul reaper can have many ranks and ranks can belong to many soul reapers (notice that Genryusai has both 'Commander' and 'Captain' ranks; that's because Genryusai Yammamoto was the Captain Commander of the Gotei 13). To represent this, we simply assign an array to a value that's named after the belongsToMany relationship of the fixture's corresponding model. In our example, from the soul reapers side (of the belongsToMany relationship), we simple pass an array of 'ranks' (since we defined a belongsToMany relationship named 'ranks' inside our SoulReaper model) we want a soul reaper to have. Extra columns on the join table can be populated using a '|' delimiter with key/values separated with a ':'.

Step 3 - Initialize an instance of the fixture class.

Now that the fixture files have been created, the next step is to create an instance of the fixture library inside of our tests. Consider the following test (we're using PHPUnit here, but the testing framework doesn't matter; SimpleTest would work just as well):

in tests/exampleTest.php

Faking Data

Fixture has built in integration with Faker. Creating fake fixture data is a breeze:

By using fixtures to seed our test database we've gained very precise control over what's in our database at any given time during an integration test. This in turn allows us to very easily test the pieces of our application that contain database specific logic.

Contributing

Fixture is always open to contributions from the community, however I ask that you please make all pull request to the development branch only. Let me reiterate this; I will not be accepting pull requests on master.


All versions of fixture with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
fzaninotto/faker Version 1.3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package codesleeve/fixture contains the following files

Loading the files please wait ....