{"id":18834271,"url":"https://github.com/chubbyphp/chubbyphp-mock","last_synced_at":"2026-04-06T03:01:56.950Z","repository":{"id":56952680,"uuid":"142683674","full_name":"chubbyphp/chubbyphp-mock","owner":"chubbyphp","description":"A helper trait simplify mocking within phpunit.","archived":false,"fork":false,"pushed_at":"2025-03-12T13:55:27.000Z","size":237,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T18:55:27.104Z","etag":null,"topics":["helper","mock","phpunit","trait"],"latest_commit_sha":null,"homepage":"","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/chubbyphp.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}},"created_at":"2018-07-28T14:27:36.000Z","updated_at":"2025-03-10T07:13:11.000Z","dependencies_parsed_at":"2024-03-13T21:26:28.313Z","dependency_job_id":"e2c52065-8469-4ac3-9425-aac508a994d6","html_url":"https://github.com/chubbyphp/chubbyphp-mock","commit_stats":{"total_commits":89,"total_committers":4,"mean_commits":22.25,"dds":0.2359550561797753,"last_synced_commit":"afff483bcee090f8f4fb74045da5b3a946ef18e0"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chubbyphp%2Fchubbyphp-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chubbyphp%2Fchubbyphp-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chubbyphp%2Fchubbyphp-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chubbyphp%2Fchubbyphp-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chubbyphp","download_url":"https://codeload.github.com/chubbyphp/chubbyphp-mock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248821977,"owners_count":21166985,"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":["helper","mock","phpunit","trait"],"created_at":"2024-11-08T02:11:29.703Z","updated_at":"2026-04-06T03:01:56.939Z","avatar_url":"https://github.com/chubbyphp.png","language":"PHP","readme":"# chubbyphp-mock\n\n[![CI](https://github.com/chubbyphp/chubbyphp-mock/actions/workflows/ci.yml/badge.svg)](https://github.com/chubbyphp/chubbyphp-mock/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/github/chubbyphp/chubbyphp-mock/badge.svg?branch=master)](https://coveralls.io/github/chubbyphp/chubbyphp-mock?branch=master)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fchubbyphp%2Fchubbyphp-mock%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/chubbyphp/chubbyphp-mock/master)\n[![Latest Stable Version](https://poser.pugx.org/chubbyphp/chubbyphp-mock/v)](https://packagist.org/packages/chubbyphp/chubbyphp-mock)\n[![Total Downloads](https://poser.pugx.org/chubbyphp/chubbyphp-mock/downloads)](https://packagist.org/packages/chubbyphp/chubbyphp-mock)\n[![Monthly Downloads](https://poser.pugx.org/chubbyphp/chubbyphp-mock/d/monthly)](https://packagist.org/packages/chubbyphp/chubbyphp-mock)\n\n[![bugs](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-mock\u0026metric=bugs)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-mock)\n[![code_smells](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-mock\u0026metric=code_smells)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-mock)\n[![coverage](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-mock\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-mock)\n[![duplicated_lines_density](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-mock\u0026metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-mock)\n[![ncloc](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-mock\u0026metric=ncloc)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-mock)\n[![sqale_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-mock\u0026metric=sqale_rating)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-mock)\n[![alert_status](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-mock\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-mock)\n[![reliability_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-mock\u0026metric=reliability_rating)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-mock)\n[![security_rating](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-mock\u0026metric=security_rating)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-mock)\n[![sqale_index](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-mock\u0026metric=sqale_index)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-mock)\n[![vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=chubbyphp_chubbyphp-mock\u0026metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=chubbyphp_chubbyphp-mock)\n\n## Description\n\nA strict mocking solution.\n\n## Requirements\n\n * php: ^8.3\n * [nikic/php-parser][2]: ^5.7\n\n## Installation\n\nThrough [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-mock][1].\n\n```sh\ncomposer require chubbyphp/chubbyphp-mock \"^2.1\" --dev\n```\n\n## Usage\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace MyProject\\Tests\\Unit\\RequestHandler;\n\nuse Chubbyphp\\Mock\\MockMethod\\WithCallback;\nuse Chubbyphp\\Mock\\MockMethod\\WithReturn;\nuse Chubbyphp\\Mock\\MockMethod\\WithReturnSelf;\nuse Chubbyphp\\Mock\\MockObjectBuilder;\nuse MyProject\\RequestHandler\\PingRequestHandler;\nuse PHPUnit\\Framework\\TestCase;\nuse Psr\\Http\\Message\\ResponseFactoryInterface;\nuse Psr\\Http\\Message\\ResponseInterface;\nuse Psr\\Http\\Message\\ServerRequestInterface;\nuse Psr\\Http\\Message\\StreamInterface;\n\nfinal class PingRequestHandlerTest extends TestCase\n{\n    public function testHandle(): void\n    {\n        $builder = new MockObjectBuilder();\n\n        $request = $builder-\u003ecreate(ServerRequestInterface::class, []);\n\n        $responseBody = $builder-\u003ecreate(StreamInterface::class, [\n            new WithCallback('write', static function (string $string): int {\n                $data = json_decode($string, true);\n                self::assertArrayHasKey('datetime', $data);\n\n                return \\strlen($string);\n            }),\n        ]);\n\n        $response = $builder-\u003ecreate(ResponseInterface::class, [\n            new WithReturnSelf('withHeader', ['Content-Type', 'application/json']),\n            new WithReturnSelf('withHeader', ['Cache-Control', 'no-cache, no-store, must-revalidate']),\n            new WithReturnSelf('withHeader', ['Pragma', 'no-cache']),\n            new WithReturnSelf('withHeader', ['Expires', '0']),\n            new WithReturn('getBody', [], $responseBody),\n        ]);\n\n        $responseFactory = $builder-\u003ecreate(ResponseFactoryInterface::class, [\n            new WithReturn('createResponse', [200, ''], $response),\n        ]);\n\n        $requestHandler = new PingRequestHandler($responseFactory);\n\n        self::assertSame($response, $requestHandler-\u003ehandle($request));\n    }\n}\n```\n\n## FAQ\n\n### Howto mock final classes/methods\n\nUse the third party package [dg/bypass-finals](https://packagist.org/packages/dg/bypass-finals).\n\n**This does not work to get rid of the final keyword on internal classes.**\n\n### What Cannot Be Mocked\n\n- **Static methods**\n\n- **Properties**\n\n- **__construct, __destruct methods**\n\n- **Interfaces extending internal interfaces:**\n  Interfaces that extend built-in PHP interfaces like `Traversable` are used as markers rather than containing methods. They cannot be mocked.\n\n- **Internal final classes or methods:**\n  Even with tools like `dg/bypass-finals`, you cannot mock internal final classes or methods.\n\n- **Poorly built extension classes:**\n  Some older PHP extensions create classes that cannot be fully reverse-engineered using reflection. These classes are not mockable.\n\nPlease report if you find other restrictions / bugs.\n\n## Upgrade\n\n[Upgrade from 1.x](doc/upgrade-from-1.x.md)\n\n\n## Copyright\n\n2026 Dominik Zogg\n\n\n[1]: https://packagist.org/packages/chubbyphp/chubbyphp-mock\n[2]: https://packagist.org/packages/nikic/php-parser\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchubbyphp%2Fchubbyphp-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchubbyphp%2Fchubbyphp-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchubbyphp%2Fchubbyphp-mock/lists"}