{"id":15014529,"url":"https://github.com/mnapoli/phpunit-easymock","last_synced_at":"2025-04-05T17:06:47.261Z","repository":{"id":23124754,"uuid":"26479454","full_name":"mnapoli/phpunit-easymock","owner":"mnapoli","description":"Build PHPUnit mocks easily","archived":false,"fork":false,"pushed_at":"2024-12-11T09:40:42.000Z","size":31,"stargazers_count":38,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T16:07:10.288Z","etag":null,"topics":["php","phpunit","phpunit-extension","phpunit-mock","tests"],"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/mnapoli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"mnapoli","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2014-11-11T10:05:48.000Z","updated_at":"2024-12-11T09:40:30.000Z","dependencies_parsed_at":"2022-08-22T11:31:42.482Z","dependency_job_id":null,"html_url":"https://github.com/mnapoli/phpunit-easymock","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnapoli%2Fphpunit-easymock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnapoli%2Fphpunit-easymock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnapoli%2Fphpunit-easymock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnapoli%2Fphpunit-easymock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mnapoli","download_url":"https://codeload.github.com/mnapoli/phpunit-easymock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247369952,"owners_count":20927928,"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":["php","phpunit","phpunit-extension","phpunit-mock","tests"],"created_at":"2024-09-24T19:45:44.182Z","updated_at":"2025-04-05T17:06:47.219Z","avatar_url":"https://github.com/mnapoli.png","language":"PHP","funding_links":["https://github.com/sponsors/mnapoli"],"categories":[],"sub_categories":[],"readme":"# PHPUnit EasyMock\n\nHelpers to build PHPUnit mock objects easily.\n\n[![Total Downloads](https://poser.pugx.org/mnapoli/phpunit-easymock/downloads)](https://packagist.org/packages/mnapoli/phpunit-easymock)\n\n## Why?\n\nThis library is **not** a mocking library. It's just a few helpers to write the most common mocks more easily.\n\nIt doesn't reinvent anything and is not intended to cover every use case: only the most common ones.\n\n## Installation\n\n```bash\n$ composer require --dev mnapoli/phpunit-easymock\n```\n\nTo be able to use EasyMock in your tests **you must include the trait in your class**:\n\n```php\nclass MyTest extends \\PHPUnit\\Framework\\TestCase\n{\n    use \\EasyMock\\EasyMock;\n\n    // ...\n}\n```\n\n## Usage\n\nHere is what a very common PHPUnit mock looks like:\n\n```php\n$mock = $this-\u003ecreateMock('My\\Class');\n\n$mock-\u003eexpect($this-\u003eany())\n    -\u003emethod('sayHello')\n    -\u003ewillReturn('Hello');\n```\n\nYuck!\n\nHere is how to write it with EasyMock:\n\n```php\n$mock = $this-\u003eeasyMock('My\\Class', [\n    'sayHello' =\u003e 'Hello',\n]);\n```\n\nWhat if you want to assert that the method is called once (i.e. `$mock-\u003eexpect($this-\u003eonce())`)? Use `spy()` instead:\n\n```php\n$mock = $this-\u003eeasySpy('My\\Class', [\n    'sayHello' =\u003e 'Hello',\n]);\n```\n\n### Features\n\nYou can mock methods so that they return values:\n\n```php\n$mock = $this-\u003eeasyMock('My\\Class', [\n    'sayHello' =\u003e 'Hello',\n]);\n```\n\nOr so that they use a callback:\n\n```php\n$mock = $this-\u003eeasyMock('My\\Class', [\n    'sayHello' =\u003e function ($name) {\n        return 'Hello ' . $name;\n    },\n]);\n```\n\nYou can also have methods throw exceptions by providing an `Exception` instance:\n\n```php\n$mock = $this-\u003eeasyMock('My\\Class', [\n    'sayHello' =\u003e new \\RuntimeException('Whoops'),\n]);\n```\n\nIt is possible to call the `mock()` method again on an existing mock:\n\n```php\n$mock = $this-\u003eeasyMock('My\\Class');\n\n$mock = $this-\u003eeasyMock($mock, [\n    'sayHello' =\u003e 'Hello',\n]);\n```\n\n### What if?\n\nIf you want to use assertions or other PHPUnit features, just do it:\n\n```php\n$mock = $this-\u003eeasyMock('My\\Class', [\n    'sayHello' =\u003e 'hello',\n]);\n\n$mock-\u003eexpects($this-\u003eonce())\n    -\u003emethod('sayGoodbye')\n    -\u003ewillReturn('Goodbye');\n```\n\nMocks are plain PHPUnit mocks, nothing special here.\n\n## Contributing\n\nSee the [CONTRIBUTING](CONTRIBUTING.md) file.\n\n## License\n\nReleased under the [MIT license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnapoli%2Fphpunit-easymock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmnapoli%2Fphpunit-easymock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnapoli%2Fphpunit-easymock/lists"}