{"id":22748812,"url":"https://github.com/apinstein/fixturenator","last_synced_at":"2025-04-14T12:05:58.536Z","repository":{"id":62486304,"uuid":"469334","full_name":"apinstein/fixturenator","owner":"apinstein","description":"A factory-based fixture generator for PHP.","archived":false,"fork":false,"pushed_at":"2017-12-28T00:28:08.000Z","size":16,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T12:05:53.324Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apinstein.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-01-12T20:13:35.000Z","updated_at":"2017-12-28T00:28:09.000Z","dependencies_parsed_at":"2022-11-02T10:02:12.028Z","dependency_job_id":null,"html_url":"https://github.com/apinstein/fixturenator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apinstein%2Ffixturenator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apinstein%2Ffixturenator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apinstein%2Ffixturenator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apinstein%2Ffixturenator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apinstein","download_url":"https://codeload.github.com/apinstein/fixturenator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877985,"owners_count":21176243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-11T03:35:33.180Z","updated_at":"2025-04-14T12:05:58.510Z","avatar_url":"https://github.com/apinstein.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Fixturenator\n============\n\nFixturenator is a factory-style test data generator inspired by [factory_girl][1], thoughtfully ported to PHP.\n\nDownload / Installation\n=======================\n\npear install apinstein.pearfarm.org/fixturenator\n\nrequire 'fixturenator/Fixturenator.php';\n\n[Source Code][2] available on GitHub.\n\nWhy Factories?\n==============\n\nThere are many patterns for preparing test data for running tests against, but in my experience they all have problems in terms of maintenance or ease of creation.\n\nThe factory pattern provides a DRY way to specify basic valid data for objects, and then to re-use that specification as a prototype for making similar objects. \n\nThe result is test data generation that doesn't break in 1000 places when you add a column to a model object, or change a validator. Fix the core factory definition and all your tests are working again!\n\nUsage\n=====\n\nEach factory is identified by a name, and some default data for the created objects.\n\n    // Static data for each instance        \n    Fixturenator::define('User', array('username' =\u003e 'joe'));\n    \n    // Closure-passing syntax on 5.3\n    Fixturenator::define('User', function($factory) {\n      $factory-\u003eusername = 'joe';\n    });\n    \n    // Closure-passing syntax on 5.2\n    Fixturenator::define('User', create_function('$factory', '\n      $factory-\u003eusername = 'joe';\n    '});\n\nIt is recommended for you to have one factory per class that provides the minimal valid data for that class. Additional factories can be created via inheritance to easily create common scenario data.\n\nFactory names must be unique.\n\n**Using Factories**\n\nThere are four main ways to create data based on factories:\n\n  * create - creates a new, unsaved instance\n  * saved - same as create, but calls the defined save method ('save' by default)\n  * stub - creates a MagicArray instance for easy stubbing functionality.\n  * asArray - a php array (hash) with all data values set by the factory\n\nExamples:\n\n    // Returns an unsaved User instance\n    $user = Fixturenator::create('User');\n    \n    // Customer the generated object\n    $user = Fixturenator::create('User', array('password' =\u003e '1234'));\n\n    // returns a \"saved\" User object, as if you called $user-\u003esave($dbCon)\n    $user = Fixturenator::saved('User', array(), $dbCon);\n\n**Dynamically Generated Attributes**\n\nYou might want to generate some data on the fly each time:\n\n    // the 'return ...' gets turned into a lambda; on 5.3 you can pass true lambda    \n    $user = Fixturenator::create('User', array('password' =\u003e 'return rand(1000,9999);'));\n    \n    // Generate one attribute based on others\n    $user = Fixturenator::create('User', array('email' =\u003e 'return \"{$o-\u003eusername}@domain.com\";'));\n\n**Sequences**\n\nSequences are very useful for generating unique and predictable data:\n\n    Fixturenator::createSequence('username', 'return \"username{$n}\";');\n    Fixturenator::getSequence('username')-\u003enext();    // =\u003e username1\n    Fixturenator::getSequence('username')-\u003enext();    // =\u003e username2\n\nYou can use these in your defines like so:\n\n    Fixturenator::define(TestObject, array(\n        'username' =\u003e new FixturenatorSequence('return \"username{$n}\";')\n    ));\n    Fixturenator::define(TestObject, array(\n        'username' =\u003e 'return Fixturenator::getSequence('username')-\u003enext()'\n    ));\n\n\nThanks\n======\n\nThanks to the factory_girl team for all the research and time that went in to figuring out the factory pattern and the great factory_girl implementation!\n\n\n  [1]: http://github.com/thoughtbot/factory_girl\n  [2]: http://github.com/apinstein/fixturenator\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapinstein%2Ffixturenator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapinstein%2Ffixturenator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapinstein%2Ffixturenator/lists"}