{"id":18832633,"url":"https://github.com/datto/phpunit-entropy","last_synced_at":"2025-09-04T06:42:44.069Z","repository":{"id":56963096,"uuid":"90173857","full_name":"datto/phpunit-entropy","owner":"datto","description":"A PHPUnit plugin to aid randomized unit testing","archived":false,"fork":false,"pushed_at":"2018-01-04T16:27:52.000Z","size":18,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-08-25T13:48:36.161Z","etag":null,"topics":["php","phpunit"],"latest_commit_sha":null,"homepage":"","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/datto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-03T17:10:29.000Z","updated_at":"2023-12-24T17:48:13.000Z","dependencies_parsed_at":"2022-08-21T08:20:53.221Z","dependency_job_id":null,"html_url":"https://github.com/datto/phpunit-entropy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/datto/phpunit-entropy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datto%2Fphpunit-entropy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datto%2Fphpunit-entropy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datto%2Fphpunit-entropy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datto%2Fphpunit-entropy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/datto","download_url":"https://codeload.github.com/datto/phpunit-entropy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/datto%2Fphpunit-entropy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273567329,"owners_count":25128630,"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","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["php","phpunit"],"created_at":"2024-11-08T01:58:34.501Z","updated_at":"2025-09-04T06:42:44.045Z","avatar_url":"https://github.com/datto.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Datto PHPUnit Entropy\n\nEntropy is a library to provide tools for working with randomized testing in\nPHPUnit as well as for testing systems that make use of PHP's random functions\nsuch as `rand` and `shuffle`.\n\n## Use cases\n\n### Detect dependent tests\n\nSometimes unit tests require changes to global state, or cover functionality\nthat alters that state. While this is never an ideal situation, this can often\nresult in the creation of inadvertent dependencies on other tests.\n \nEnabling Entropy's test shuffling functionality randomizes the order of your\ntests, helping to highlight these dependencies.\n\nEntropy's test-shuffling also avoids changing the order of tests using the\n`@depends` functionality of PHPUnit; future work will work to ensure that\nshuffling can still occur for these tests when appropriate.\n\n### Randomized testing\n\nSometimes you can find yourself in a situation where the range of inputs for a\nfunction is so large that taking a cross-section of those inputs is a more\nefficient use of your resources. But what happens if that cross-section has\nholes where your tests might fail?\n\nOne way to get around this is to use randomized inputs, where input is\ngenerated in such a way as to get a random cross-section of the ranges. In\nother words, using `rand` or another such non-deterministic approach.\n\nAn extension of this, property-based testing is the practice of applying random\ninput to your application or function, and observing that the output adheres to\ncertain rules or has certain properties relative to the input, rather than\nprecise testing of equality to a known result set.\n\nBy managing the random seed for your tests, Entropy allows not only the use of\nthese approaches, but also to make them repeatable, either by accepting a fixed\nseed or recovering it from the last failed run until your test suite passed.\n\n## Including in your project\n\nYou can add this library to your project using Composer:\n\n```shell\n$ composer require datto/phpunit-entropy\n```\n\n## Running\n\nOnce configured, you can run your test suite as normal; the listener will look\nafter itself. On test error or failure, the seed used will be stored in a\ntemporary file, so that on the next run it will be reused, rather than a new\nseed generated.\n\n### Defining the seed\n\nThe seed for the random number generator is provided from up to four locations,\npresented here in priority order.\n\n#### Environment variable\n\nIf set, the `SEED` environment variable will be used to override any other\nsettings. It can be set via `export`, but recommended use is to set it for the\ncurrent run only:\n\n```shell\nSEED=123456 phpunit -c phpunit.xml tests\n```\n\n#### Configuration\n\nThe seed may be fixed by configuration; see the [Configuration](#Configuration)\nsection below.\n\n#### Last run\n\nIf a test run fails, the seed used is stored in a temporary file. This is then\nloaded on a subsequent test, and will persist until the suite succeeds again.\n\n#### rand()\n\nIf no seed is set via the above methods, the final method is to use PHP's\n`rand` function.\n\n## Configuration\n\n### Entropy Test Listener\n\nOnce installed via composer, configuring the test listener is simply a matter\nof altering your PHPUnit configuration file (often `phpunit.xml`):\n\n```xml\n\u003cphpunit xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n  xsi:noNamespaceSchemaLocation=\"http://schema.phpunit.de/4.1/phpunit.xsd\"\n  backupGlobals=\"false\"\n  colors=\"true\"\n  bootstrap=\"bootstrap.php\"\n  \u003e\n    \u003clisteners\u003e\n        \u003clistener class=\"Datto\\PHPUnit\\Entropy\\Listener\"\u003e\n            \u003carguments\u003e\n                \u003carray\u003e\n                    \u003celement key=\"seeding\"\u003e\n                        \u003carray\u003e\n                            \u003celement key=\"enabled\"\u003e\n                                \u003cboolean\u003etrue\u003c/boolean\u003e\n                            \u003c/element\u003e\n                            \u003celement key=\"seed\"\u003e\n                                \u003cinteger\u003e1234567\u003c/integer\u003e\n                            \u003c/element\u003e\n                            \u003celement key=\"file\"\u003e\n                                \u003cstring\u003e/tmp/phpentropy-seed\u003c/string\u003e\n                            \u003c/element\u003e\n                        \u003c/array\u003e\n                    \u003c/element\u003e\n                    \u003celement key=\"shuffle\"\u003e\n                        \u003cboolean\u003etrue\u003c/boolean\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#### Arguments\n\n##### seeding\n\n###### enabled - boolean\n\nIf set to true, the random number generator will be seeded by the listener.\n\n###### seed - integer\n\nIf you set the seed via this argument, only this value will be used to seed\nthe random number generator. See the section on seed priority below.\n\n###### file - string\n\nIf set, this file will be used to store the last failed random seed; it\ndefaults to `[TMPDIR LOCATION]/phpunit-entropy-seed`.\n\n##### shuffle - boolean\n\nIf set to true, the order in which unit tests are executed will be randomized\n(except for suites where `@depends` is in use). This is useful in determining\nand identifying inter-test dependencies.\n\n## Future work\n\n * Keep track of subsequent test runs\n * Detect changes between runs\n * Provide guiding output when tests are shuffled\n\n## Developer contact\n\nChristopher Hoult \u003c[choult@datto.com](mailto://choult@datto.com)\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatto%2Fphpunit-entropy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdatto%2Fphpunit-entropy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdatto%2Fphpunit-entropy/lists"}