Eustáquio Rangel edited this page Aug 5, 2013 · 6 revisions

Previous: Scopes - Next: Log

Using factories for testing


Create a directory, say, factories, to store all your factories there. Then tell TORM where the factories are using



Then, on the dir, create .php files. They can have the name you want, but it's a good idea make them reflect your models, so, we can have a user.php file with the following contents:

    TORM\Factory::define("user",array("name"=>"Mary Doe","email"=>"mary@doe.com","level"=>1));

We just need the factory name where is mandatory that it reflects the class name (no problem if it's lower case) and then some data to use with the new object of the specified class.

Getting the attributes

To get the attributes of the example above, we can use

    $data = TORM\Factory::attributes_for("user");

Building a new (non-saved) object

To build a new and not saved object, we can use

    $user = TORM\Factory::build("user");

Creating and saving a new object

To create a new object and save a new record on the database specified by the connection, we can use

    $user = TORM\Factory::create("user");

Previous: Scopes - Next: Log

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.