PHPackages                             solcomart/aspect-mock - 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. solcomart/aspect-mock

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

solcomart/aspect-mock
=====================

Experimental Mocking Framework powered by Aspects

09PHP

Since Aug 22Pushed 8mo agoCompare

[ Source](https://github.com/solcomart/AspectMock)[ Packagist](https://packagist.org/packages/solcomart/aspect-mock)[ RSS](/packages/solcomart-aspect-mock/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

AspectMock
==========

[](#aspectmock)

AspectMock is not an ordinary PHP mocking framework. With the power of Aspect Oriented programming and the awesome [Go-AOP](https://github.com/goaop/framework) library, AspectMock allows you to stub and mock practically anything in your PHP code!

**Documentation** | [Test Doubles Builder](https://github.com/Codeception/AspectMock/blob/master/docs/Test.md) | [ClassProxy](https://github.com/Codeception/AspectMock/blob/master/docs/ClassProxy.md) | [InstanceProxy](https://github.com/Codeception/AspectMock/blob/master/docs/InstanceProxy.md) | [FuncProxy](https://github.com/Codeception/AspectMock/blob/master/docs/FuncProxy.md)

[![Actions Status](https://github.com/Codeception/AspectMock/workflows/CI/badge.svg)](https://github.com/Codeception/AspectMock/actions)[![Latest Stable Version](https://camo.githubusercontent.com/728366488639e04a706754a517369fbfad338f57df1c4b4fb0b88133a84ccd86/68747470733a2f2f706f7365722e707567782e6f72672f636f646563657074696f6e2f6173706563742d6d6f636b2f762f737461626c652e706e67)](https://packagist.org/packages/codeception/aspect-mock)[![Total Downloads](https://camo.githubusercontent.com/5f5113b3db659b00695ab172aea8ef47e08c869bb3ae1f1ff33c45bff6702826/68747470733a2f2f706f7365722e707567782e6f72672f636f646563657074696f6e2f6173706563742d6d6f636b2f646f776e6c6f616473)](https://packagist.org/packages/codeception/aspect-mock)[![Monthly Downloads](https://camo.githubusercontent.com/87f27b1d0be5745c6267b667430b840c51c3cb5f1cfd88880ac4360790f877c3/68747470733a2f2f706f7365722e707567782e6f72672f636f646563657074696f6e2f6173706563742d6d6f636b2f642f6d6f6e74686c79)](https://packagist.org/packages/codeception/aspect-mock)[![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)

Motivation
----------

[](#motivation)

PHP is a language that was not designed to be testable. Really. How would you fake the `time()` function to produce the same result for each test call? Is there any way to stub a static method of a class? Can you redefine a class method at runtime? Dynamic languages like Ruby or JavaScript allow us to do this. These features are essential for testing. AspectMock to the rescue!

Thousands of lines of untested code are written everyday in PHP. In most cases, this code is not actually bad, but PHP does not provide capabilities to test it. You may suggest rewriting it from scratch following test driven design practices and use dependency injection wherever possible. Should this be done for stable working code? Well, there are much better ways to waste time.

With AspectMock you can unit-test practically any OOP code. PHP powered with AOP incorporates features of dynamic languages we have long been missing. There is no excuse for not testing your code. You do not have to rewrite it from scratch to make it testable. Just install AspectMock with PHPUnit or Codeception and try to write some tests. It's really, really simple!

Features
--------

[](#features)

- Create test doubles for **static methods**.
- Create test doubles for **class methods called anywhere**.
- Redefine methods on the fly.
- Simple syntax that's easy to remember.

Code Pitch
----------

[](#code-pitch)

#### Allows stubbing and mocking of static methods.

[](#allows-stubbing-and-mocking-of-static-methods)

Let's redefine static methods and verify their calls at runtime.

```
