Coder Social home page Coder Social logo

phpunit-accelerator's Introduction

PHPUnit Accelerator

What I found is that PHPUnit is really hard to debug memory with, because it in itself keeps a lot of objects in memory before actually starting any test so the initial memory is jumping depending by the number of tests available - it creates a new test class instance for each test, so UserTest having 1k test declarations/function will result in 1k UserTest class instances before it actually starts processing them, which I'd say is more of a inefficiency from the PHPUnit side, the more tests you have the higher the starting memory will be.

Inspired by Kris Wallsmith faster PHPUnit article, we've created a PHPUnit test listener that speeds up PHPUnit tests about 20% by freeing memory.

Installation

To install this library, run the command below and you will get the latest version

composer require zhukovsergei/phpunit-accelerator --dev

Usage

Just add to your phpunit.xml configuration

<phpunit>
    <listeners>
        <listener class="\MyBuilder\PhpunitAccelerator\TestListener"/>
    </listeners>
</phpunit>

Ignoring Tests

Sometimes it is necessary to ignore specific tests, where freeing their properties is undesired. For this use case, you have the ability to extend the behaviour of the listener by implementing the IgnoreTestPolicy interface.

As an example, if we hypothetically wanted to ignore all tests which include "Legacy" in their test filename, we could create a custom ignore policy as follows

<?php

use MyBuilder\PhpunitAccelerator\IgnoreTestPolicy;

class IgnoreLegacyTestPolicy implements IgnoreTestPolicy {
    public function shouldIgnore(\ReflectionObject $testReflection) {
        return strpos($testReflection->getFilename(), 'Legacy') !== false;
    }
}

And pass it to the constructor of our test listener in phpunit.xml configuration

<phpunit>
    <listeners>
        <listener class="\MyBuilder\PhpunitAccelerator\TestListener">
            <arguments>
                <object class="\IgnoreLegacyTestPolicy"/>
            </arguments>
        </listener>
    </listeners>
</phpunit>

Created by MyBuilder - Check out our blog for more insight into this and other open-source projects we release.

phpunit-accelerator's People

Contributors

gavinlove avatar enumag avatar keyvanakbary avatar b1rdex avatar sergeyz avatar live627 avatar dxops avatar adamnicholson avatar sp-felix-carmona avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.