Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nunomaduro/mock-final-classes

🏄‍♂️ Allows mocking final classes in PHP.
https://github.com/nunomaduro/mock-final-classes

Last synced: 2 days ago
JSON representation

🏄‍♂️ Allows mocking final classes in PHP.

Awesome Lists containing this project

README

        


Mock final classes example


Build Status
Total Downloads
Latest Version
License


Created by, and is maintained by Nuno Maduro, and once installed it automatically allows mocking of final methods and classes.

## 💡 Installation & Usage

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

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

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

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

## 🤯 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

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).