{"id":25518278,"url":"https://github.com/sitphp/doubles","last_synced_at":"2025-04-10T23:32:17.287Z","repository":{"id":57052088,"uuid":"190221878","full_name":"sitphp/doubles","owner":"sitphp","description":"A simple yet powerful library to make class doubles for testing","archived":false,"fork":false,"pushed_at":"2022-11-19T04:18:57.000Z","size":155,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-24T20:13:38.808Z","etag":null,"topics":["doubles","mock","php","phpunit"],"latest_commit_sha":null,"homepage":"https://sitphp.com/doubles/doc/intro/latest","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/sitphp.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-06-04T14:49:55.000Z","updated_at":"2022-09-05T13:51:18.000Z","dependencies_parsed_at":"2023-01-22T07:01:33.914Z","dependency_job_id":null,"html_url":"https://github.com/sitphp/doubles","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sitphp%2Fdoubles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sitphp%2Fdoubles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sitphp%2Fdoubles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sitphp%2Fdoubles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sitphp","download_url":"https://codeload.github.com/sitphp/doubles/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248316067,"owners_count":21083375,"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":["doubles","mock","php","phpunit"],"created_at":"2025-02-19T16:24:53.321Z","updated_at":"2025-04-10T23:32:17.267Z","avatar_url":"https://github.com/sitphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SitPHP/Doubles\n\n![Build Status](https://travis-ci.org/sitphp/doubles.svg?branch=master)\n\nThe \"sitphp/doubles\" library can help you to test your PHP classes by generating doubles that look like the original\nclasses but can be manipulated and tested (sort of a copy of a class). These doubles then can then be used instead of\nthe original classes for your test. This library can create doubles of any kind of class, interface or trait.\n\nSee full documentation : [here](https://sitphp.com/doubles/doc/intro)\n\n## Requirements\n\nThe \"sitphp/doubles\" library requires at least PhpUnit 6.5 and at least PHP 7.0. It should be installed from composer\nwhich will make sure your configuration matches requirements.\n\u003e {.note .info} Note : You can get composer here : [https://getcomposer.org](https://getcomposer.org).\n\n## Installation\n\nAdd the line `\"sitphp/doubles\": \"2.4.*\"` in the `\"require-dev\"` section of your composer.json file :\n\n```json\n{\n    \"require-dev\": {\n        \"sitphp/doubles\": \"2.4.*\"\n    }\n}\n```\n\nAnd run the following command :\n\n```bash    \ncomposer update\n```\n\nThis will install the latest version of the \"sitphp/doubles\" library with the required PhpUnit package.\n\n## Creating a double\n\nA double is called a \"dummy\" when all the methods of the original class are overwritten to return `null`. To get a \"\ndummy\" double instance, use the `dummy` method :\n\n```php\n// Get a double instance of type \"dummy\" for class \"MyClass\"\n$my_double = Double::dummy(MyClass::class)-\u003egetInstance();\n```\n\nA double is called a \"mock\" when all the methods of the original class are overwritten to behave the same as in the\noriginal class. To get a \"mock\" double instance, use the `mock` method :\n\n```php\n// Get a double instance of type \"mock\" for class \"MyClass\"\n$my_double = Double::mock(MyClass::class)-\u003egetInstance();\n```\n\nFor more details : [Read the doc on creating doubles](doc/03_creating_doubles.md)\n\n## Testing a double\n\nTo test how many times a double method is called, use the `count` method :\n\n```php\n// Test that the method \"myMethod\" is called a least one time\n$double::_method('myMethod')-\u003ecount('\u003e=1');\n```\n\nTo test the values of the arguments passed to a double method, use the `args` method :\n\n```php\n// Test that the arguments passed to method \"myMethod\" are \"value1\" and \"value2\"\n$double::_method('myMethod')-\u003eargs(['value1', 'value2']);\n```\n\nTo change the return value of a method, use the `stub` method. :\n\n```php\n// Make method \"myMethod\" return \"hello\"\n$my_double::_method('myMethod')-\u003ereturn('hello');\n```\n\nFor more details : [Read the doc on testing doubles](doc/04_testing_doubles.md)\n\n## Configuration\n\nYou define the configuration for a specific double using the 2nd argument of the `dummy` and `mock` methods :\u003c/p\u003e\n\n```php\n// Get double instance with config\n$my_double = Double::dummy(MyClass::class, [\n    'allow_final_doubles' =\u003e true,\n    'allow_non_existent_classes' =\u003e true\n])-\u003egetInstance();\n```\n\nHere is a list of all available config parameters :\n\n- `allow_final_doubles` : Set this parameter to `false` to stop trying to make doubles of final classes/methods.\n- `allow_protected_methods` : Set this parameter to `false` to disallow testing protected methods.\n- `allow_non_existent_classes` : Set this parameter to `false` to disallow alias doubles of non existent classes.\n- `test_unexpected_methods` : Set this parameter to `true` to automatically receive an assertion error whenever an\n  unexpected method is called.\n\nFor more details : [Read the doc on configuration](doc/05_configuration.md)\n\n## About\n\n### License\n\nThis library is licensed under the [MIT license](https://opensource.org/licenses/MIT).\n\n### Author\n\nAlexandre Geiswiller - [alexandre.geiswiller@gmail.com](mailto:alexandre.geiswiller@gmail.com).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsitphp%2Fdoubles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsitphp%2Fdoubles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsitphp%2Fdoubles/lists"}