PHPackages                             nunomaduro/mock-final-classes - 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. nunomaduro/mock-final-classes

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

nunomaduro/mock-final-classes
=============================

Allows mocking of final methods and classes in PHP.

v1.2.0(3y ago)113854.3k—5.6%5[1 PRs](https://github.com/nunomaduro/mock-final-classes/pulls)19MITPHPPHP ^7.1 || ^8.0CI failing

Since Jun 5Pushed 2y ago2 watchersCompare

[ Source](https://github.com/nunomaduro/mock-final-classes)[ Packagist](https://packagist.org/packages/nunomaduro/mock-final-classes)[ Fund](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L)[ GitHub Sponsors](https://github.com/nunomaduro)[ RSS](/packages/nunomaduro-mock-final-classes/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (4)Used By (19)

 [![Mock final classes example](https://raw.githubusercontent.com/nunomaduro/mock-final-classes/master/docs/doc.png)](https://raw.githubusercontent.com/nunomaduro/mock-final-classes/master/docs/doc.png)

 [![Build Status](https://camo.githubusercontent.com/a587bbb76c61946a0fbc66eb8a193aeaa42a39e3cc2f8d580f41bdce4456841e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6e756e6f6d616475726f2f6d6f636b2d66696e616c2d636c61737365732f6d61737465722e737667)](https://travis-ci.org/nunomaduro/mock-final-classes) [![Total Downloads](https://camo.githubusercontent.com/c470d422873b720367f81fc2501ff8266b8522614d27cc48ce043d23c2728ff7/68747470733a2f2f706f7365722e707567782e6f72672f6e756e6f6d616475726f2f6d6f636b2d66696e616c2d636c61737365732f642f746f74616c2e737667)](https://packagist.org/packages/nunomaduro/mock-final-classes) [![Latest Version](https://camo.githubusercontent.com/04a9703c1df2d072a70fe7e9e03a84fef0d096212c50a7a8b3f57557c6e21e37/68747470733a2f2f706f7365722e707567782e6f72672f6e756e6f6d616475726f2f6d6f636b2d66696e616c2d636c61737365732f762f737461626c652e737667)](https://packagist.org/packages/nunomaduro/mock-final-classes) [![License](https://camo.githubusercontent.com/c4f602f78825016e78ef795ef6a61b2aa18ed368a803bf4d4cdeed5efe5a0030/68747470733a2f2f706f7365722e707567782e6f72672f6e756e6f6d616475726f2f6d6f636b2d66696e616c2d636c61737365732f6c6963656e73652e737667)](https://packagist.org/packages/nunomaduro/mock-final-classes)

 Created by, and is maintained by **[Nuno Maduro](https://twitter.com/enunomaduro)**, and once installed it automatically **allows mocking of final methods and classes**.

💡 Installation &amp; Usage
--------------------------

[](#-installation--usage)

> **Requires [PHP 7.1+](https://php.net/releases/)**

First, install the package using [Composer](https://getcomposer.org):

```
composer require --dev nunomaduro/mock-final-classes
```

**That's it! You can now mock final methods and classes.** 🏄‍♂️

🤯 How it works?
---------------

[](#-how-it-works)

1. First, we run the file [autoload.php](https://github.com/nunomaduro/mock-final-classes/blob/master/autoload.php) using [Composer Autoload](https://github.com/nunomaduro/mock-final-classes/blob/8628de25120b6106421d7730457c45ac668ecef9/composer.json#L35).
2. Then, we determine if you are running a supported test framework
    - [ParaTest](https://github.com/nunomaduro/mock-final-classes/blob/master/src/Frameworks/ParaTest.php)
    - [Pest](https://github.com/nunomaduro/mock-final-classes/blob/master/src/Frameworks/Pest.php)
    - [PHPUnit](https://github.com/nunomaduro/mock-final-classes/blob/master/src/Frameworks/PhpUnit.php)
3. Then, we use the library [dg/bypass-finals](https://github.com/dg/bypass-finals) to remove final keywords from source code on-the-fly: [https://github.com/nunomaduro/mock-final-classes/src/Runner.php#L31](https://github.com/nunomaduro/mock-final-classes/blob/8628de25120b6106421d7730457c45ac668ecef9/src/Runner.php#L31).

👏🏻 Credits
----------

[](#-credits)

Most of the work is done by the library [dg/bypass-finals](https://github.com/dg/bypass-finals), so make sure you support the maintainer here: [Donate](https://nette.org/make-donation?to=bypass-finals). Thank you!

---

Mock Final Classes is an open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity53

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 76.9% 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 ~719 days

Total

3

Last Release

1100d ago

PHP version history (2 changes)v1.0.0PHP ^7.1

v1.1.0PHP ^7.1 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/86cfef5c1f5195df1a9db17a5f8ecb34455e1f0133a725de9acf7f2fb26ac6a1?d=identicon)[nunomaduro](/maintainers/nunomaduro)

---

Top Contributors

[![nunomaduro](https://avatars.githubusercontent.com/u/5457236?v=4)](https://github.com/nunomaduro "nunomaduro (20 commits)")[![Synchro](https://avatars.githubusercontent.com/u/81561?v=4)](https://github.com/Synchro "Synchro (4 commits)")[![moussaclarke](https://avatars.githubusercontent.com/u/13017858?v=4)](https://github.com/moussaclarke "moussaclarke (1 commits)")[![tscni](https://avatars.githubusercontent.com/u/32767367?v=4)](https://github.com/tscni "tscni (1 commits)")

---

Tags

phpphpunitmockclassclassesfinal

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/nunomaduro-mock-final-classes/health.svg)

```
[![Health](https://phpackages.com/badges/nunomaduro-mock-final-classes/health.svg)](https://phpackages.com/packages/nunomaduro-mock-final-classes)
```

###  Alternatives

[blastcloud/guzzler

Supercharge your app or SDK with a testing library specifically for Guzzle.

272419.3k35](/packages/blastcloud-guzzler)[letsdrink/ouzo-goodies

Utility classes, test assertions and mocking framework extracted from Ouzo framework.

132617.9k7](/packages/letsdrink-ouzo-goodies)[quizlet/hammock

Hammock is a stand-alone mocking library for Hacklang.

27445.5k](/packages/quizlet-hammock)[janmarek/mockista

Mockista is library for mocking, which I've written, because I find mocking in PHPUnit awful.

29221.0k28](/packages/janmarek-mockista)[doppiogancio/mocked-client

A simple way to mock a client

2174.9k3](/packages/doppiogancio-mocked-client)[robiningelbrecht/phpunit-coverage-tools

PHPUnit coverage tools

1783.0k34](/packages/robiningelbrecht-phpunit-coverage-tools)

PHPackages © 2026

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