{"id":13828608,"url":"https://github.com/funkatron/FUnit","last_synced_at":"2025-07-09T06:32:23.567Z","repository":{"id":2143547,"uuid":"3087869","full_name":"funkatron/FUnit","owner":"funkatron","description":"The testing microframework for PHP","archived":false,"fork":false,"pushed_at":"2018-01-27T17:39:31.000Z","size":113,"stargazers_count":84,"open_issues_count":5,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-18T16:57:59.590Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"phusion/node-sha3","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/funkatron.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":"2012-01-02T14:19:34.000Z","updated_at":"2024-10-30T10:06:42.000Z","dependencies_parsed_at":"2022-08-20T08:41:17.882Z","dependency_job_id":null,"html_url":"https://github.com/funkatron/FUnit","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funkatron%2FFUnit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funkatron%2FFUnit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funkatron%2FFUnit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/funkatron%2FFUnit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/funkatron","download_url":"https://codeload.github.com/funkatron/FUnit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225492420,"owners_count":17482869,"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-08-04T09:02:54.771Z","updated_at":"2024-11-20T08:30:52.044Z","avatar_url":"https://github.com/funkatron.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# FUnit: The testing microframework for PHP\n\nFUnit is a testing microframework for PHP 5.3+, partially inspired by [QUnit](http://qunitjs.com/). FUnit was created by [Ed Finkler](http://funkatron.com) for **[Fictive Kin](http://fictivekin.com)**.\n\n**If you can code PHP, you can write tests with FUnit.**\n\n## Features\n\n* Simple to write tests and get output – **start writing tests fast**\n* Short, straightforward syntax\n* Can be run from the CLI – no web server required\n* Fancy colored output in terminal\n\n## Example\n\n``` php\n\u003c?php\nrequire __DIR__ . '/FUnit.php';\nuse \\FUnit as fu;  // note the alias to \"fu\" for terseness\n\nfu::test(\"this is a test\", function() {\n\tfu::ok(1, \"the integer '1' is okay\");\n\tfu::ok(0, \"the integer '0' is not okay\"); // this will fail!\n});\n\n$exit_code = fu::run();\nexit($exit_code);\n```\n\nWill output:\n\n\t\u003e php example_standalone.php\n    Running test 'this is a test...'\n\tRESULTS:\n\t--------------------------------------------\n\tTEST: this is a test (1/2):\n\t * PASS ok() the integer '1' is okay\n\t * FAIL ok() the integer '0' is not okay\n\n\tERRORS/EXCEPTIONS: 0\n\tTOTAL ASSERTIONS: 1 pass, 1 fail, 0 expected fail, 2 total\n\tTESTS: 1 run, 0 pass, 1 total\n\nSee the `example_standalone.php` file for more, or try running it with `php example_standalone.php`\n\nAlternately, if you load `standalone_example.php` in a web browser, it will output a very simple HTML version of the text report. If you're running PHP 5.4 or above, you can use the dev server to view it like so:\n\n`php -S 0.0.0.0:8000 example_standalone.php`\n\nAnd then open \u003chttp://0.0.0.0:8000\u003e in a web browser.\n\n## Methods\n\n### Test Suite Building Methods\n\n* **`FUnit::test($name, \\Closure $test)`**    \n  Add a test with the name $name and an anonymous function $test. $test would contain various **assertions**, like `FUnit::ok()`\n\n* **`FUnit::run($report = true, $filter = null, $report_format = 'text')`**    \n  Runs the registered tests.\n  * `$report` (boolean): If `false` is passed, the report output is suppressed.\n  * `$filter` (string): If this is passed, only tests that contain the `$filter` string will be run.\n  * `$report_format` (string): Default is 'text'. Also accepts 'xunit'.\n\n* **`FUnit::setup(\\Closure $setup)`**    \n  Register a function to run at the start of each test. See `FUnit::fixture()`\n\n* **`FUnit::teardown(\\Closure $setup)`**    \n  Register a function to run at the end of each test. See `FUnit::fixture()` and `FUnit::reset_fixtures()`\n\n* **`FUnit::fixture($key, [$val])`**    \n  Retrieve or register a fixture. Use this in FUnit::setup() to assign fixtures to keys, and retrieve those fixtures in your tests\n\n* **`FUnit::reset_fixtures()`**    \n  Clears out all fixtures in the FUnit::$fixtures array. This doesn't guarantee clean shutdown/close\n\n\n### Assertions\n\n* **`FUnit::ok($a, $msg = null)`**    \n  Assert that $a is truthy. Optional $msg describes the test\n\n* **`FUnit::not_ok($a, $msg = null)`**    \n  Assert that $a is not truthy. Optional $msg describes the test\n\n* **`FUnit::equal($a, $b, $msg = null)`**    \n  Assert that $a == $b. Optional $msg describes the test\n\n* **`FUnit::not_equal($a, $b, $msg = null)`**    \n  Assert that $a != $b. Optional $msg describes the test\n\n* **`FUnit::strict_equal($a, $b, $msg = null)`**    \n  Assert that $a === $b. Optional $msg describes the test\n\n* **`FUnit::not_strict_equal($a, $b, $msg = null)`**    \n  Assert that $a !== $b. Optional $msg describes the test\n\n* **`FUnit::has($needle, $haystack, $msg = null)`**    \n  Assert that an array or object (`$haystack`) has a key or property (`$needle`)\n\n* **`FUnit::not_has($needle, $haystack, $msg = null)`**    \n  Assert that an array or object (`$haystack`) does *not* have a key or property (`$needle`). Forgive my grammar.\n\n* **`FUnit::fail($msg = null, [$expected = null])`**    \n  Force a failed assertion. If `$expected === true`, it's marked as an *expected failure*\n\n* **`FUnit::expect_fail($msg = null)`**    \n  Assets an *expected failure.* Equivalent to `FUnit::fail('msg', true)`\n\n* **`FUnit::pass($msg = null)`**    \n  Force a successful assertion.\n\n* **`FUnit::throws($callback, $params, $exception = null, $msg = null)`**    \n  Assert that `$callback` throws an exception of type `$exception`. `$callback` must be a [*callable*](http://php.net/manual/en/language.types.callable.php)\n\n* **`FUnit::all_ok($a, $callback, $msg = null)`**    \n  Iterate over all the items in `$a` and pass each to `$callback`. If the callback returns `true` for all, it passes -- otherwise it fails. `$callback` must be a [*callable*](http://php.net/manual/en/language.types.callable.php)\n\n### Utility Methods\n\n* **`FUnit::report($format = 'text')`**    \n  Output the test report. If you've suppressed reporting output previously, you can use this to output the report manually.\n\n* **`FUnit::exit_code()`**    \n  Retrieve the exit code. If any test fails, the exit code will be set to `1`. Otherwise `0`. You can use this value to return a success or failure result with the PHP function `exit()`.\n\n\n### Configuration Methods\n\n* **`FUnit::set_disable_reporting($state)`**    \n  If passed `true`, report will not be output after test runs finish. Re-enable by passing `false`.\n\n* **`FUnit::set_debug($state)`**    \n  If passed `true`, extra debugging info (including timing and details about assertion failures) will be output. Disable by passing `false`.\n\n* **`FUnit::set_silence($state)`**    \n  If passed `true`, only the report will be output -- no progress, debugging info, etc. Disable by passing `false`.\n\n\n## Report formats\n\nBy default, FUnit outputs a colorful `text` output, formatted for the terminal. You can also output reports in `xunit`-style xml.\n\nThe report format is the third parameter of `FUnit::run()`:\n\nExample:\n``` php\n// Outputs a colored text report. This is the default format.\nFUnit::run(true, null, 'text');\n\n// Outputs xUnit-style xml\nFUnit::run(true, null, 'xunit');\n```\n\n### Browser output\n\nThe standard `text` report format will output as very simple HTML if the test file is loaded up through a web server. You can test this with the dev server if you're running PHP 5.4+:\n\n`php -S 0.0.0.0:8000 test_file.php`\n\nAnd then open \u003chttp://0.0.0.0:8000\u003e in a web browser.\n\n## CLI Test Runner Utility\n\nFUnit was designed to not require a separate test runner tool, but it does come with one at `bin/fu` (or `vendor/bin/fu` if you've installed via Composer). `fu` allows you to run tests in a single file, a group of files in a directory, and filter what tests are run.\n\nExamples:\n* **`fu --help`**    \n  Get detailed help and information on all options\n\n* **`fu ./tests`**    \n  Scan the directory `./tests` for files that have \"test(s)\" in their names, and run those tests\n\n* **`fu tests.php`**    \n  Execute tests in `tests.php`\n\n* **`fu -d tests.php`**    \n  Execute tests in `tests.php` with additional debugging info\n\n* **`fu --filter=\"API\" tests.php`**    \n  Execute only the tests in tests.php that have \"API\" in the name\n\n* **`fu -s tests.php`**    \n  Execute the tests tests.php, but suppress all output other than the report\n\n*Note:* When `fu` loads multiple test files, it `require`s each one. That means all the code within each is executed. Calls to `FUnit::run()` are suppressed, but non-FUnit code (like `exit()` calls or `require` statements) could cause issues.\n\n## Installation\n### Install with Composer\nIf you're using [Composer](https://github.com/composer/composer) to manage dependencies, you can add FUnit with it.\n\n``` json\n{\n\t\"require\": {\n\t\t\"funkatron/funit\": \"dev-master\"\n\t}\n}\n```\n\n*Note that FUnit has not yet reached 1.0! That means BC may break!*\n\nIf you install via Composer, you can use the auto-generated autoloader to load FUnit, like so:\n\n``` php\n\u003c?php\nrequire \"vendor/autoload.php\"\nuse \\FUnit as fu;\n\nfu::test(\"this is a test\", function() {\n    fu::ok(1, \"the integer '1' is okay\");\n    fu::ok(0, \"the integer '0' is not okay\"); // this will fail!\n});\n\nfu::run();\n```\n\n### Install source from GitHub\nTo install the source code:\n\n\tgit clone git://github.com/funkatron/FUnit.git\n\nAnd include it in your scripts:\n\n``` php\nrequire_once '/path/to/FUnit/FUnit.php';\n```\n\n### Install source from zip/tarball\nAlternatively, you can fetch a [tarball](https://github.com/funkatron/FUnit/tarball/master) or [zipball](https://github.com/funkatron/FUnit/zipball/master):\n\n    $ curl https://github.com/funkatron/FUnit/tarball/master | tar xzv\n    (or)\n    $ wget https://github.com/funkatron/FUnit/tarball/master -O - | tar xzv\n\n### Using a Class Loader\nIf you're using a class loader (e.g., [Symfony Class Loader](https://github.com/symfony/ClassLoader)) for [PSR-0](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md)-style class loading:\n\n``` php\n$loader-\u003eregisterNamespace('FUnit', 'path/to/vendor/FUnit');\n```\n\n## Upgrading\n\nIf you're using a version older than 0.5, the namespace/class name changed to follow PSR-0 autoloader standards. The base class is now `\\FUnit`, not `\\FUnit\\fu`. You can still call all your methods with `fu::XXX()` by aliasing the namespace like so:\n``` php\nuse \\FUnit as fu\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunkatron%2FFUnit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffunkatron%2FFUnit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffunkatron%2FFUnit/lists"}