{"id":31908307,"url":"https://github.com/enzyme/parrot","last_synced_at":"2025-10-13T15:26:56.842Z","repository":{"id":56978274,"uuid":"47906410","full_name":"enzyme/parrot","owner":"enzyme","description":"Mockable native static functions for PHP.","archived":false,"fork":false,"pushed_at":"2018-10-13T20:35:10.000Z","size":22,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-01T01:09:57.776Z","etag":null,"topics":[],"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/enzyme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-13T04:48:07.000Z","updated_at":"2025-04-22T08:01:45.000Z","dependencies_parsed_at":"2022-08-21T11:50:43.442Z","dependency_job_id":null,"html_url":"https://github.com/enzyme/parrot","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/enzyme/parrot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzyme%2Fparrot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzyme%2Fparrot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzyme%2Fparrot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzyme%2Fparrot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/enzyme","download_url":"https://codeload.github.com/enzyme/parrot/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/enzyme%2Fparrot/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279015918,"owners_count":26085778,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-10-13T15:26:51.100Z","updated_at":"2025-10-13T15:26:56.837Z","avatar_url":"https://github.com/enzyme.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://cloud.githubusercontent.com/assets/2805249/11770677/3c3de7f6-a250-11e5-8145-bcb9fb8c27cb.png\" width=\"200\"\u003e\n\n[![Build Status](https://travis-ci.org/enzyme/parrot.svg?branch=master)](https://travis-ci.org/enzyme/parrot)\n\nMockable native static functions for PHP.\n\n# What is it?\n\nDo you have a class method that calls a PHP native/built-in function like `file_get_contents`, which you then test by having to create a dummy file for it to ingest? Well, say hello to **Parrot**. Now you can inject the built-in File functions, along with many others as a dependency which you can mock out during tests.\n\n# Installation\n\n```bash\ncomposer require enzyme/parrot\n```\n\n# Example\n\nLet's take a look at what used to happen:\n\n#### Using the built in method.\n\n```php\nclass Foo\n{\n    public function openConfig($file)\n    {\n        $contents = file_get_contents($file);\n        return $contents;\n    }\n}\n```\n\nTesting...\n\n```php\npublic function FooTest\n{\n    $file = __DIR__ . '/actual_file.txt';\n    $expected = 'Contents of actual_file.txt';\n\n    $foo = new Foo;\n    $actual = $foo-\u003eopenConfig($file);\n\n    $this-\u003eassertEquals($actual, $expected);\n}\n```\n\nThe problem with the above is, `actual_file.txt` needs to reside in your test folder, get shipped with your tests, have the correct permission etc... it's a hassle.\n\n#### Now using Parrot.\n\n```php\nuse Enzyme\\Parrot\\File;\n\nclass Foo\n{\n    protected $fileDispatch;\n\n    public function __construct(File $fileDispatch)\n    {\n        $this-\u003efileDispatch = $fileDispatch;\n    }\n\n    public function openConfig($file)\n    {\n        $contents = $this-\u003efileDispatch-\u003egetContents($file);\n        return $contents;\n    }\n}\n```\n\nTesting...\n\n```php\npublic function FooTest\n{\n    $file = __DIR__ . '/fake_file.txt';\n    $expected = 'Contents of fake_file.txt';\n\n    $fileDispatch = m::mock('Enzyme\\Parrot\\File[getContents]', function ($mock) use ($expected, $file) {\n        $mock-\u003eshouldReceive('getContents')-\u003ewithArgs([$file, []])-\u003etimes(1)-\u003eandReturn($expected);\n    });\n\n\n    $foo = new Foo($fileDispatch);\n    $actual = $foo-\u003eopenConfig($file);\n\n    $this-\u003eassertEquals($actual, $expected);\n}\n```\n\nNow we just fake the file and it's contents, sweet!!!\n\n# Sugar\n\nYou may have noticed in the above example that the Parrot version of `file_get_contents` was simply `getContents()`.\n\nWith all the Parrot'd wrappers around PHP's functions, we leave off the prefix. Who wants to repeat themselves?\n\n#### The function name rules.\n\n1. If the original function name starts with a prefix like `file_`, `f`, `curl_`, `imap_`, `mysql_` etc, you simply leave them off when using the equivalent class wrapper.\n\n2. If the original name has an underscore in it, replace it with camelCase. So for example `file_get_contents` becomes `getContents` and `mysql_affected_rows` becomes `affectedRows`.\n\n3. If the original name has a string of words, they are converted to camelCase too. For example `imap_createmailbox` becomes `createMailbox`.\n\n4. If the original function, following the rules above now starts with a number, replace then number with it's spelt equivalent. For example `imap_8bit` becomes `eightBit`.\n\n# Wrappers\n\nThe follow wrappers are currently available:\n\nName | Prefixes removed\n-----|-----------------\nCurl | curl_\nFile | file, file_, f\nFtp  | ftp_\nGz   | gz\nImage | image\nImap | imap_\nMySql | mysql_\nPostgreSql | pg_\nSqlite | sqlite_\nGlob | glob (Simply becomes `execute`)\n\n# Missing something?\n\nIf there's a particular wrapper you're looking for and it isn't listed above, open a new issue, or simply extend `Parrot` following the rules in the existing wrappers and send a PR. Please check out `CONTRIBUTING.md` as well.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenzyme%2Fparrot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenzyme%2Fparrot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenzyme%2Fparrot/lists"}