{"id":17959619,"url":"https://github.com/imjoehaines/flowder","last_synced_at":"2025-11-11T19:33:44.416Z","repository":{"id":20237287,"uuid":"84310419","full_name":"imjoehaines/flowder","owner":"imjoehaines","description":"A simple and extensible fixture loader for PHP 7.3+, supporting SQLite and MySQL","archived":false,"fork":false,"pushed_at":"2023-10-20T06:15:25.000Z","size":502,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T03:36:34.864Z","etag":null,"topics":["fixture-loading","fixtures","flowder","mysql","php","sqlite","testing"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imjoehaines.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-08T10:53:53.000Z","updated_at":"2021-01-17T07:50:02.000Z","dependencies_parsed_at":"2024-06-19T20:03:07.039Z","dependency_job_id":"356618df-baa7-459e-a825-b6b2b0d68d71","html_url":"https://github.com/imjoehaines/flowder","commit_stats":{"total_commits":248,"total_committers":2,"mean_commits":124.0,"dds":0.342741935483871,"last_synced_commit":"a922b2e21ba1c07403ffc90cb4eaf623bc31ba2c"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imjoehaines%2Fflowder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imjoehaines%2Fflowder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imjoehaines%2Fflowder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imjoehaines%2Fflowder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imjoehaines","download_url":"https://codeload.github.com/imjoehaines/flowder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245394650,"owners_count":20608116,"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":["fixture-loading","fixtures","flowder","mysql","php","sqlite","testing"],"created_at":"2024-10-29T11:03:51.607Z","updated_at":"2025-11-11T19:33:39.388Z","avatar_url":"https://github.com/imjoehaines.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flowder [![Latest Stable Version](https://poser.pugx.org/imjoehaines/flowder/v/stable)](https://packagist.org/packages/imjoehaines/flowder)\n\nFlowder is a (really) simple fixture loader for PHP 7.3+, supporting SQLite and MySQL.\n\n_Using Flowder in PHP 7.2 or below? Try [version 1](https://packagist.org/packages/imjoehaines/flowder#v1.0.0) instead!_\n\n**NB:** If you're looking to use Flowder in a project, you probably want to use an exisiting framework integration:\n\n- [Flowder PHPUnit](https://github.com/imjoehaines/flowder-phpunit) — A Flowder test listener for PHPUnit\n- [Flowdception](https://github.com/imjoehaines/flowdception) — A Flowder Extension for Codception\n\n## Basic Concepts\n\nFlowder is built with three basic building blocks; [Loaders](#loaders), [Truncators](#truncators) and [Persisters](#persisters).\n\nA Loader is responsible for taking a thing to load (such as a file or directory) and converting it into an array of data that can be persisted.\n\nA Truncator is responsible for ensuring all the database tables where data will be persisted are empty before persisting the data.\n\nA Persister is responsible for taking the data provided by a Loader and inserting it into the database.\n\nThese three concepts are represented by the following interfaces:\n\n- [`Imjoehaines\\Flowder\\Loader\\LoaderInterface`](src/Loader/LoaderInterface.php)\n- [`Imjoehaines\\Flowder\\Truncator\\TruncatorInterface`](src/Truncator/TruncatorInterface.php)\n- [`Imjoehaines\\Flowder\\Persister\\PersisterInterface`](src/Persister/PersisterInterface.php)\n\nBuilding your own Loaders, Truncators and Persisters is as easy as creating a class that implements ones of these interfaces.\n\n## Usage\n\nLoading fixtures with Flowder takes a few lines of code \u0026mdash; it just requires a Loader, Truncator and Persister.\n\nFor example, to load a single PHP file into a SQLite in-memory database, the following file could be used\n\n```php\n$db = new PDO('sqlite::memory:');\n\n$flowder = new Imjoehaines\\Flowder\\Flowder(\n    new Imjoehaines\\Flowder\\Loader\\PhpFileLoader(),\n    new Imjoehaines\\Flowder\\Truncator\\SqliteTruncator($db),\n    new Imjoehaines\\Flowder\\Persister\\SqlitePersister($db)\n);\n\n$flowder-\u003eloadFixtures('test_data.php');\n```\n\n## Provided Classes\n\n#### Flowder\n\n`Flowder` is the main class you will be using. It is responsible for orchestrating the loading, truncating and persisting processes.\n\nAs seen in the example above, it is constructed with three arguments \u0026mdash; an instance of `LoaderInterface`, an instance of `TruncatorInterface` and an instance of `PersisterInterface`.\n\nAfter construction, call `loadFixtures` and pass it a thing to load in order to persist the data. For example, using the `PhpFileLoader` you would pass `loadFixtures` the path to a PHP file.\n\n### Loaders\n\nFlowder comes bundled with three Loaders:\n\n#### PhpFileLoader\n\nThis Loader takes a PHP file name, `require`s it and uses a returned array of data as the data to be persisted. The file name itself is used as the table name (ignoring the file extension).\n\nFor example, given the following `example_table.php` file\n\n```php\nreturn [\n    [\n        'column1' =\u003e 1,\n        'column2' =\u003e 2,\n    ],\n    [\n        'column1' =\u003e 4,\n        'column2' =\u003e 5,\n    ],\n];\n```\n\nThen when loaded with the `PhpFileLoader`, it would return the following PHP array\n\n```php\n[\n    'example_table' =\u003e [\n        [\n            'column1' =\u003e 1,\n            'column2' =\u003e 2,\n        ],\n        [\n            'column1' =\u003e 4,\n            'column2' =\u003e 5,\n        ],\n    ],\n]\n```\n\n#### DirectoryLoader\n\nThe `DirectoryLoader` is a decorator around another Loader instance that will run the Loader's `load` method for each file in the directory provided to `DirectoryLoader::load`.\n\nFor example, the following code will load all files in `/some/directory` using the `PhpFileLoader`\n\n```php\n$loader = new DirectoryLoader(\n    new PhpFileLoader()\n);\n\n$data = $loader-\u003eload('/some/directory');\n```\n\n#### CachingLoader\n\nThe `CachingLoader` is another decorator that caches the result of it's `load` method so that repeated calls to load the same thing will return the same result as it did on the first call to `load`.\n\nExtending the above example, we can use the following code to load all files in `/some/directory` using the `PhpFileLoader`, but only actually hit the disk on the first time through the `for` loop. All other iterations will simply return the cached value\n\n```php\n$loader = new CachingLoader(\n    new DirectoryLoader(\n        new PhpFileLoader()\n    )\n);\n\nfor ($i = 0; $i \u003c 100; $i++) {\n    $data = $loader-\u003eload('/some/directory');\n}\n```\n\nIt is usually a good idea to use the CachingLoader whenever you are loading the same resource more than once as it can dramatically speed up fixture loading.\n\n#### Additional Loaders\n\nFor loading file formats other than PHP, take a look at the JSON or YAML loaders:\n\n- [JSON Loader](https://github.com/imjoehaines/flowder-json-loader)\n- [YAML Loader](https://github.com/imjoehaines/flowder-yaml-loader)\n\n### Truncators\n\nFlowder comes with two Truncator classes:\n\n#### MySqlTruncator\n\nThis Truncator takes a table name and runs a MySQL `TRUNCATE TABLE` query on it. It will disable foreign key checks before the truncate and enable them afterwards, to ensure ordering of truncation does not matter. It is your responsibility to make sure this does not leave your database in an inconsistent state after all of your fixtures run.\n\n#### SqliteTruncator\n\nThis Truncator takes a table name and runs a `DELETE FROM` query on it. Like the `MySqlTruncator`, it will disable foreign key checks before the truncate and enable them afterwards.\n\n### Persisters\n\n#### MySqlPersister\n\nThe `MySqlPersister` takes a table name and array of data and converts it into a single `INSERT` query. Like the `MySqlTruncator` it will disable foreign key checks before the insert and enable them afterwards to ensure the ordering of inserts does not matter. It is your responsibility to make sure this does not leave your database in an inconsistent state after all of your fixtures run.\n\n#### SqlitePersister\n\nThe `SqlitePersister` is functionally identical to the `MySqlPersister`, but inserts data a row at a time inside a transaction instead of building a single `INSERT` query. This is to get around SQLite's [`SQLITE_MAX_VARIABLE_NUMBER`](https://www.sqlite.org/lang_expr.html#varparam) limitation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimjoehaines%2Fflowder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimjoehaines%2Fflowder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimjoehaines%2Fflowder/lists"}