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)114981.2k↓19.7%5[2 PRs](https://github.com/nunomaduro/mock-final-classes/pulls)19MITPHPPHP ^7.1 || ^8.0CI passing

Since Jun 5Pushed 1w 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 2d ago

READMEChangelog (1)Dependencies (6)Versions (6)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) [![YouTube Channel Subscribers](https://camo.githubusercontent.com/a32a48cc6ec1283f38f5beedd4f3aec3eff914f663007ce9295ab1b60e5507e2/68747470733a2f2f696d672e736869656c64732e696f2f796f75747562652f6368616e6e656c2f73756273637269626572732f55434f5f68595a463267625f4379473573413741726c47673f7374796c653d666c6174266c6162656c3d796f757475626526636f6c6f723d627269676874677265656e)](https://youtube.com/@nunomaduro?sub_confirmation=1)

 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

57

—

FairBetter than 98% of packages

Maintenance64

Regular maintenance activity

Popularity53

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 68.6% 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

1146d 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 (24 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 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)")[![nunolaraveltestaccount](https://avatars.githubusercontent.com/u/106339258?v=4)](https://github.com/nunolaraveltestaccount "nunolaraveltestaccount (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.

272470.1k42](/packages/blastcloud-guzzler)[letsdrink/ouzo-goodies

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

129656.1k11](/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.

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

A simple way to mock a client

1975.9k5](/packages/doppiogancio-mocked-client)[lastzero/test-tools

Increases testing productivity by adding a service container and self-initializing fakes to PHPUnit

2244.5k13](/packages/lastzero-test-tools)

PHPackages © 2026

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