{"id":15014440,"url":"https://github.com/php-mock/php-mock-phpunit","last_synced_at":"2025-05-15T04:06:59.774Z","repository":{"id":29730721,"uuid":"33273982","full_name":"php-mock/php-mock-phpunit","owner":"php-mock","description":" Mock built-in PHP functions (e.g. time() or rand()) in PHPUnit.","archived":false,"fork":false,"pushed_at":"2025-04-04T06:35:38.000Z","size":178,"stargazers_count":168,"open_issues_count":3,"forks_count":19,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T10:09:54.665Z","etag":null,"topics":["builtin-functions","mock","php","php-mock","phpunit"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-mock.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},"funding":{"github":["michalbundyra"]}},"created_at":"2015-04-01T21:28:25.000Z","updated_at":"2025-04-04T06:35:42.000Z","dependencies_parsed_at":"2022-07-24T16:32:03.046Z","dependency_job_id":"b2bed58d-17e8-453f-95f8-98f381b2b284","html_url":"https://github.com/php-mock/php-mock-phpunit","commit_stats":{"total_commits":78,"total_committers":6,"mean_commits":13.0,"dds":0.5,"last_synced_commit":"8cd8fc626f964f5f8a29034078797be235203ccf"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-mock%2Fphp-mock-phpunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-mock%2Fphp-mock-phpunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-mock%2Fphp-mock-phpunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-mock%2Fphp-mock-phpunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-mock","download_url":"https://codeload.github.com/php-mock/php-mock-phpunit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254270646,"owners_count":22042859,"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":["builtin-functions","mock","php","php-mock","phpunit"],"created_at":"2024-09-24T19:45:38.357Z","updated_at":"2025-05-15T04:06:54.752Z","avatar_url":"https://github.com/php-mock.png","language":"PHP","readme":"[![.github/workflows/tests.yml](https://github.com/php-mock/php-mock-phpunit/actions/workflows/tests.yml/badge.svg)](https://github.com/php-mock/php-mock-phpunit/actions/workflows/tests.yml)\n\n# Mock PHP built-in functions with PHPUnit\n\nThis package integrates the function mock library\n[PHP-Mock](https://github.com/php-mock/php-mock) with PHPUnit.\n\n## Installation\n\nUse [Composer](https://getcomposer.org/):\n\n```sh\ncomposer require --dev php-mock/php-mock-phpunit\n```\n\n## Usage\n\nPHP-Mock integrates with the trait\n[`PHPMock`](http://php-mock.github.io/php-mock-phpunit/api/class-phpmock.phpunit.PHPMock.html)\ninto your PHPUnit test case. This trait extends the framework\nby the method\n[`getFunctionMock()`](http://php-mock.github.io/php-mock-phpunit/api/class-phpmock.phpunit.PHPMock.html#_getFunctionMock).\nWith this method you can build a mock in the way you are used to build a\nPHPUnit mock:\n\n```php\nnamespace foo;\n\nclass BuiltinTest extends \\PHPUnit\\Framework\\TestCase\n{\n\n    use \\phpmock\\phpunit\\PHPMock;\n\n    public function testTime()\n    {\n        $time = $this-\u003egetFunctionMock(__NAMESPACE__, \"time\");\n        $time-\u003eexpects($this-\u003eonce())-\u003ewillReturn(3);\n\n        $this-\u003eassertEquals(3, time());\n    }\n\n    public function testExec()\n    {\n        $exec = $this-\u003egetFunctionMock(__NAMESPACE__, \"exec\");\n        $exec-\u003eexpects($this-\u003eonce())-\u003ewillReturnCallback(\n            function ($command, \u0026$output, \u0026$return_var) {\n                $this-\u003eassertEquals(\"foo\", $command);\n                $output = [\"failure\"];\n                $return_var = 1;\n            }\n        );\n\n        exec(\"foo\", $output, $return_var);\n        $this-\u003eassertEquals([\"failure\"], $output);\n        $this-\u003eassertEquals(1, $return_var);\n    }\n}\n```\n\nThere's no need to disable the mocked function. The PHPUnit integration does\nthat for you.\n\n### Restrictions\n\nThis library comes with the same restrictions as the underlying\n[`php-mock`](https://github.com/php-mock/php-mock#requirements-and-restrictions):\n\n* Only *unqualified* function calls in a namespace context can be mocked.\n  E.g. a call for `time()` in the namespace `foo` is mockable,\n  a call for `\\time()` is not.\n\n* The mock has to be defined before the first call to the unqualified function\n  in the tested class. This is documented in [Bug #68541](https://bugs.php.net/bug.php?id=68541).\n  In most cases you can ignore this restriction. But if you happen to run into\n  this issue you can call [`PHPMock::defineFunctionMock()`](http://php-mock.github.io/php-mock-phpunit/api/class-phpmock.phpunit.PHPMock.html#_defineFunctionMock)\n  before that first call (e.g. with `@beforeClass`).\n  This would define a side effectless namespaced function. Another effective\n  approach is running your test in an isolated process (e.g. with `@runInSeparateProcess`).\n\n## License and authors\n\nThis project is free and under the WTFPL.\nResponsable for this project is Markus Malkusch markus@malkusch.de.\n\n### Donations\n\nIf you like this project and feel generous donate a few Bitcoins here:\n[1335STSwu9hST4vcMRppEPgENMHD2r1REK](bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK)\n","funding_links":["https://github.com/sponsors/michalbundyra"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-mock%2Fphp-mock-phpunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-mock%2Fphp-mock-phpunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-mock%2Fphp-mock-phpunit/lists"}