PHPackages                             enzyme/parrot - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. enzyme/parrot

ActiveLibrary

enzyme/parrot
=============

Mockable native static functions for PHP.

v0.0.2(9y ago)02441[1 issues](https://github.com/enzyme/parrot/issues)[1 PRs](https://github.com/enzyme/parrot/pulls)MITPHPPHP &gt;=5.5.0

Since Dec 14Pushed 7y ago1 watchersCompare

[ Source](https://github.com/enzyme/parrot)[ Packagist](https://packagist.org/packages/enzyme/parrot)[ Docs](https://github.com/enzyme/parrot)[ RSS](/packages/enzyme-parrot/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

[![](https://cloud.githubusercontent.com/assets/2805249/11770677/3c3de7f6-a250-11e5-8145-bcb9fb8c27cb.png)](https://cloud.githubusercontent.com/assets/2805249/11770677/3c3de7f6-a250-11e5-8145-bcb9fb8c27cb.png)

[![Build Status](https://camo.githubusercontent.com/5083cd6516713635ac03157c01ef2404c0f2d7955668d5af8ef9b6adb2e14e7a/68747470733a2f2f7472617669732d63692e6f72672f656e7a796d652f706172726f742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/enzyme/parrot)

Mockable native static functions for PHP.

What is it?
===========

[](#what-is-it)

Do 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.

Installation
============

[](#installation)

```
composer require enzyme/parrot
```

Example
=======

[](#example)

Let's take a look at what used to happen:

#### Using the built in method.

[](#using-the-built-in-method)

```
class Foo
{
    public function openConfig($file)
    {
        $contents = file_get_contents($file);
        return $contents;
    }
}
```

Testing...

```
public function FooTest
{
    $file = __DIR__ . '/actual_file.txt';
    $expected = 'Contents of actual_file.txt';

    $foo = new Foo;
    $actual = $foo->openConfig($file);

    $this->assertEquals($actual, $expected);
}
```

The 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.

#### Now using Parrot.

[](#now-using-parrot)

```
use Enzyme\Parrot\File;

class Foo
{
    protected $fileDispatch;

    public function __construct(File $fileDispatch)
    {
        $this->fileDispatch = $fileDispatch;
    }

    public function openConfig($file)
    {
        $contents = $this->fileDispatch->getContents($file);
        return $contents;
    }
}
```

Testing...

```
public function FooTest
{
    $file = __DIR__ . '/fake_file.txt';
    $expected = 'Contents of fake_file.txt';

    $fileDispatch = m::mock('Enzyme\Parrot\File[getContents]', function ($mock) use ($expected, $file) {
        $mock->shouldReceive('getContents')->withArgs([$file, []])->times(1)->andReturn($expected);
    });

    $foo = new Foo($fileDispatch);
    $actual = $foo->openConfig($file);

    $this->assertEquals($actual, $expected);
}
```

Now we just fake the file and it's contents, sweet!!!

Sugar
=====

[](#sugar)

You may have noticed in the above example that the Parrot version of `file_get_contents` was simply `getContents()`.

With all the Parrot'd wrappers around PHP's functions, we leave off the prefix. Who wants to repeat themselves?

#### The function name rules.

[](#the-function-name-rules)

1. 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.
2. 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`.
3. If the original name has a string of words, they are converted to camelCase too. For example `imap_createmailbox` becomes `createMailbox`.
4. 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`.

Wrappers
========

[](#wrappers)

The follow wrappers are currently available:

NamePrefixes removedCurlcurl\_Filefile, file\_, fFtpftp\_GzgzImageimageImapimap\_MySqlmysql\_PostgreSqlpg\_Sqlitesqlite\_Globglob (Simply becomes `execute`)Missing something?
==================

[](#missing-something)

If 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.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~157 days

Total

2

Last Release

3642d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/148afe40f056b8f57e43ed0505c6040f762e26805b1d1bebed87484d529bae07?d=identicon)[r3oath](/maintainers/r3oath)

---

Top Contributors

[![r3oath](https://avatars.githubusercontent.com/u/2805249?v=4)](https://github.com/r3oath "r3oath (11 commits)")

---

Tags

phpstaticfunctionsprimitivesenzymeparrotmockable

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/enzyme-parrot/health.svg)

```
[![Health](https://phpackages.com/badges/enzyme-parrot/health.svg)](https://phpackages.com/packages/enzyme-parrot)
```

###  Alternatives

[phan/phan

A static analyzer for PHP

5.6k11.2M1.1k](/packages/phan-phan)[nilportugues/php_todo

Looks into the code using a user-defined list of to-do phrases and stops commit if the total amount increased or is above a threshold.

1210.0k](/packages/nilportugues-php-todo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
