Giter VIP home page Giter VIP logo

factory_lib's Introduction

FactoryLib
==========

This is a simple data factory class - for generating rows in a database or 
associative arrays of data, normally used in testing. To use it include 
factory_lib.php and then define your tables. The database connection is 
the basic mysql_* functions.

include dirname(__FILE__) . "/factory_lib.php" ;

Factory::$factory_data['my_table_name'] = array('forename' => 'Jeremy', 
												'surname' => Wilkins, 'age' => 32) ;

This will define the default data - you can create a row in the database
with this data by doing

Factory::create('my_table_name') ;

and just get an array of data using

Factory::hash('my_table_name') ;

Either of these take a second parameter of overriding data, and fields
not set will use the defaults, eg

Factory::create('my_table_name', array('age' => 21)) ;

You can also include the magic value {{counter}} in strings for creating
multiple rows, each with unique data - eg.

Factory::$factory_data['testing'] => array('name' => 'Test User {{counter}}')
for($i = 0; $i < 5; $i++)
	Factory::create('testing') ;

Will create 5 rows, with names Test User 1 to Test User 5.

You can also use UNIX_TIMESTAMP() and NOW() as magic string values - these 
will get passed through to mysql automatically rather than being escaped and
inserted as text.

Factory::truncate('my_table_name') will trunctate the named table (good for 
the setUp() function in unit tests).

factory_lib's People

Contributors

jebw avatar

Stargazers

 avatar

Watchers

 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.