{"id":19312126,"url":"https://github.com/bigcommerce/mock-injector","last_synced_at":"2025-10-28T21:16:45.958Z","repository":{"id":46249163,"uuid":"78925484","full_name":"bigcommerce/mock-injector","owner":"bigcommerce","description":"Auto-mocking dependencies for DI components testing.","archived":false,"fork":false,"pushed_at":"2024-07-30T06:53:41.000Z","size":120,"stargazers_count":3,"open_issues_count":0,"forks_count":9,"subscribers_count":120,"default_branch":"master","last_synced_at":"2024-10-01T08:07:21.859Z","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/bigcommerce.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-14T07:40:41.000Z","updated_at":"2024-07-30T06:02:56.000Z","dependencies_parsed_at":"2024-05-18T02:28:38.508Z","dependency_job_id":"b221ab2b-dcd0-46da-ba4e-224c8ca2607f","html_url":"https://github.com/bigcommerce/mock-injector","commit_stats":{"total_commits":40,"total_committers":9,"mean_commits":4.444444444444445,"dds":0.7,"last_synced_commit":"be1d3ccdb681bd664fd7e15afd44590c2dcbfb0b"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigcommerce%2Fmock-injector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigcommerce%2Fmock-injector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigcommerce%2Fmock-injector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigcommerce%2Fmock-injector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigcommerce","download_url":"https://codeload.github.com/bigcommerce/mock-injector/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223900372,"owners_count":17222028,"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-11-10T00:32:56.834Z","updated_at":"2025-10-16T20:38:25.601Z","avatar_url":"https://github.com/bigcommerce.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bigcommerce/mock-injector \n[![Build Status](https://scrutinizer-ci.com/g/bigcommerce/mock-injector/badges/build.png?b=master\u0026s=6b0bd1c0db716ba85e2c12a64d640ab1a4d85369)](https://scrutinizer-ci.com/g/bigcommerce/mock-injector/build-status/master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/bigcommerce/mock-injector/badges/quality-score.png?b=master\u0026s=c0811fd76bcb31f9e73a0beb8114e5de34d9f0ca)](https://scrutinizer-ci.com/g/bigcommerce/mock-injector/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/bigcommerce/mock-injector/badges/coverage.png?b=master\u0026s=a592e4140397a936727ce28d598ca19078aa0a64)](https://scrutinizer-ci.com/g/bigcommerce/mock-injector/?branch=master)\n\n\nAuto-mocking test Dependency Injector component\n\nWill automatically mock all injected dependencies of an object using the BigCommerce Injector. This allows objects to be\nrefactored to have dependencies removed or new ones added without needing to rebuild all the mock definitions or modify\nmany tests, making decoupled DI driven development much easier.\n\nMocks can be configured with expectations by calling getMock(CLASS_NAME) on the TestInjector within your tests. This \nwill return an ObjectProphecy object (a mock generated by Prophecy - the mocking library included in PHPUnit).\n\nA single mock instance is created per Fully Qualified Class Name, so if the object you're testing takes two of the same\ntyped parameter, the same mock will be passed to both (so ensure your expectations are set appropriately).\n\nConstruction Usage:\n````\n// All constructor dependencies resolved through mocking\n$testObject = $testInjector-\u003ecreate(My\\Test\\Object::class); \n\n// Parameter injection - will provide parameters either by type, name or position - otherwise resolve via mocking\n$testObject = $testInjector-\u003ecreate(My\\Test\\Object::class, [\n    \"enabled\" =\u003e true,              // Named\n    7 =\u003e \"fish\",                    // Positional\n    Logger::class =\u003e new Logger(),  // Type\n]);\n````\n\nInvocation usage\n````\n// Call the method 'createUser' on an existing object\n$result = $testInjector-\u003einvoke($instanceOfThing, \"createUser\");\n\n// Parameter injection - will provide parameters either by type, name or position - otherwise resolve via mocking\n$result = $testInjector-\u003einvoke($instanceOfThing, \"createUser\", [\n    \"enabled\" =\u003e true,              // Named\n    7 =\u003e \"fish\",                    // Positional\n    Logger::class =\u003e new Logger(),  // Type\n]);\n````\n\n\nFor integration with your PHPUnit tests, see: [AutoMockingTest.php](src/AutoMockingTest.php) \n\n\n(The MIT License)\nCopyright (C) 2015-2017 BigCommerce Inc.\nAll rights reserved.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\ndocumentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\nrights to use, copy, modify, merge, publish, distribute, sublicense,and/or sell copies of the Software, and to permit\npersons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the\nSoftware.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\nWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\nOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigcommerce%2Fmock-injector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigcommerce%2Fmock-injector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigcommerce%2Fmock-injector/lists"}