Giter Club home page Giter Club logo

yii-factory-girl's People

Contributors

ddinchev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

amashigeseiji

yii-factory-girl's Issues

Refactor the Sequence static utility.

The Sequence static utility was borrowed from kengos' FactoryGirl implementation but instead of static utility, values could be represented by value object that know their state or the Sequence at least could be instantiated per FactoryData.

Data files format propositions RFC

In the classical way of defining fixtures in Yii, data files return array of attribute arrays. While I don't like that approach as return in root of a PHP file:

  • is not well known feature of PHP
  • is considered bad coding practice
  • has non-idempotent behaviour in some cases

So I would suggest the following way of managing data files.

Data files by default go under protected\tests\factories, path that is configurable. Files have the format of TableNameFactory.php and contain a class named TableNameFactory. For example if we have table named Vehicles, we would create VehiclesFactory.php that contain Vehicles class. If we have user_profile table (singular, lowercase convention), we would have user_profileFactory.php that contains user_profileFactory class. Although the suffix is configurable param and can be changed to _factory to match user convention.

Those classes have simple interface like:

// FileName VehiclesFactory.php
class VehiclesFactory
{
    public static function getConfig()
    {
        return array(
            'class' => 'Vehicles', // -> new Vehicles, but if left black it's expected to have a model with TableName
            'attributes' => array(
                // this is default base configuration added to any newly created Vehicles factory, if no additional config was supplied
                'ModelID'  => 123, // $vehicle->ModelID = 123
                'UserID' => UsersFactory::create()->UserID
            ),
            'motorcylcle' => array(
                // this is alias that can be called with VehiclesFactory::create(array(), 'motorcycle') that would overwrite the default config with this config
                // of course you can supply attributes to overwrite the motorcycle alias config as well
                'ModelID' => 246, // motorcycle model
            )
        );
    }

    /**
     * @param array $attributes
     * @param null $alias
     * @return \Vehicles
     */
    public static function create(array $attributes = null, $alias = null) {
        return Yii::app()->factorygirl->create('Vehicles', $attributes, $alias);
    }
}

This is one possible solution where the config and create are static methods. But I think I could also define an abstract FactoryData class which the data classes (like VehiclesFactory) subclass.

Another one is to just return config directly as in fixtures and use YiiFactoryGirl like Yii::app()->factorygirl->create('Vehicles', $attr, $alias) but it kind'a sucks as you have to type hint anywhere you create a factory in your tests.

Any suggestions and questions are welcome.

Yii2 Support

Hey!

I admire your effort to put this all together. I would like to contribute to this library to add support for Yii2.
Any suggestion on where to start? Do you want to have backwards compatibility with Yii1? Should I create a new project called yii2-factory-girl or something?

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.