PHPackages                             unit-testing/function-spy - 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. unit-testing/function-spy

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

unit-testing/function-spy
=========================

a testing utility for phpunit that helps test globally defined functions

v1.0.0(11y ago)1464MITPHPPHP &gt;=5.4.0

Since Feb 27Pushed 11y ago1 watchersCompare

[ Source](https://github.com/unit-testing/function-spy)[ Packagist](https://packagist.org/packages/unit-testing/function-spy)[ RSS](/packages/unit-testing-function-spy/feed)WikiDiscussions master Synced 1mo ago

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

UnitTesting\\FunctionSpy
========================

[](#unittestingfunctionspy)

Sometimes you want to unit test a global or native PHP method, especially when working with a package that has a bunch of globally defined functions (like Wordpress).

Inspiration was taken from javascript testing module: .

Installation
------------

[](#installation)

- `composer require --dev unit-testing/function-spy:dev-master`
- Or, require the module in your `composer.json` like this: `"require-dev": { "unit-testing/function-spy": "dev-master" }` and run `composer update`

### Spy

[](#spy)

The `Spy` class is a static container that fires up an instance of `Registry`. It has one defined static method `instance` to instantiate or to get the bound instance of `Registry`. All other static calls are forwarded onto the `Registry` instance.

You will only ever need to use the static method when mocking a function or class method you're trying to test:

```
