PHPackages                             qratorlabs/smocky - 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. qratorlabs/smocky

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

qratorlabs/smocky
=================

Mocking library based on runkit

1.3.2(4mo ago)48.7k[1 PRs](https://github.com/QratorLabs/Smocky/pulls)1MITPHPPHP ^7.1 || ^8.0CI passing

Since Feb 19Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/QratorLabs/Smocky)[ Packagist](https://packagist.org/packages/qratorlabs/smocky)[ Docs](https://github.com/QratorLabs/Smocky)[ RSS](/packages/qratorlabs-smocky/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (3)Versions (20)Used By (1)

Mock static methods
===================

[](#mock-static-methods)

...and a bit more ;)

Goals
=====

[](#goals)

- easy mocking
- make any changes revertible
- revert changes automatically

Targets
=======

[](#targets)

There are several classes that will do the work:

- For class methods:
    - `MockedClassMethod` to mock any class with closure
    - `UndefinedClassMethod` to make method disappear
- For class constants:
    - `MockedClassConstant`
    - `UndefinedClassConstant`
- For global constants:
    - `MockedGlobalConstant`
    - `UndefinedGlobalConstant`
- For functions (global or Namespaced):
    - `MockedFunction`
    - `UndefinedFunction`

Install
=======

[](#install)

```
composer require --dev qratorlabs/smocky
```

### Note

[](#note)

There is a workaround that ensures that any (defined) children of class, which method is mocking, have its own method, defined by user or mocked (by Smocky - closure that calls parent).

Example for code that will fail without this workaround following code will end up with `Segmentation fault: 11`

```
class Base
{
    public static function methodName()
    {
        return 'something';
    }
}

class Child extends Base
{

}

// simulating PHPUnit test case
(new class('test') extends \PHPUnit\Framework\TestCase {

    public function test(): void
    {
        // child should instanced (or loaded any other way)
        $child = new Child();
        // mocking method of base class
        $method = new MockedClassMethod(Base::class, 'methodName');
        // at least one call should be made
        Base::methodName();
    }
})->run();
```

Trivia
======

[](#trivia)

Revertible changes
------------------

[](#revertible-changes)

All changes are made revertible by using internal storage and `__destruct` methods.

Drawbacks
---------

[](#drawbacks)

Thing to keep in mind before using:

- Mocking anything will hit memory consumption (ex. to preserve changes)
- Mocking methods will hit performance (a bit)
- To mock static class we must check (and mock) children of mocking class

Powered by
==========

[](#powered-by)

- [runkit7](https://github.com/runkit7/runkit7)
- [phpunit](https://github.com/sebastianbergmann/phpunit)

Tested with
===========

[](#tested-with)

- [phpunit](https://github.com/sebastianbergmann/phpunit)
- [phpstan](https://github.com/phpstan/phpstan)
- [PHP\_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance82

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity67

Established project with proven stability

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

Recently: every ~92 days

Total

18

Last Release

144d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4123596?v=4)[Ilia Urvachev](/maintainers/rtm-ctrlz)[@rtm-ctrlz](https://github.com/rtm-ctrlz)

---

Top Contributors

[![rtm-ctrlz](https://avatars.githubusercontent.com/u/4123596?v=4)](https://github.com/rtm-ctrlz "rtm-ctrlz (43 commits)")

---

Tags

helpermockmocking-methodsphpphpunitrunkit7testing

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/qratorlabs-smocky/health.svg)

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

###  Alternatives

[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14429.2M360](/packages/dms-phpunit-arraysubset-asserts)

PHPackages © 2026

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