Code Monkey home page Code Monkey logo

phactory's Introduction

PHP data factory

Usage

Installation

Add voldern/phactory as a dev dependency using composer.

{
  "require-dev": {
    "voldern/phactory": "dev-master"
  }
}

Defining a factory

By default factories should recide in a folder named factories and the filename should be the same as the factory name.

Create a class extending \Phactory\Phactory and return the attributes configuration from a method named getFieldsConfig.

class InteractionFactory extends \Phactory\Phactory {
    protected function getFieldsConfig() {
        return array(
            'feedModuleId' => array(
                'type' => '\Phactory\Type\MongoId',
                'generator' => 'random'
             ),
            'type' => array(
                'type' => '\Phactory\Type\String',
                'generator' => 'static',
                'value' => 'interaction'
            ),
            'title' => array(
                'type' => '\Phactory\Type\String',
                'generator' => 'random',
                'values' => array('Tittelen', 'Dette er en tittel', 'Nyhetssak',
                    'VM 2013 Dag 1', 'EM 2012')
            ),
            'name' => array(
                'type' => '\Phactory\Type\String',
                'generator' => 'random',
                'values' => array('VM 2013', 'EM 2012', 'Navnet er langt', 'Dette er en test')
            ),
            'moderated' => array(
                'type' => '\Phactory\Type\Boolean',
                'generator' => 'static',
                'value' => false
            ),
            'permissions' => array(
                'type' => '\Phactory\Type\ArrayType',
                'generator' => 'static',
                'value' => array()
            ),
            'startDate' => array(
                'type' => '\Phactory\Type\DateTime',
                'generator' => 'static',
                'value' => 'now'
            ),
            'endDate' => array(
                'type' => '\Phactory\Type\DateTime',
                'generator' => 'random',
                'range' => array('min' => '+5 minutes', 'max' => '+20 minutes')
            ),
            'refreshRate' => array(
                'type' => '\Phactory\Type\Integer',
                'generator' => 'random',
                'range' => array('min' => 5, 'max' => 30)
            )
        );
    }
}

Running

Use the phactory CLI located in bin/ or vendor/bin/.

The currently supported commands are:

  • List factories: phactory phactory:list
  • Populate DB using factory: phactory phactory:populate [--dir=] [-f|--file=] [--host=] [-db|--database=] [-c|--cleanup] factory table [count]

License

"THE BEER-WARE LICENSE":

Copyright (C) 2013 Espen Volden

As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me one or more beers in return.

phactory's People

Stargazers

Thomas Krampl avatar

Watchers

Espen Volden avatar James Cloos avatar

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.