The most powerful and flexible mocking framework for PHPUnit / Codeception.

Related tags

Testing AspectMock
Overview

AspectMock

AspectMock is not an ordinary PHP mocking framework. With the power of Aspect Oriented programming and the awesome Go-AOP library, AspectMock allows you to stub and mock practically anything in your PHP code!

Documentation | Test Doubles Builder | ClassProxy | InstanceProxy | FuncProxy

Build Status Latest Stable Version Total Downloads Monthly Downloads PHP 7 ready

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

  • 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

Allows stubbing and mocking of static methods.

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

<?php
function testTableName()
{
	$this->assertEquals('users', UserModel::tableName());	
	$userModel = test::double('UserModel', ['tableName' => 'my_users']);
	$this->assertEquals('my_users', UserModel::tableName());
	$userModel->verifyInvoked('tableName');	
}
?>

Allows replacement of class methods.

Testing code developed with the ActiveRecord pattern. Does the use of the ActiveRecord pattern sound like bad practice? No. But the code below is untestable in classic unit testing.

<?php
class UserService {
    function createUserByName($name) {
    	$user = new User;
    	$user->setName($name);
    	$user->save();
    }
}
?>

Without AspectMock you need to introduce User as an explicit dependency into class UserService to get it tested. But lets leave the code as it is. It works. Nevertheless, we should still test it to avoid regressions.

We don't want the $user->save method to actually get executed, as it will hit the database. Instead we will replace it with a dummy and verify that it gets called by createUserByName:

<?php
function testUserCreate()
{
	$user = test::double('User', ['save' => null]);
	$service = new UserService;
	$service->createUserByName('davert');
	$this->assertEquals('davert', $user->getName());
	$user->verifyInvoked('save');
}
?>

Intercept even parent class methods and magic methods

<?php
// User extends ActiveRecord
function testUserCreate()
{
	$AR = test::double('ActiveRecord', ['save' => null]));
	test::double('User', ['findByNameAndEmail' => new User(['name' => 'jon'])])); 
	$user = User::findByNameAndEmail('jon','[email protected]'); // magic method
	$this->assertEquals('jon', $user->getName());
	$user->save(['name' => 'miles']); // ActiveRecord->save did not hit database
	$AR->verifyInvoked('save');
	$this->assertEquals('miles', $user->getName());
}
?>

Override even standard PHP functions

<?php
namespace demo;
test::func('demo', 'time', 'now');
$this->assertEquals('now', time());

Beautifully simple

Only 4 methods are necessary for method call verification and one method to define test doubles:

<?php
function testSimpleStubAndMock()
{	
	$user = test::double(new User, ['getName' => 'davert']);
	$this->assertEquals('davert', $user->getName());
	$user->verifyInvoked('getName');
	$user->verifyInvokedOnce('getName');
	$user->verifyNeverInvoked('setName');
	$user->verifyInvokedMultipleTimes('setName',1);
}
?>

To check that method setName was called with davert as argument.

<?php
$user->verifyMethodInvoked('setName', ['davert']);
?>

Wow! But how does it work?

No PECL extensions is required. The Go! AOP library does the heavy lifting by patching autoloaded PHP classes on the fly. By introducing pointcuts to every method call, Go! allows intercepting practically any call to a method. AspectMock is a very tiny framework consisting of only 8 files using the power of the Go! AOP Framework. Check out Aspect Oriented Development and the Go! library itself.

Requirements

PHP >= 5.6 + Go! AOP Requirements

Installation

1. Add aspect-mock to your composer.json.

{
	"require-dev": {
		"codeception/aspect-mock": "*"
	}
}

2. Install AspectMock with Go! AOP as a dependency.

php composer.phar update

Configuration

Include AspectMock\Kernel class into your tests bootstrap file.

With Composer's Autoloader

<?php
include __DIR__.'/../vendor/autoload.php'; // composer autoload

$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
    'debug' => true,
    'includePaths' => [__DIR__.'/../src']
]);
?>

If your project uses Composer's autoloader, that's all you need to get started.

With Custom Autoloader

If you use a custom autoloader (like in Yii/Yii2 frameworks), you should explicitly point AspectMock to modify it:

<?php
include __DIR__.'/../vendor/autoload.php'; // composer autoload

$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
    'debug' => true,
    'includePaths' => [__DIR__.'/../src']
]);
$kernel->loadFile('YourAutoloader.php'); // path to your autoloader
?>

Load all autoloaders of your project this way, if you do not rely on Composer entirely.

Without Autoloader

If it still doesn't work for you...

Explicitly load all required files before testing:

<?php
include __DIR__.'/../vendor/autoload.php'; // composer autoload

$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
    'debug' => true,
    'includePaths' => [__DIR__.'/../src']
]);
require 'YourAutoloader.php';
$kernel->loadPhpFiles('/../common');
?>

Customization

There are a few options you can customize setting up AspectMock. All them are defined in Go! Framework. They might help If you still didn't get AspectMock running on your project.

  • appDir defines the root of web application which is being tested. All classes outside the root will be replaced with the proxies generated by AspectMock. By default it is a directory in which vendor dir of composer if located. If you don't use Composer or you have custom path to composer's vendor's folder, you should specify appDir
  • cacheDir a dir where updated source PHP files can be stored. If this directory is not set, proxie classes will be built on each run. Otherwise all PHP files used in tests will be updated with aspect injections and stored into cacheDir path.
  • includePaths directories with files that should be enhanced by Go Aop. Should point to your applications source files as well as framework files and any libraries you use..
  • excludePaths a paths in which PHP files should not be affected by aspects. You should exclude your tests files from interception.

Example:

<?php
$kernel = \AspectMock\Kernel::getInstance();
$kernel->init([
    'appDir'    => __DIR__ . '/../../',
    'cacheDir'  => '/tmp/myapp',
    'includePaths' => [__DIR__.'/../src']
    'excludePaths' => [__DIR__] // tests dir should be excluded
]);
?>

More configs for different frameworks.

It's pretty important to configure AspectMock properly. Otherwise it may not work as expected or you get side effects. Please make sure you included all files that you need to mock, but your test files as well as testing frameworks are excluded.

Usage in PHPUnit

Use newly created bootstrap in your phpunit.xml configuration. Also disable backupGlobals:

<phpunit bootstrap="bootstrap.php" backupGlobals="false">

Clear the test doubles registry between tests.

<?php
use AspectMock\Test as test;

class UserTest extends \PHPUnit_Framework_TestCase
{
    protected function tearDown()
    {
        test::clean(); // remove all registered test doubles
    }

    public function testDoubleClass()
    {
        $user = test::double('demo\UserModel', ['save' => null]);
        \demo\UserModel::tableName();
        \demo\UserModel::tableName();
        $user->verifyInvokedMultipleTimes('tableName',2);
    }

?>

Usage in Codeception.

Include AspectMock\Kernel into tests/_bootstrap.php. We recommend including a call to test::clean() from your CodeHelper class:

<?php
namespace Codeception\Module;

class CodeHelper extends \Codeception\Module
{
	function _after(\Codeception\TestCase $test)
	{
		\AspectMock\Test::clean();
	}
}
?>

Improvements?

There is guaranteed to be room for improvements. This framework was not designed to do everything you might ever need (see notes below). But if you feel like you require a feature, please submit a Pull Request. It's pretty easy since there's not much code, and the Go! library is very well documented.

Credits

Follow @codeception for updates.

Developed by Michael Bodnarchuk.

License: MIT.

Powered by Go! Aspect-Oriented Framework

Comments
  • Lack of comment in the doubled class causes

    Lack of comment in the doubled class causes "ParseError: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) or const (T_CONST)"

    Hi,

    Love AspectMock! I finally managed to start testing stuff which I've previously found untestable.

    However, I'm getting a very weird and annoying issue with it, though. I'm getting "ParseError: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) or const (T_CONST)" without any apparent reason.

    image

    I've done a bunch of tests to figure out what it could be. I've even went so far as to try to double a completely blank class, just it's definition.

    Actually, I've now reproduced it:

    Here's the test: image

    Here's the Class image

    And here's the Result:: image

    There's absolutely no 'if' in that class. It's as clean as it can be.

    At first I thought it was the bootstrap.php file, but it's all correct there: image

    The $kernel is initialized correctly. image

    After a lot work trying to figure it out, I did find a quite easy fix, but which makes no sense.

    Just by adding a simple comment "//"after opening the class, makes the test pass. Like this: image This is the result: image

    It makes absolutely no sense to me why that fixes it. I'm ok with that fix for now, as it allows me to focus on the rest of the project. It's not pretty having to add useless comments throughtout the code, but it does the job for now.

    It would be nice to know what actually causes this issue and if there's anything more robust I can do, or can be added to AspectMock to avoid this in the future.

    Thanks!

    opened by eugenlisov 27
  • Mocking does not actually mock

    Mocking does not actually mock

    I added the configuration as suggested in the docs for Yii 1.1 and when I run the unit tests with PHPUnit 3.7, the methods I am mocking do not get overridden.

    This is my bootstrap.php for PHPUnit:

    <?php
    
    $yiit=dirname(__FILE__).'/../../../yii/framework/yiit.php';
    if (!file_exists($yiit))
        $yiit = dirname(__FILE__).'/../../vendor/yiisoft/yii/framework/yiit.php';
    $config=dirname(__FILE__).'/../config/test.php';
    
    $kernel = AspectMock\Kernel::getInstance();
    $kernel->init([
        'debug' => true,
        'includePaths' => [
            __DIR__.'/../',
        ],
        'excludePaths' => [
            __DIR__.'/../runtime',
            __DIR__.'/../data',
            __DIR__.'/../commands',
            __DIR__.'/../bin',
            __DIR__.'/../migrations',
        ],
    ]);
    $kernel->loadFile($yiit);
    
    Yii::createWebApplication($config);
    
    ?>
    
    //The basic class I am trying to mock:
    class FounderBadgeType implements BadgeTypeInterface {
    
        public function getBadgeOrder() {
            return 1;
        }
        //...
    }
    
    //Unit Test
    $type = test::double(new FounderBadgeType(), ['getBadgeOrder' => 5]);
    $this->assertEquals(5,$type->getBadgeOrder()); //FAILS? Still returns 1, not 5
    
    opened by davemasterdave 13
  • Update dependency GoAOP to have PHP5.6/PHP7 features support

    Update dependency GoAOP to have PHP5.6/PHP7 features support

    Currently there are errors when doubling code that contains new language features that cannot be parsed by old GoAOP. GoAOP with version 1.0.x supports new language features (but breaks backwards compatybility as it requires php>=5.6).

    enhancement 
    opened by zuozp8 12
  • Fail to load classes in shutdown function?

    Fail to load classes in shutdown function?

    I'm not sure this is a bug of AspectMock/Go AOP, or PHP. And it happens on CentOS 6.5 (64bit). Not on Ubuntu 12.04 (32bit), Mac OS X.

    I get a strange error that autoloader can't load a class when it is called in a function registered by register_shutdown_function().

    I investigated it. I put the code below in shutdown function.

    echo file_get_contents('php://filter/read=go.source.transforming.loader/resource=/path/to/class/file.php');
    

    But nothing was outputed.

    I put the same code in a test method. It worked fine.

    Does anyone have any advices?

    opened by kenjis 12
  • GoAOP deprecated StreamMetaData->source

    GoAOP deprecated StreamMetaData->source

    After upgrading goaop/framework to 2.2.0 I get deprecation warning during cache generation, also the cache is not really generated, just the folder is created. This causes that doubles don't work after the first run while the folder is there. Downgrading to goaop/framework 2.1.2 everything works again as it should.

    I get this error during cache generation:

    Deprecated: Setting StreamMetaData->source is deprecated, use tokenStream instead in vendor/goaop/framework/src/Instrument/Transformer/StreamMetaData.php on line 132

    codeception/aspect-mock 2.1.1 Experimental Mocking Framework powered by Aspects codeception/codeception 2.3.6 BDD-style testing framework goaop/framework 2.2.0 Framework for aspect-oriented programming in PHP. goaop/parser-reflection 1.4.0 Provides reflection information, based on raw source

    bug 
    opened by bl-cp 9
  • Serialization error

    Serialization error

    I'm trying to test this out, but get "Exception: Serialization of 'Closure' is not allowed" every time I run phpunit. PHPUnit has issues with serializing closures, but I'm not sure why that would affect my machine and not yours.

    Here is my source code. I'm not even using any of the functionality yet. Just trying to get the tests to run. See anything glaringly wrong?

    https://github.com/JeffreyWay/Temporary-Bug

    I'm using PHPUnit 3.7.19 and PHP 5.4.1.

    bug 
    opened by JeffreyWay 9
  • Fix syntax error in PHP 7.1

    Fix syntax error in PHP 7.1

    [] operator not supported for strings in PHP 7.1

    I initial the variable as array, and put the value then.

    PHP Fatal error:  Uncaught Error: [] operator not supported for strings in /home/zero/devel/boltics-core/vendor/codeception/aspect-mock/src/AspectMock/Kernel.php:24
    Stack trace:
    #0 /home/zero/devel/boltics-core/tests/bootstrap.php(9): AspectMock\Kernel->init(Array)
    #1 /home/zero/devel/boltics-core/vendor/phpunit/phpunit/src/Util/FileLoader.php(57): include_once('/home/zero/deve...')
    #2 /home/zero/devel/boltics-core/vendor/phpunit/phpunit/src/Util/FileLoader.php(45): PHPUnit\Util\FileLoader::load('/home/zero/deve...')
    #3 /home/zero/devel/boltics-core/vendor/phpunit/phpunit/src/TextUI/Command.php(1058): PHPUnit\Util\FileLoader::checkAndLoad('/home/zero/deve...')
    #4 /home/zero/devel/boltics-core/vendor/phpunit/phpunit/src/TextUI/Command.php(863): PHPUnit\TextUI\Command->handleBootstrap('/home/zero/deve...')
    #5 /home/zero/devel/boltics-core/vendor/phpunit/phpunit/src/TextUI/Command.php(173): PHPUnit\TextUI\Command->handleArguments(Array)
    #6 /home/zero/devel/boltics-core/vendor/phpunit/phpunit/src/TextUI/Command.php(162): PHPUnit\T in /home/zero/devel/boltics-core/vendor/codeception/aspect-mock/src/AspectMock/Kernel.php on line 24
    
    opened by johnroyer 8
  • Phalcon PHP Mocking

    Phalcon PHP Mocking

    Is it possible to mock a static method from the phalcon extension?

            $model = test::double("Common\\Models\\User", ["findFirst"=>new User()]);
            $user = User::findFirst();
            $model->verifyInvoked("findFirst");
    

    I have a model method User::findFirst() I'm trying to mock. User extends Phalcon\Mvc\Model (an extension class) and findFirst is a static method of that parent class. Unfortunately, verifyInvoked() returns false. Is it possible (now OR in the future) that AspectMock could do this? Adding the findFirst method to my User model works, so it appears it is setup correctly.

    opened by jymboche 8
  • Strict standards: Declaration of AspectMock\Kernel::registerTransformers() should be compatible with Go\Core\AspectKernel::registerTransformers()

    Strict standards: Declaration of AspectMock\Kernel::registerTransformers() should be compatible with Go\Core\AspectKernel::registerTransformers()

    After updating lisachenko/go-aop-php 2ed1ec1 => 0dd0610, the error occurs.

    Strict standards: Declaration of AspectMock\Kernel::registerTransformers() should be compatible with Go\Core\AspectKernel::registerTransformers() in .../vendor/codeception/aspect-mock/src/AspectMock/Kernel.php on line 19

    Catchable fatal error: Argument 1 passed to AspectMock\Kernel::registerTransformers() must be an instance of Go\Instrument\ClassLoading\SourceTransformingLoader, none given, called in .../vendor/lisachenko/go-aop-php/src/Go/Core/AspectKernel.php on line 106 and defined in .../vendor/codeception/aspect-mock/src/AspectMock/Kernel.php on line 58

    opened by kenjis 8
  • don't let GoAOP upgrade

    don't let GoAOP upgrade

    This PR is a proposal to limit the updating of goaop/framework so that the AST streaming issues

    • https://github.com/goaop/framework/issues/363
    • https://github.com/Codeception/AspectMock/issues/146

    which are not totally resolved in 2.2.

    I'd be happy to fix this the "right way" with AOP tokenStreams, but it doesn't look like that code has settled down yet in 2.2, so it seems like wasted effort.

    opened by JoeVieira 7
  • Add missing type hints and parameter types to FuncProxy

    Add missing type hints and parameter types to FuncProxy

    While working with AspectMock, I saw some missing type hints and comments in FuncProxy. To help developers figuring out the correct arguments for the methods, I've added type hints and doc-block comments to the class.

    This is helpful, when someone is working directly with the code.

    opened by SenseException 7
  • Redefinition of parameter $_ PointcutGrammar.php

    Redefinition of parameter $_ PointcutGrammar.php

    Redefinition of parameter $_ in /opt/project/new/vendor/lisachenko/go-aop-php/src/Go/Aop/Pointcut/PointcutGrammar.php on line 61

    my config in _bootstrap yii2 advanced

    `require(DIR . '/../vendor/autoload.php');

    $kernel = \AspectMock\Kernel::getInstance(); $kernel->init([ 'debug' => true, 'includePaths' => [ DIR . '/../../', ] ]);`

    where did i go wrong?

    opened by romanpan2 0
  • Does not install with Composer w/o warnings/errors (PHP 8)

    Does not install with Composer w/o warnings/errors (PHP 8)

    AspectMock 4.1.1 won't install cleanly under PHP 8 with Composer:

    $ composer update 
    Loading composer repositories with package information
    Updating dependencies
    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - Root composer.json requires codeception/aspect-mock 4.1.1 -> satisfiable by codeception/aspect-mock[4.1.1].
        - codeception/aspect-mock 4.1.1 requires php ^7.4 -> your php version (8.1.2) does not satisfy that requirement.
    

    The only way I can get it to install without errors is to use Composer's --ignore-platform-reqs option.

    Although there are problems with goaop/parser-reflection under PHP 8 (see https://github.com/goaop/framework/issues/466), I believe AM itself will work without issue under the newer PHP versions (other than the problem I reported in #201).

    I believe changing this composer.json line would be sufficient:

    -        "php": "^7.4",
    +        "php": ">=7.4",
    
    opened by jimbonator 2
  • Error when mocking built-in function with pass-by-reference argument and argument with default value (PHP 8)

    Error when mocking built-in function with pass-by-reference argument and argument with default value (PHP 8)

    This is for AspectMock 4.1.1.

    During our migration from PHP 7.4 to PHP 8.1, we've encountered this pattern a few times:

    When our PHP-Unit tests mock a PHP built-in function that has at least one argument passed by reference and one argument with a default value, the mock fails with the error ParseError: syntax error, unexpected token "=", expecting ")".

    The stack track looks like this:

    /tmp/flockoipmSG:4
    /petabox/www/common/vendor/codeception/aspect-mock/src/AspectMock/Core/Mocker.php:275
    /petabox/www/common/vendor/codeception/aspect-mock/src/AspectMock/Core/Registry.php:38
    /petabox/www/common/vendor/codeception/aspect-mock/src/AspectMock/Test.php:248
    

    Examining the temporary file reveals the problem:

    $ cat /tmp/flockoipmSG
    <?php
    namespace Atomic;
    if (!function_exists('Atomic\flock')) {
        function flock($p0, int $p1, &$p2 = null=NULL) {
             $args = [];
             switch(count(func_get_args())) {
                 case 3: $args = [$p0, $p1, &$p2]; break;
                 case 2: $args = [$p0, $p1]; break;
                 case 1: $args = [$p0]; break;
             }
             if (($__am_res = __amock_before_func('Atomic','flock', $args)) !== __AM_CONTINUE__) {
                 return $__am_res;
             }
             return call_user_func_array('flock', $args);
        }
    }
    

    The function declaration has two default values for an argument (function flock($p0, int $p1, &$p2 = null=NULL).

    Other functions which have given us this problem are:

    • system()
    • stream_socket_client()
    • stream_select()

    The last one is interesting because, unlike the others, the passed-by-reference arguments don't have default values. Only the final argument does:

    stream_select(
        ?array &$read,
        ?array &$write,
        ?array &$except,
        ?int $seconds,
        ?int $microseconds = null
    ): int|false
    

    That's what leads me to believe the problem is the existence of both in the function signature, but not necessarily that a single argument needs to be both pass-by-reference and have a default value for this to fail.

    We don't see this under PHP 7.4, so I assume this related to the PHP version.

    opened by jimbonator 1
  • It still uses real class instead mock class.

    It still uses real class instead mock class.

    I use it to mock class for my fuelphp project. But It still uses real class instead of mock class. $user = test::double('\Apply\Model_Apply_Token', [ 'find_one_by' => null, ]); var_dump(Model_Apply_Token::find_one_by('uuid', 12341);

    opened by khiemnguyen-ffw 1
  • Error: Using $this when not in object context

    Error: Using $this when not in object context

    namespace app\aspectmockexample;
    
    class AdminUserModel extends UserModel
    {
        public function save()
        {
            $this->name = "Admin_111";
            parent::save();
        }
    }
    
    testing:
       public function testMagicStaticInherited()
        {
            double::registerClass('app\aspectmockexample\AdminUserModel', ['defaultRole' => 'admin']);
            TestCase::assertEquals('admin', AdminUserModel::defaultRole());
        }
    
    cache file generic:
        public static function __callStatic($name, $args)
        {
            if ($name == 'defaultRole') { if (($__am_res = __amock_before($this, __CLASS__, __FUNCTION__, array(), false)) !== __AM_CONTINUE__) return $__am_res; 
                return "member";
            }
        }
    

    Error message:

    1) StubTest::testMagicStaticInherited
    Error: Using $this when not in object context
    
    
    opened by Jekahome 0
Releases(4.1.1)
  • 4.1.1(Dec 18, 2021)

  • 4.1.0(Dec 17, 2021)

    What's Changed

    • Updated code base to PHP 7.4 by @TavoNiievez in https://github.com/Codeception/AspectMock/pull/197
    • Allow running Actions manually and run once a week by @Naktibalda in https://github.com/Codeception/AspectMock/pull/195

    Full Changelog: https://github.com/Codeception/AspectMock/compare/4.0.0...4.1.0

    Source code(tar.gz)
    Source code(zip)
  • 4.0.0(Apr 16, 2021)

  • 3.1.1(Apr 10, 2021)

    • Fixed PHPUnit Framework Exception Undefined offset at BeforeMock by @ahmed-abid
    • This version does not support PHP 8
    • This version does not support goaop/framework v3
    Source code(tar.gz)
    Source code(zip)
  • 3.1.0(Feb 29, 2020)

    • Support for goaop/framework v3
    • Support for symfony/finder v5
    • Added missing assertions for method call invocations #160 by @bhoehl
    • Fixed wrong method invocation count on dynamic methods using exceptions #161 by @bhoehl
    • Bugfix: Handle a case when excludePaths is a string
    Source code(tar.gz)
    Source code(zip)
  • 3.0.2(Oct 7, 2018)

  • 3.0.1(Jul 31, 2018)

  • 2.0.1(Jan 31, 2017)

  • 2.0.0-RC(Jan 31, 2017)

  • 2.0.0(Jan 31, 2017)

  • 1.0.0(Mar 14, 2016)

  • 0.5.5(Jan 10, 2016)

  • 0.5.4(Jan 8, 2016)

    • Improved namespace handling
    • Added ability to display actually passed parameter in the error message
    • Fixed counting of dynamic class methods (#24)
    • Fixes for functions that have a brace as default on parameters
    • Replace return with yield when docComments returns Generator
    Source code(tar.gz)
    Source code(zip)
  • 0.5.1(Oct 15, 2014)

  • 0.5.0(Oct 9, 2014)

  • 0.5.0-beta2(May 13, 2014)

  • 0.5.0-beta(May 13, 2014)

  • 0.4.2(May 9, 2014)

  • 0.4.1(Feb 25, 2014)

    Traits support and other Pull Requests merged. Robo builder added

    0.4.1

    02/25/2014

    • RoboFile
    • Verify invocation arguments with closures @gchaincl
    • Verify invocation arguments with closures by @gchaincl
    • better support for traits by @andyfowler
    Source code(tar.gz)
    Source code(zip)
  • 0.4.0(Sep 9, 2013)

    A huge improvement to stability, performance added. Level of hard magic reduced. AspectMock dropped Go Aop proxy classes, and now tries to affect your code in very minimal way.

    Instead of creating A_AspectProxy for class A (as Go Aop does), AspectMock places its tiny beacons directly into A methods, in very beginning of method definition.

    Changes:

    • you can freely use debugger, as your classes left practically unchanged.
    • stacktrace look much more cleaner and more natural.
    • performance dramatically improved. Still, AOP magic takes about 15% of overall execution.
    • remved MethodProxy class. You can't verify result of method calls anymore.
    • test::ns method added to api, for prepending a namespace name to class.
    • debug is enabled by default
    Source code(tar.gz)
    Source code(zip)
  • 0.3.0(Aug 27, 2013)

    This version adds flexibility to method interception. Now you can catch call to a parent class and redeclare it. Also you can mock magic methods just same way you do for non-magic ones. No matter how an where method is declared, we will try to catch it and mock it if you wish that, master.

    • updated to Go Aop 0.4.1 (improved work with Yii)
    • interception of parent class methods
    • interception of magic methods
    Source code(tar.gz)
    Source code(zip)
Owner
Codeception Testing Framework
Codeception Testing Framework and related projects
Codeception Testing Framework
Essence is a very flexible BDD style assertion framework for PHP that fits into existing PHPUnit projects nicely

Essence 1.5.1 Essence is a very flexible BDD style assertion framework for PHP that fits into existing PHPUnit projects nicely. Installation composer

bound1ess 2 Apr 7, 2015
Provides generic data providers for use with phpunit/phpunit.

data-provider Installation Run composer require --dev ergebnis/data-provider Usage This package provides the following generic data providers: Ergebni

null 25 Jan 2, 2023
Qase-phpunit - Qase TMS PHPUnit reporter.

Qase TMS PHPUnit reporter Publish results simple and easy. How to integrate composer require qase/phpunit-reporter Example of usage The PHPUnit report

Qase TMS 6 Nov 24, 2022
Mockery - Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library

Mockery Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its c

Mockery 10.3k Jan 1, 2023
PHP Mocking Framework

Phake Phake is a framework for PHP that aims to provide mock objects, test doubles and method stubs. Phake was inspired by a lack of flexibility and e

Phake 469 Dec 2, 2022
Highly opinionated mocking framework for PHP 5.3+

Prophecy Prophecy is a highly opinionated yet very powerful and flexible PHP object mocking framework. Though initially it was created to fulfil phpsp

PHPSpec Framework 8.5k Jan 3, 2023
PHP Mocking Framework

Phake Phake is a framework for PHP that aims to provide mock objects, test doubles and method stubs. Phake was inspired by a lack of flexibility and e

Phake 469 Dec 2, 2022
Removes final keywords from source code on-the-fly and allows mocking of final methods and classes

Removes final keywords from source code on-the-fly and allows mocking of final methods and classes. It can be used together with any test tool such as PHPUnit or Mockery.

David Grudl 326 Dec 9, 2022
A PHP library for mocking date and time in tests

ClockMock Slope s.r.l. ClockMock provides a way for mocking the current timestamp used by PHP for \DateTime(Immutable) objects and date/time related f

Slope 44 Dec 7, 2022
vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system. It can be used with any unit test framework, like PHPUnit or SimpleTest.

vfsStream vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system. It can be used with

null 1.4k Dec 23, 2022
PHP libraries that makes Selenium WebDriver + PHPUnit functional testing easy and robust

Steward: easy and robust testing with Selenium WebDriver + PHPUnit Steward is a set of libraries made to simplify writing and running robust functiona

LMC s.r.o. 219 Dec 17, 2022
PHPStan PHPUnit extensions and rules

PHPStan PHPUnit extensions and rules PHPStan PHPUnit This extension provides following features: createMock(), getMockForAbstractClass() and getMockFr

PHPStan 359 Dec 28, 2022
Additional PHPUnit assertions and helper functions

Jasny PHPUnit extension Additional functionality for PHPUnit. Callback mock - assert that callback is called with correct arguments. Safe mocks - disa

Arnold Daniels 2 Jul 24, 2022
:computer: Parallel testing for PHPUnit

ParaTest The objective of ParaTest is to support parallel testing in PHPUnit. Provided you have well-written PHPUnit tests, you can drop paratest in y

null 2k Dec 31, 2022
Rector upgrades rules for PHPUnit

Rector Rules for PHPUnit See available PHPUnit rules Install composer require rector/rector-phpunit Use Sets To add a set to your config, use Rector\P

RectorPHP 34 Dec 27, 2022
A sample RESTful API in Laravel with PHPunit test.

Laravel PHP Framework URL | URI | Action |

Fasil 9 Jul 11, 2020
PHPUnit Application Architecture Test

PHPUnit Application Architecture Test Idea: write architecture tests as well as feature and unit tests Installation Install via composer composer requ

null 19 Dec 11, 2022
PHPUnit to Pest Converter

PestConverter PestConverter is a PHP library for converting PHPUnit tests to Pest tests. Before use Before using this converter, make sure your files

null 10 Nov 21, 2022