{"id":15008328,"url":"https://github.com/icanhazstring/phpunit-faker-extension","last_synced_at":"2025-04-09T16:04:06.792Z","repository":{"id":56988479,"uuid":"167526333","full_name":"icanhazstring/phpunit-faker-extension","owner":"icanhazstring","description":"Extension to add fzaninotto/Faker into phpunit","archived":false,"fork":false,"pushed_at":"2019-01-25T15:59:52.000Z","size":16,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T16:03:13.780Z","etag":null,"topics":["extension","faker","phpunit","testing"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/icanhazstring.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}},"created_at":"2019-01-25T10:01:55.000Z","updated_at":"2023-02-23T07:51:21.000Z","dependencies_parsed_at":"2022-08-21T12:50:29.564Z","dependency_job_id":null,"html_url":"https://github.com/icanhazstring/phpunit-faker-extension","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icanhazstring%2Fphpunit-faker-extension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icanhazstring%2Fphpunit-faker-extension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icanhazstring%2Fphpunit-faker-extension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icanhazstring%2Fphpunit-faker-extension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icanhazstring","download_url":"https://codeload.github.com/icanhazstring/phpunit-faker-extension/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065290,"owners_count":21041871,"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":["extension","faker","phpunit","testing"],"created_at":"2024-09-24T19:17:39.293Z","updated_at":"2025-04-09T16:04:06.754Z","avatar_url":"https://github.com/icanhazstring.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phpunit-faker-extension\n\n![Build](https://img.shields.io/travis/com/icanhazstring/phpunit-faker-extension/master.svg)\n![Min php version](https://img.shields.io/badge/php-%5E7.1-lightgrey.svg)\n![Min phpunit version](https://img.shields.io/badge/phpunit%2Fphpunit-%5E7.5-lightgrey.svg)\n\nUsing this extension you can use [fzaninotto/faker](https://github.com/fzaninotto/faker) with your phpunit tests. \nEvery test will be seeded so you will be able run the same test again if an error occurs.\n\n![phpunit-faker-extension-screenshot](https://i.imgur.com/5aYU9hJ.png)\n\n## Installation\n\nYou can install this extension by using [Composer](http://getcomposer.org). This package should be added as a `require-dev` dependency:\n\n    composer require --dev icanhazstring/phpunit-faker-extension\n\n\n## Usage\n\nEnable with all defaults by adding the following code to your project's `phpunit.xml` file:\n\n```xml\n\u003cphpunit bootstrap=\"vendor/autoload.php\"\u003e\n...\n    \u003clisteners\u003e\n        \u003clistener class=\"PHPUnitFaker\\FakerTestListener\" /\u003e\n    \u003c/listeners\u003e\n\u003c/phpunit\u003e\n```\n\nNow run the test suite as normal. As soon as all tests are completed, \nyou will see a seed that was used to generate the faker data:\n\n`Tests done with seed: XXX`\n\n### Using Fake inside a test\n\nTo use faker inside your tests, you will need to implement the `FakerAwareTest` interface and the `FakerTrait`.\nSince not all tests will need faker, the interface makes sure only tests using faker, will get the needed data.\n\nTo actually invoke you only need to do the following:\n\n```php\nclass AwesomeTest extends TestCase implements FakerAwareTest\n{\n    use FakerTrait;\n    \n    public function testAwesomeStuff(): void\n    {\n        $this-\u003eassertSame($this-\u003efake()-\u003ename, $this-\u003efake()-\u003ename);\n    }\n}\n```\n\u003e See faker documentation for more information about formatters: https://github.com/fzaninotto/faker#formatters\n\n### Running tests with a given seed\n\nTo run tests with a given seed, simple set the `PHPUNIT_SEED` environment variable before running phpunit:\n\n```bash\n$ PHPUNIT_SEED=XXX vendor/bin/phpunit\n```\n\n## Configuration\n\nThis extension has three configurable parameters:\n- **locale** - The locale that faker should use (Default: `en_GB`)\n- **fakerProviderProvider** - (Silly name I know) A single invokable class returning a list of providers (string or instance)\n\nThese configuration parameters are set in `phpunit.xml` when adding the listener:\n\n```xml\n\u003cphpunit bootstrap=\"vendor/autoload.php\"\u003e\n    \u003c!-- ... other suite configuration here ... --\u003e\n\n    \u003clisteners\u003e\n        \u003clistener class=\"PHPUnitFaker\\FakerTestListener\"\u003e\n            \u003carguments\u003e\n                \u003carray\u003e\n                    \u003celement key=\"locale\"\u003e\n                        \u003cstring\u003ede_DE\u003c/string\u003e\n                    \u003c/element\u003e\n                    \u003celement key=\"fakerProviderProvider\"\u003e\n                        \u003cstring\u003eYour\\FakerProviderProvider\u003c/string\u003e\n                    \u003c/element\u003e\n                \u003c/array\u003e\n            \u003c/arguments\u003e\n        \u003c/listener\u003e\n    \u003c/listeners\u003e\n\u003c/phpunit\u003e\n```\n\n## License\n\nphpunit-faker-extension is available under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficanhazstring%2Fphpunit-faker-extension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficanhazstring%2Fphpunit-faker-extension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficanhazstring%2Fphpunit-faker-extension/lists"}