Download the PHP package derptest/phpmachinist without Composer
On this page you can find all versions of the php package derptest/phpmachinist. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package phpmachinist
PHPMachinist: Testing Object Factory
What???!??!
A Slightly less annoying way of creating database fixtures for PHP testing. It borrows heavily from several projects:
- https://github.com/chriskite/phactory
- https://github.com/thoughtbot/factory_girl
- https://github.com/ccollins/milkman
- https://github.com/notahat/machinist
They're totally awesome. Just either in the wrong language, or didn't quite do what I wanted.
Hip Hop VM (HHVM) Support
Hip Hop VM is supported and tested. If you want to use the Doctrine store, it will require Doctrine ORM 2.4.x or newer.
Data Store Support
The following data stores are currently supported:
- PDO
- MySQL
- SQLite
- Doctrine 2 ORM
Install
Add the package derptest/phpmachinist to your composer.json For more information about Composer, please visit http://getcomposer.org
Configure
Configuration of PHP Machinist happens in two steps:
-
Register data stores
Registering data stores is done via either the static
Machinist::store()
method or theaddStore()
method on a Machinist instance. Both methods take the same parameters, aStoreInterface
instance and an optional name for that store. If no name is given, it will default todefault
. Below is an example of both:Note: when using the pdo error mode will be set. It will default to exception such that a test that triggers an error will throw an exception and fail. This default behavior can be overridden by passing an error mode as the second parameter of the factory method.
-
Define Blueprints
Blueprints are what define the entities in your data store by allowing you to configure the following:
- The
StoreInterface
to use when saving or retrieving data for the blueprint - The table/collection in which the data will be stored
- The default values for columns/properties in the table/collection. Default values allow you to only deal with the data that is truly important to your test logic and not waste time and clutter your test code with setting values that are meaningless but required by your data store
- The relationships between the blueprint and other previously defined blueprints
Multiple blueprints may be defined for the same table/collection. This allows you to quickly set up use multiple sets of default values for your data. The below example shows the creation of two blueprints for a user table with different roles. Defining multiple blueprints makes your tests more readable not to mention faster to write.
- The
Relationships in depth
Relationships are quite possibly the strongest feature of PHP Machinist. They allow you to quickly associate related data without having to worry about primary keys, foreign keys, and all that other nonsense in your actual tests. They will even do some "find or create" magic for you. Here is how you use the Blueprints from the example above to create two users and one company really quickly.
That's the fill sum of the code needed to create two users and one company. PHP Machinist did some magic on the first
blueprint make call. It looked for a company with the name
of Pedro for Class President
. It didn't find one, so
it created a company and used that for the relationship. For the second make()
call, it found the company created in
the first call and used that company for the relationship.
Relationships will also populate data from data finds as well. Here is an example using the same blueprints and the data created from the previous example.
This will result in Pedro for Class President
being shown on the screen.
License
See LICENSE file in the project