{"id":28399402,"url":"https://github.com/codeception/stub","last_synced_at":"2025-06-28T21:31:43.210Z","repository":{"id":44674559,"uuid":"100705598","full_name":"Codeception/Stub","owner":"Codeception","description":"Flexible Stub wrapper for PHPUnit's Mock Builder","archived":false,"fork":false,"pushed_at":"2025-02-14T09:01:49.000Z","size":77,"stargazers_count":299,"open_issues_count":8,"forks_count":17,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-06-27T12:24:32.180Z","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/Codeception.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,"zenodo":null}},"created_at":"2017-08-18T11:26:35.000Z","updated_at":"2025-05-21T05:46:01.000Z","dependencies_parsed_at":"2023-01-31T05:01:02.684Z","dependency_job_id":"f8e80d00-0539-4e81-ba11-517b983fb9d0","html_url":"https://github.com/Codeception/Stub","commit_stats":{"total_commits":55,"total_committers":16,"mean_commits":3.4375,"dds":0.6363636363636364,"last_synced_commit":"4fcad2c165f365377486dc3fd8703b07f1f2fcae"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/Codeception/Stub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codeception%2FStub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codeception%2FStub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codeception%2FStub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codeception%2FStub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Codeception","download_url":"https://codeload.github.com/Codeception/Stub/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codeception%2FStub/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262502305,"owners_count":23321122,"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":"2025-06-01T08:09:00.908Z","updated_at":"2025-06-28T21:31:43.183Z","avatar_url":"https://github.com/Codeception.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Codeception\\Stub\n\n![CI](https://github.com/Codeception/Stub/workflows/CI/badge.svg)\n[![Latest Stable Version](https://poser.pugx.org/codeception/stub/v/stable)](https://packagist.org/packages/codeception/stub)\n[![Total Downloads](https://poser.pugx.org/codeception/stub/downloads)](https://packagist.org/packages/codeception/stub)\n[![License](https://poser.pugx.org/codeception/stub/license)](https://packagist.org/packages/codeception/stub)\n\nLibrary on top of PHPUnit's mock builder providing a highly simplified syntax:\n\n## Reference\n\n* [Stub](https://github.com/Codeception/Stub/blob/master/docs/Stub.md) - creating stub classes using static methods\n* [Stub Trait](https://github.com/Codeception/Stub/blob/master/docs/StubTrait.md) - creating stubs and mocks using trait\n* [Expected](https://github.com/Codeception/Stub/blob/master/docs/Expected.md) - defining expectations for mocks\n\n## Install\n\nEnabled by default in Codeception.\nFor PHPUnit install this package:\n\n```\ncomposer require codeception/stub --dev\n```\n\n## Stubs\n\nStubs can be constructed with `Codeception\\Stub` static calls:\n\n```php\n\u003c?php\n// create a stub with find method replaced\n$userRepository = Stub::make(UserRepository::class, ['find' =\u003e new User]);\n$userRepository-\u003efind(1); // =\u003e User\n\n// create a dummy\n$userRepository = Stub::makeEmpty(UserRepository::class);\n\n// create a stub with all methods replaced except one\n$user = Stub::makeEmptyExcept(User::class, 'validate');\n$user-\u003evalidate($data);\n\n// create a stub by calling constructor and replacing a method\n$user = Stub::construct(User::class, ['name' =\u003e 'davert'], ['save' =\u003e false]);\n\n// create a stub by calling constructor with empty methods\n$user = Stub::constructEmpty(User::class, ['name' =\u003e 'davert']);\n\n// create a stub by calling constructor with empty methods\n$user = Stub::constructEmptyExcept(User::class, 'getName', ['name' =\u003e 'davert']);\n$user-\u003egetName(); // =\u003e davert\n$user-\u003esetName('jane'); // =\u003e this method is empty\n$user-\u003egetName(); // =\u003e davert \n```\n\n[See complete reference](https://github.com/Codeception/Stub/blob/master/docs/Stub.md)\n\nAlternatively, stubs can be created by using [`Codeception\\Test\\Feature\\Stub` trait](https://github.com/Codeception/Stub/blob/master/docs/StubTrait.md):\n\n```php\n\u003c?php\n$this-\u003emake(UserRepositry::class);\n$this-\u003emakeEmpty(UserRepositry::class);\n$this-\u003econstruct(UserRepositry::class);\n$this-\u003econstructEmpty(UserRepositry::class);\n// ...\n```\n\n## Mocks\n\nMocks should be created by including [`Codeception\\Test\\Feature\\Stub` trait](https://github.com/Codeception/Stub/blob/master/docs/StubTrait.md) into a test case.\nExecution expectation are set with [`Codeception\\Stub\\Expected`](https://github.com/Codeception/Stub/blob/master/docs/Expected.md):\n\n```php\n\u003c?php\n// find should be never called\n$userRepository = $this-\u003emake(UserRepository::class, [\n    'find' =\u003e Codeception\\Stub\\Expected::never()\n]);\n\n// find should be called once and return a new user\n$userRepository = $this-\u003emake(UserRepository::class, [\n    'find' =\u003e Codeception\\Stub\\Expected::once(new User)\n]);\n```\n\n\n## License \n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeception%2Fstub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeception%2Fstub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeception%2Fstub/lists"}