{"id":21056011,"url":"https://github.com/xp-framework/mocks","last_synced_at":"2025-03-14T00:15:03.292Z","repository":{"id":57084830,"uuid":"40012117","full_name":"xp-framework/mocks","owner":"xp-framework","description":"Mocks for the XP Framework","archived":false,"fork":false,"pushed_at":"2022-02-27T10:48:01.000Z","size":84,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-21T16:48:07.937Z","etag":null,"topics":["mock","php","unittest","xp-framework"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xp-framework.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-31T15:35:44.000Z","updated_at":"2022-02-27T10:42:24.000Z","dependencies_parsed_at":"2022-08-25T00:50:18.000Z","dependency_job_id":null,"html_url":"https://github.com/xp-framework/mocks","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fmocks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fmocks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fmocks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-framework%2Fmocks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xp-framework","download_url":"https://codeload.github.com/xp-framework/mocks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243500787,"owners_count":20300775,"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":["mock","php","unittest","xp-framework"],"created_at":"2024-11-19T16:48:15.923Z","updated_at":"2025-03-14T00:15:03.248Z","avatar_url":"https://github.com/xp-framework.png","language":"PHP","readme":"Mocks\n=====\n\n[![Build status on GitHub](https://github.com/xp-framework/mocks/workflows/Tests/badge.svg)](https://github.com/xp-framework/mocks/actions)\n[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)\n[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)\n[![Requires PHP 7.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_0plus.svg)](http://php.net/)\n[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)\n[![Latest Stable Version](https://poser.pugx.org/xp-framework/mocks/version.png)](https://packagist.org/packages/xp-framework/mocks)\n\nMocks for the XP Framework.\n\nExample\n-------\nHere's an example implementation:\n\n```php\nuse lang\\IllegalAccessException;\n\ninterface Context {\n  public function hasPermission($name);\n}\n\nclass UserService {\n  private $context;\n\n  public function __construct(Context $context) {\n    $this-\u003econtext= $context;\n  }\n\n  public function allUsers() {\n    if (!$this-\u003econtext-\u003ehasPermission('rt=all,rn=users')) {\n      throw new IllegalAccessException('Permission denied!');\n    }\n\n    return []; // TODO: Actually do something:)\n  }\n}\n```\n\nThis is how we can mock the `Context` interface:\n\n```php\nuse unittest\\TestCase;\n\nclass UserServiceTest extends TestCase {\n\n  #[@test]\n  public function allUsers_works_when_hasPermission_returns_true() {\n    $mocks= new MockRepository();\n    $context= $mocks-\u003ecreateMock('Context');\n    $context-\u003ehasPermission('rt=all,rn=users')-\u003ereturns(true);\n    $mocks-\u003ereplayAll();\n\n    $fixture= new UserService($context);\n    $this-\u003eassertEquals([], $fixture-\u003eallUsers());\n  }\n}\n```\n\nFurther reading\n---------------\n\nSee [XP RFC #0219](https://github.com/xp-framework/rfc/issues/219) for a detailled introduction.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-framework%2Fmocks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxp-framework%2Fmocks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-framework%2Fmocks/lists"}