2017 © Pedro PelĂĄez
 

library phactory

A PHP library for generating data for tests

image

alanwillms/phactory

A PHP library for generating data for tests

  • Sunday, November 2, 2014
  • by alanwillms
  • Repository
  • 1 Watchers
  • 0 Stars
  • 88 Installations
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Phactory

(ver documentação em portuguĂȘs), (*1)

A PHP library for creating data for tests. Designed for simplicity and extensibility., (*2)

Usage

Define factories like so:, (*3)

<?php

class UserPhactory
{
    public function blueprint()
    {
        return array(
            'name' => 'User #{sn}',
            'activated' => true,
        );
    }

    public function admin()
    {
        return array(
            'isadmin' => true,
        );
    }
}

Then use them:, (*4)

<?php

$user = Phactory::user();

echo $user->name; // 'User 0001'
echo $user->activated ? 'true' : 'false'; // 'true'

$admin = Phactory::user('admin');

echo $user->name; // 'User 0002'
echo $user->activated ? 'true' : 'false'; // 'true'
echo $user->isadmin ? 'true' : 'false'; // 'true'

That's just the basics of what Phactory allows you to do, fixtures, dependencies and relationships are also supported, read the wiki documentation for more information., (*5)

What it doesn't do

Phactory doesn't know about your database or ORM, this is by design. Rather than trying to support every ORM out there Phactory is designed to be easily extended to support whatever it needs to. e.g. using our above UserPhactory, (*6)

<?php

class User {}

class MyCustomBuilder extends \Phactory\Builder
{
    protected function toObject($name, $values)
    {
        $object = new $name;

        foreach ($values as $key => $value) {
            $object->$key = $value;
        }

        return $object;
    }
}

Phactory::builder(new MyCustomBuilder);

$user = Phactory::user();

echo get_class($user); // 'User'

Status

Up to v1.1.4, (*7)

Build Status, (*8)

Installing

Via composer:, (*9)

{
  "require-dev": {
    "rbone/phactory": "1.1.*"
  }
}

Via GIT:, (*10)

git clone git://github.com/rbone/phactory.git

<?php

require 'phactory/bootstrap.php';

The Versions

02/11 2014

dev-8-fix-dependencies-with-null-values

dev-8-fix-dependencies-with-null-values https://github.com/rbone/phactory

A PHP library for generating data for tests

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Richard Bone
by Alan Willms

test data

08/09 2014

dev-5-scenarios

dev-5-scenarios https://github.com/rbone/phactory

A PHP library for generating data for tests

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Richard Bone
by Alan Willms

test data

27/08 2014

dev-master

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

A PHP library for generating data for tests

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Richard Bone
by Alan Willms

test data

31/05 2013

1.1.4

1.1.4.0 https://github.com/rbone/phactory

A PHP library for generating data for tests

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Richard Bone

test data

31/05 2013

dev-features/improved_dependency_error_messages

dev-features/improved_dependency_error_messages https://github.com/rbone/phactory

A PHP library for generating data for tests

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Richard Bone

test data

28/05 2013

1.1.3

1.1.3.0 https://github.com/rbone/phactory

A PHP library for generating data for tests

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Richard Bone

test data

23/05 2013

1.1.2

1.1.2.0 https://github.com/rbone/phactory

A PHP library for generating data for tests

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Richard Bone

test data