PHPackages                             rezen/proxyz - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. rezen/proxyz

ActiveLibrary[Testing &amp; Quality](/categories/testing)

rezen/proxyz
============

A library to make it easier to change native php functions behaviour

1.10(4y ago)419MITPHPPHP &gt;=7.2.5

Since Aug 26Pushed 4y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (3)Versions (19)Used By (0)

proxyz
======

[](#proxyz)

[![Latest Stable Version](https://camo.githubusercontent.com/bad8c46a4bd5bd28348c57864977ef182ce236d99786f33e8f766d55e907337a/68747470733a2f2f706f7365722e707567782e6f72672f72657a656e2f70726f78797a2f76)](//packagist.org/packages/rezen/proxyz)

If you are trying to test a PHP application and want to override `file_get_contents` response, you're in for a heap of fun (okay, so not fun). Really, any function that interacts with stateful bits is annoying. PHP has so many functions (not objects) that are in the global namespace that make testing hard. Also if you are writing a plugin for WordPress, you are using functions in the global namespace which you can not overwrite. To mitigate some of this pain, what you need is a method proxy. A method proxy will allow you to override or watch the behaviour of a function in the global namespace effortlessly.

Install
-------

[](#install)

`composer require rezen/proxyz`

Example
-------

[](#example)

In your app, wherever you init and configure things, add a wrapper

```
// Wrap around the file_get_contents method
\Proxyz\addWrapper('file_get_contents', function($args, $fn) {
    if ($args[0] === "config.json") {
        return "{}";
    }
    return call_user_func_array($fn, $args);
});

// Force curl to pin the ip down
\Proxyz\addOverride('curl_init', function($url=null) {
    if (is_null($url)) {
        return curl_init($url);
    }

    $host = parse_url($url, PHP_URL_HOST);
    $ip = gethostbyname($host);

    if (in_array($ip, ['127.0.0.1', '169.254.169.254'])) {
        throw new \Exception("Requests to internal IPs are not allowed");
    }
    $resource = curl_init($url);
    curl_setopt($resource, CURLOPT_RESOLVE, [
        "{$host}:443:{$ip}",
        "{$host}:80:{$ip}",
    ]);
    return $resource;
});
```

Wherever you need to override the `file_get_contents`, import the namespaced function.

```
use function \Proxyz\Php\Filesystem\file_get_contents;
use function \Proxyz\Php\Curl\{curl_init, curl_setopt, curl_exec};

$config = file_get_contents("config.json");
```

Override a class when need be!

```
\Proxyz\addOverride(\SplFileInfo::class, \Sample\Dance::class);
$instance = \Proxyz\newInstance(\SplFileInfo::class, [$first]);
\Sample\Dance::class === get_class($instance);
```

Testing
-------

[](#testing)

```
composer install
# Unit tests
./vendor/bin/phpunit  -d memory_limit=1024M --testdox ./test/tests/

# Performance of functions
php test/performance.php
```

Todo
----

[](#todo)

- Code rewriter for detecting native functions and adding `use` imports
- Improve WordPress references
    - Currently ~20+ functions have variable references
        - `ag --php '\&\$' --ignore *class* --nofilename | awk '$1=$1'  | grep '^function' | grep '_' | grep -v 'tion _' | grep -v sodium | cut -d ' ' -f2 | cut -d'(' -f1 | sort | uniq`
        - **Functions**
            - add\_comment\_to\_entry
            - crypto\_generichash\_final
            - crypto\_generichash\_update
            - feed\_start\_element
            - get\_page\_hierarchy
            - merge\_originals\_with
            - merge\_with
            - recurse\_dirsize
            - separate\_comments
            - translate\_entry
            - update\_page\_cache
            - update\_post\_cache
            - update\_post\_caches
            - wp\_add\_id3\_tag\_data
            - wp\_cache\_get
            - wp\_get\_post\_revision
            - wp\_getimagesize
            - wp\_handle\_sideload
            - wp\_handle\_upload
            - wp\_handle\_upload\_error
            - wp\_kses\_attr\_check
            - wp\_parse\_str

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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 ~19 days

Recently: every ~0 days

Total

18

Last Release

1760d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c592beedc269a22b4c31e85617f1b5aa3245ffef2b08f7fd44aff875cbd8101?d=identicon)[rezen](/maintainers/rezen)

---

Top Contributors

[![rezen](https://avatars.githubusercontent.com/u/465024?v=4)](https://github.com/rezen "rezen (43 commits)")

---

Tags

phpproxytestingtestingproxy

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rezen-proxyz/health.svg)

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

###  Alternatives

[phpunit/phpunit

The PHP Unit Testing framework.

20.0k910.7M134.8k](/packages/phpunit-phpunit)[phpunit/php-code-coverage

Library that provides collection, processing, and rendering functionality for PHP code coverage information.

8.9k892.4M1.5k](/packages/phpunit-php-code-coverage)[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/packages/mockery-mockery)[behat/behat

Scenario-oriented BDD framework for PHP

4.0k96.8M2.0k](/packages/behat-behat)[symfony/phpunit-bridge

Provides utilities for PHPUnit, especially user deprecation notices management

2.5k201.2M4.2k](/packages/symfony-phpunit-bridge)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)

PHPackages © 2026

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