{"id":21053507,"url":"https://github.com/etcinit/mockingbird","last_synced_at":"2025-05-15T21:36:41.914Z","repository":{"id":56976083,"uuid":"78693615","full_name":"etcinit/mockingbird","owner":"etcinit","description":"A DSL for mocking dependencies on PHP unit tests","archived":true,"fork":false,"pushed_at":"2017-03-08T17:46:26.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-13T23:29:52.917Z","etag":null,"topics":["dependency-injection","dsl","ioc","mocking"],"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/etcinit.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-01-12T00:45:12.000Z","updated_at":"2024-01-16T01:18:42.000Z","dependencies_parsed_at":"2022-08-21T11:20:42.135Z","dependency_job_id":null,"html_url":"https://github.com/etcinit/mockingbird","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etcinit%2Fmockingbird","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etcinit%2Fmockingbird/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etcinit%2Fmockingbird/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/etcinit%2Fmockingbird/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/etcinit","download_url":"https://codeload.github.com/etcinit/mockingbird/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254425816,"owners_count":22069239,"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":["dependency-injection","dsl","ioc","mocking"],"created_at":"2024-11-19T16:06:59.987Z","updated_at":"2025-05-15T21:36:41.568Z","avatar_url":"https://github.com/etcinit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mockingbird\n\nA DSL for mocking dependencies on PHP unit tests\n\n## Features:\n\n- Acts like a mini IoC container for your unit tests.\n- Automatically creates mocks for your class' dependencies.\n- Supports injecting dependencies through the constructor and methods.\n- Provides a DSL on top of Mockery for quickly mocking dependencies.\n- You can provide real/non-mock instances and scalar arguments.\n- Works with Laravel!\n\n## Requirements\n\n- PHP 7 or higher.\n- Composer\n\n## Installation\n\nRun `composer require chromabits/mockingbird` on a Composer project.\n\n## Quick Example:\n\n```php\n\u003c?php\n\ninclude_once __DIR__ . '/../vendor/autoload.php';\n\n// Mockingbird is available as a set of functions, which you can import into\n// your current scope.\nuse function Mockingbird\\{ stage, on };\n\n// We begin by defining the classes which will act as our dependencies for this\n// example.\nclass DependencyA {\n    private $prefix;\n\n    public function __construct(string $prefix)\n    {\n        $this-\u003eprefix = $prefix;\n    }\n\n    public function getPrefix(): string { return $this-\u003eprefix; }\n};\nclass DependencyB {};\nclass DependencyC {\n    public function sayWorld(string $postfix): string {\n        return 'world' . $postfix;\n    }\n}\n\n// We also define our service class which will consume these dependencies\n// through constructor-based and method-based dependency injection.\nclass Service {\n    /**\n     * @var DependencyA\n     */\n    private $a;\n\n    public function __construct(DependencyA $a, DependencyB $b) {\n        $this-\u003ea = $a;\n    }\n\n    public function targetMethod(DependencyC $c): string\n    {\n        return $this-\u003ea-\u003egetPrefix() . 'hello ' . $c-\u003esayWorld('!');\n    }\n};\n\n// Our Service class has three dependencies, two services injected through the\n// constructor and one passed on the called method. We will build a stage that\n// provides them for us:\n//\n// - DependencyA: We will pass down a real instance (not a mock).\n// - DependencyB: We will let Stage auto-mock it for us.\n// - DependencyC: We will manually create our own mock.\n//\n$result = stage()\n    -\u003eprovide(new DependencyA('\u003e\u003e\u003e '))\n    -\u003emock(DependencyC::class, [\n        on('sayWorld', ['!'], 'worlds!!!'),\n    ])\n    -\u003emakeAndCall(Service::class, 'targetMethod');\n\n// Should output \"\u003e\u003e\u003e hello worlds!!!\"\necho $result;\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fetcinit%2Fmockingbird","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fetcinit%2Fmockingbird","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fetcinit%2Fmockingbird/lists"}