PHPackages                             xepozz/internal-mocker - 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. xepozz/internal-mocker

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

xepozz/internal-mocker
======================

1.4.1(1y ago)3364.3k↑17.7%1[1 PRs](https://github.com/xepozz/internal-mocker/pulls)7PHP

Since Apr 15Pushed 1y ago3 watchersCompare

[ Source](https://github.com/xepozz/internal-mocker)[ Packagist](https://packagist.org/packages/xepozz/internal-mocker)[ RSS](/packages/xepozz-internal-mocker/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (9)Used By (7)

Introduction
============

[](#introduction)

The package helps mock internal php functions as simple as possible. Use this package when you need mock such functions as: `time()`, `str_contains()`, `rand`, etc.

[![Latest Stable Version](https://camo.githubusercontent.com/0c28887828c1e6a71d15467e62c50c71f6a0586733f643c41188f48d65e41493/68747470733a2f2f706f7365722e707567782e6f72672f7865706f7a7a2f696e7465726e616c2d6d6f636b65722f762f737461626c652e737667)](https://packagist.org/packages/xepozz/internal-mocker)[![Total Downloads](https://camo.githubusercontent.com/525f6c3b87e5ade53e569e033e80c11a0955cb135744c92d1f9eda087f564e9b/68747470733a2f2f706f7365722e707567782e6f72672f7865706f7a7a2f696e7465726e616c2d6d6f636b65722f646f776e6c6f6164732e737667)](https://packagist.org/packages/xepozz/internal-mocker)[![phpunit](https://github.com/xepozz/internal-mocker/workflows/PHPUnit/badge.svg)](https://github.com/xepozz/internal-mocker/actions)

Table of contents
=================

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Register a PHPUnit Extension](#register-a-phpunit-extension)
        - [PHPUnit 9](#phpunit-9)
        - [PHPUnit 10 and higher](#phpunit-10-and-higher)
    - [Register mocks](#register-mocks)
        - [Runtime mocks](#runtime-mocks)
        - [Pre-defined mock](#pre-defined-mock)
        - [Mix of two previous ways](#mix-of-two-previous-ways)
    - [State](#state)
    - [Tracking calls](#tracking-calls)
- [Global namespaced functions](#global-namespaced-functions)
    - [Internal functions](#internal-functions)
        - [Internal function implementation](#internal-function-implementation)
- [Restrictions](#restrictions)
    - [Data Providers](#data-providers)

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

[](#installation)

```
composer require xepozz/internal-mocker --dev
```

Usage
-----

[](#usage)

The main idea is pretty simple: register a Listener for PHPUnit and call the Mocker extension first.

### Register a PHPUnit Extension

[](#register-a-phpunit-extension)

#### PHPUnit 9

[](#phpunit-9)

1. Create new file `tests/MockerExtension.php`
2. Paste the following code into the created file: ```
