2017 © Pedro Peláez
 

library phactory

PHP data factory

image

voldern/phactory

PHP data factory

  • Monday, April 29, 2013
  • by voldern
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHP data factory

Usage

Installation

Add voldern/phactory as a dev dependency using composer., (*1)

{
  "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., (*2)

Create a class extending \Phactory\Phactory and return the attributes configuration from a method named getFieldsConfig., (*3)

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/., (*4)

The currently supported commands are:, (*5)

  • 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":, (*6)

Copyright (C) 2013 Espen Volden, (*7)

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., (*8)

The Versions

29/04 2013

dev-master

9999999-dev https://github.com/voldern/phactory

PHP data factory

  Sources   Download

BEER-WARE

The Requires

 

by Espen Volden