{"id":19406283,"url":"https://github.com/chadicus/test-helpers","last_synced_at":"2025-04-24T09:31:03.303Z","repository":{"id":16571534,"uuid":"19325486","full_name":"chadicus/test-helpers","owner":"chadicus","description":"Classes designed to assist with PHPUnit testing","archived":false,"fork":false,"pushed_at":"2023-07-05T15:00:39.000Z","size":665,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-03T02:12:13.543Z","etag":null,"topics":[],"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/chadicus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","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":"2014-04-30T19:57:21.000Z","updated_at":"2023-07-05T15:00:07.000Z","dependencies_parsed_at":"2024-11-10T11:52:03.419Z","dependency_job_id":null,"html_url":"https://github.com/chadicus/test-helpers","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/chadicus%2Ftest-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadicus%2Ftest-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadicus%2Ftest-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chadicus%2Ftest-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chadicus","download_url":"https://codeload.github.com/chadicus/test-helpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250600623,"owners_count":21456996,"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-11-10T11:41:52.758Z","updated_at":"2025-04-24T09:31:03.042Z","avatar_url":"https://github.com/chadicus.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chadicus Test Helpers\n\n[![Latest Stable Version](https://poser.pugx.org/chadicus/test-helpers/v/stable)](https://packagist.org/packages/chadicus/test-helpers)\n[![Latest Unstable Version](https://poser.pugx.org/chadicus/test-helpers/v/unstable)](https://packagist.org/packages/chadicus/test-helpers)\n[![License](https://poser.pugx.org/chadicus/test-helpers/license)](https://packagist.org/packages/chadicus/test-helpers)\n\n[![Total Downloads](https://poser.pugx.org/chadicus/test-helpers/downloads)](https://packagist.org/packages/chadicus/test-helpers)\n[![Daily Downloads](https://poser.pugx.org/chadicus/test-helpers/d/daily)](https://packagist.org/packages/chadicus/test-helpers)\n[![Monthly Downloads](https://poser.pugx.org/chadicus/test-helpers/d/monthly)](https://packagist.org/packages/chadicus/test-helpers)\n\n## Requirements\n\nTest Helpers requires PHP 7.3 (or later).\n\n## Composer\nTo add the library as a local, per-project dependency use [Composer](http://getcomposer.org)! Simply add a dependency on\n`chadicus/test-helpers` to your project's `composer.json` file such as:\n\n```sh\ncomposer require --dev chadicus/test-helpers\n```\n\nNOTE: test-helpers should never be used in production. They are meant for testing enviornments only.\n\n## Documentation\nPHP docs for the project can be found [here](http://chadicus.github.io/test-helpers).\n\n## Contact\nDevelopers may be contacted at:\n\n * [Pull Requests](https://github.com/chadicus/test-helpers/pulls)\n * [Issues](https://github.com/chadicus/test-helpers/issues)\n\n## Project Build\nWith a checkout of the code get [Composer](http://getcomposer.org) in your PATH and run:\n\n```sh\ncomposer install\ncomposer run test\ncomposer run lint\n```\n# \\Chadicus\\FunctionRegistry\n\nSome internal PHP functions are documented to return certain values on failure. If you're a meticulous programmer you want to account for these return values in your code and respond to them accordingly.\n```php\nclass MyClass\n{\n    public function doSomething()\n    {\n        $curl = curl_init();\n        if ($curl === false) {\n            throw new \\Exception('curl_init() failed');\n        }\n\n        //do something with $curl ...\n    }\n}\n```\n\nA meticulous programmer may also want to ensure their unit test code coverage is 100%.\n\nOne way to accomplish this is to use @codeCoverageIgnore annotations\n```php\nclass MyClass\n{\n    public function doSomething()\n    {\n        $curl = curl_init();\n        if ($curl === false) {\n            //@codeCoverageIgnoreStart\n            throw new \\Exception('curl_init() failed');\n            //@codeCoverageIgnoreEnd\n        }\n\n        //do something with $curl ...\n    }\n}\n```\n\nThis gets us the code coverage but the code isn't really tested.\n\nThe `FunctionRegistry` class alows you to _mock_ an internal PHP function\n\n```php\nclass MyClassTest extends \\PHPUnit_Framework_TestCase\n{\n    protected function setUp()\n    {\n        // prepare the curl functions for mocking\n        \\Chadicus\\FunctionRegistry::reset(__NAMESPACE__, array('curl'));\n    }\n\n    /**\n     * @expectedExceptionMessage curl_init() failed\n     */\n    public function testCurlInitFails()\n    {\n        \\Chadicus\\FunctionRegistry::set(\n            __NAMESPACE__,\n            'curl_init',\n            function () {\n                return false;\n            }\n        );\n\n        $myClass = new MyClass();\n\n        // this will call our custom curl_init function\n        $myClass-\u003edoSomething();\n    }\n}\n```\n\nFor functions and constants, PHP will fall back to global functions or constants if a namespaced function or constant does not exist. It is because of this behavior that we can _mock_ internal functions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadicus%2Ftest-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchadicus%2Ftest-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchadicus%2Ftest-helpers/lists"}