Giter Club home page Giter Club logo

haigha's Introduction

Tip

Haigha has been superseeded by the brand new Hatter - similar features, still application independant, but no longer trying to use Alice in a way that it wasn't designed for.

Haigha: Alice fixtures for tables

Alice is an awesome database fixtures library. It works with Doctrine out-of-the-box, but if you don't use the Doctrine ORM, you'll need custom persisters...

This is where Haigha comes in:

Haigha lets you use Alice directly with database tables!

Features

  • Supports all standard Alice functionality (ranges, optional data, references, inheritence, etc)
  • Supports Faker data providers
  • Supports any PDO connection
  • No need to write classes, directly persist from yml to your sql database

Example fixture file

Haigha uses Alice to load fixture files, so the format is identical (Details). The only thing to keep in mind is that you use tablenames instead of classnames. Prefix your tablenames with table.. For example, if your tablename is called user, you use it like this:

table.group:
  group_random_users:
    id: 1 # This is important for version ~2.0
    name: Random users

table.user:
  random_user{0..9}:
    group_id: @group_random_users
    username: <userName()>
    firstname: <firstName()>
    lastname: <lastName()>
    password: <password()>
    email: <email()>

How to use Haigha in your application

Simply add the following to your require or require-dev section in your composer.json and run composer update:

"require": {
  "linkorb/haigha": "^2.0"
}

You can now use Haigha in your applications, or use the included command-line tool to load fixtures into your database:

Command-line usage

The haigha command-line tool knows one sub-command: fixtures:load.

The first argument is the filename of your fixture definition (yaml).

The second argument is the (optional) database url. If no database url is specified, haigha used your PDO environment variable instead.

Database URL

A full URL containing username, password, hostname and dbname. For example:

./vendor/bin/haigha fixtures:load examples/random_users.yml mysql://username:password@hostname/dbname

Just a dbname

In this case linkorb/database-manager is used for loading database connection details (server, username, password, etc) from .conf files (read project readme for more details).

In a nutshell - you must have a database_name.conf file at /share/config/database/ as described at database-manager's documentation.

./vendor/bin/haigha fixtures:load examples/random_users.yml dbname

Library usage:

You can use Haigha in your own application like this:

// Instantiate a new Alice loader
$loader = new Nelmio\Alice\Fixtures\Loader();

// Add the Haigha instantiator
$instantiator = new Haigha\TableRecordInstantiator();
$loader->addInstantiator($instantiator);

// Load (Haigha) objects from a Alice yml file
$objects = $loader->load('examples/random_users.yml');

// Instantiate the Haigha PDO persister, and pass a PDO connection
$persister = new PdoPersister($pdo);

// Persist the Haigha objects on the PDO connection
$persister->persist($objects);

Test

Customize phpunit.xml:

cp phpunit.xml.dist phpunit.xml

Run:

vendor/bin/phpunit

License

MIT (see LICENSE.md)

Brought to you by the LinkORB Engineering team


Check out our other projects at linkorb.com/engineering.

Btw, we're hiring!

haigha's People

Contributors

h-wang avatar igormukhingmailcom avatar joostfaassen avatar pakulin-dev avatar prajapati-kaushik avatar seldaek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

haigha's Issues

Handling of many to many relationships

What's the best way to handle m:n bindings? I tried something like:

table.object:
    object:
        other_ids: [1,2,3]

Which ideally would create the object first then write ($objectId,1), ($objectId, 2), ($objectId, 3) into the join table object_other. I hope it makes sense.

I guess an option would be to do:

table.object_other:
    relation_1:
        object_id: 1
        other_id: 1
    relation_2:
        object_id: 1
        other_id: 2
    relation_3:
        object_id: 1
        other_id: 3

But that's obviously a lot more verbose.. I might be able to generate it on the fly by extending the TableRecordInstantiator but I thought I'd check with you first.

Symfony requirements

Hey, thanks for the quick merge, but now I noticed I can't update to latest as it requires symfony4. Given the usage you make of console and dotenv, I'd imagine a require on both of these of "^3.4 || ^4.3 || ^5.0" would probably work (and includes only the still-maintained releases). I haven't checked, but unless you are aware of a reason not to do this, it'd be nice to relax the constraint a bit.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.