{"id":23274172,"url":"https://github.com/pbwebmedia/mimic","last_synced_at":"2025-08-21T06:31:45.861Z","repository":{"id":57037011,"uuid":"66468673","full_name":"PBWebMedia/mimic","owner":"PBWebMedia","description":"Mimic classes for functional testing","archived":false,"fork":false,"pushed_at":"2024-04-08T08:46:22.000Z","size":135,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-18T11:27:58.978Z","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/PBWebMedia.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}},"created_at":"2016-08-24T13:59:30.000Z","updated_at":"2023-06-13T09:01:25.000Z","dependencies_parsed_at":"2024-04-08T09:52:35.742Z","dependency_job_id":"990c151f-2887-4288-bb23-16f7fa801ea7","html_url":"https://github.com/PBWebMedia/mimic","commit_stats":{"total_commits":40,"total_committers":5,"mean_commits":8.0,"dds":0.4,"last_synced_commit":"8103809bc14e404e2f5c710c28eaaea9ba29ae6c"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PBWebMedia%2Fmimic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PBWebMedia%2Fmimic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PBWebMedia%2Fmimic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PBWebMedia%2Fmimic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PBWebMedia","download_url":"https://codeload.github.com/PBWebMedia/mimic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230494926,"owners_count":18235047,"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":"2024-12-19T20:12:26.125Z","updated_at":"2024-12-19T20:12:26.737Z","avatar_url":"https://github.com/PBWebMedia.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mimic\n\nThis library can be used to create mimics of your classes, which can be used for (functional) testing.\n\nA mimicked class is similar to mock objects with stub methods in phpunit, but on a functional level.\n\n## Installation\n\n### Install with composer\n\nInstall mimic using composer:\n\n```\ncomposer require pbweb/mimic\n```\n\n## Example\n\nLets say you have a client class which talks to an external REST service. The interface might look like this:\n\n```php\ninterface RestClient\n{\n    public function get($something);\n    public function put($something);\n}\n```\n\nNow, using a class which really connects to the REST server in a (functional) test is a bad idea, since that server may not be in the scope of your test and influence the results.\n\nTo create a mimic client you need to extend `MimicActionHandler` like this:\n\n```php\nclass MimicRestClient extends MimicActionHandler implements RestClient\n{\n    public function get($something)\n    {\n        return $this-\u003ehandleAction(__FUNCTION__, func_get_args());\n    }\n    \n    public function put($something)\n    {\n        return $this-\u003ehandleAction(__FUNCTION__, func_get_args());\n    }\n}\n```\n\nNow you can mimic the behaviour of the `RestClient` in your tests:\n\n```php\n// In your dependency injection container:\n$mimicClient = new MimicRestClient();\n\n// In your test setup:\n$mimicClient-\u003eenqueue('get', ['cheese'], 'cheese result');\n\n// In your test or in a class which you are testing:\n$result = $mimicClient-\u003eget('cheese'); // returns 'cheese result'\n```\n\n#### Argument Matchers\nIn case you want more control over the arguments that are expected for a call, you can use argument matchers.\n\nThe `ArgumentMatchers` class instantiates several matchers which can be passed to the expected argument list of enqueue.\n```php\n// Matches any call to update that has 1 as its first argument and any value as its second argument.\n$mimicClient-\u003eenqueue('update', [1, ArgumentMatchers::any(), 'result');\n```\n\n## Usage\n\nExtending `MimicActionHandler` will allow your class to have the mimic enqueue system.\nEvery method you want to mimic should have this as the body:\n\n```php\nreturn $this-\u003ehandleAction(__FUNCTION__, func_get_args());\n```\n\nSee `tests/Service/SampleMimic` for an example.\n\n### enableQueue\n\n```php\n$mimic-\u003eenableQueue();\n```\n\n`enableQueue` will enable the use of the queue.\n\n### disableQueue\n\n```php\n$mimic-\u003edisableQueue();\n```\n\n`disableQueue` will stop the use of the queue.\n\n### isQueueEnabled\n\n```php\n$isQueueEnabled = $mimic-\u003eisQueueEnabled();\n```\n\n`isQueueEnabled` will return a boolean value with the state of the queue.\n\n### enqueue\n\n```php\n$mimic-\u003eenqueue($method, array $argumentList = [], $response = null, $throw = false);\n```\n    \n`enqueue` will add a method call to the expected queue.\nYou can add as many method prediction as you like.\nIf the next call to the mimic is the expected call then the given response will be returned and it will be removed from the queue.\nIf the next call to the mimic is not the same as the expected call added to the queue then an exception will be thrown.\n\nIf you set `throw` to `true` then the response will be thrown instead of returned.\n\n### getQueueContent\n\n```php\n$actionList = $mimic-\u003egetQueueContent();\n```\n    \n`getQueueContent` will return all the remaining actions added to the queue as Action models.\nSee the `Action` class for more information about the model.\n\n### isFinished\n\n```php\n$isFinished = $mimic-\u003eisFinished();\n```\n    \n`isFinished` will return true if there are no more action left in the queue. false otherwise.\n\n### clearQueue\n    \n```php\n$mimic-\u003eclearQueue();\n```\n    \n`clearQueue` will remove all the remaining actions from the queue.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpbwebmedia%2Fmimic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpbwebmedia%2Fmimic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpbwebmedia%2Fmimic/lists"}