2017 © Pedro Peláez
 

library phprtest

Simple resources usage tests for PHP applications

image

yegortokmakov/phprtest

Simple resources usage tests for PHP applications

  • Tuesday, June 30, 2015
  • by yegortokmakov
  • Repository
  • 1 Watchers
  • 5 Stars
  • 71 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 8 % Grown

The README.md

PHPRTest Latest Stable Build Status

PHPRTest is a simple resources usage tests for modern PHP applications. In a fashion of PHPUnit, it allows developers to keep track of memory consumption and execution time of critical parts of software. PHPRTest allows to set up soft and hard limits for each test suite and is easy to integrate with your favorite CI solution., (*1)

Usage

Here is a basic test of Symfony console application. In this test we run import command and assert that execution time is less than 0.05 seconds, soft memory usage limit is 6 MB and hard memory usage limit is 10 MB., (*2)

<?php

class ImportTest extends \Phprtest\TestSuite
{
    /**
     * @assert memoryUsage 6.5M 10M
     * @assert timeUsage 0.05
     */
    public function testImportCommand()
    {
        $app = new \Symfony\Component\Console\Application('Myapp', 1);
        $app->add(new \Myapp\Command\Import('import'));
        $app->run(new ArgvInput(['myapp', 'import']));
    }
}

Running this test will produce similar results:, (*3)

PHP Resources usage tests
--------------------------------

ImportTest
+-------------------------------+----------+-----------+-----------+---------+
|            METRIC             |  RESULT  | SOFTLIMIT | HARDLIMIT | STATUS  |
+-------------------------------+----------+-----------+-----------+---------+
| testImportCommand:memoryUsage | 7141330  | 6815744   | 10485760  | softHit |
| testImportCommand:timeUsage   | 0.0341   | 0.05      | 0.05      | ok      |
+-------------------------------+----------+-----------+-----------+---------+

Warnings:
testImportCommand:memoryUsage warning assertion for memoryUsage: 7141330 > 6291456

1 tests completed. 1 warnings, 0 failures.

To extract some part of the code from measurements (e.g. initialization of data), you can use @provider annotation:, (*4)

<?php

class ImportTest extends \Phprtest\TestSuite
{
    /**
     * @assert memoryUsage 6M 10M
     * @assert timeUsage 0.05
     * @provider applicationProvider
     */
    public function testImportCommand($app)
    {
        $app->run(new ArgvInput(['myapp', 'import']));
    }

    public function applicationProvider()
    {
        $app = new \Symfony\Component\Console\Application('Myapp', 1);
        $app->add(new \Myapp\Command\Import('import'));

        return $app;
    }
}

To run same test multiple times, you can use @repeat annotation:, (*5)

<?php

class ImportTest extends \Phprtest\TestSuite
{
    /**
     * @assert memoryUsage 6M 10M
     * @assert timeUsage 0.05
     * @repeat 5
     */
    public function testImportCommand($app)
    {
        $app = new \Symfony\Component\Console\Application('Myapp', 1);
        $app->add(new \Myapp\Command\Import('import'));
        $app->run(new ArgvInput(['myapp', 'import']));
    }
}

Installation

PHPRTest is available on Packagist (yegortokmakov/phprtest) and as such installable via Composer., (*6)

php composer.phar require yegortokmakov/phprtest

Or simply add a dependency on yegortokmakov/phprtest to your project's composer.json file if you use Composer to manage the dependencies of your project. Here is a minimal example of a composer.json file that just defines a development-time dependency on PHPRTest:, (*7)

{
    "require-dev": {
        "yegortokmakov/phprtest": "dev-master"
    }
}

Todo

  • Limits for etalon test
  • CPU usage
  • Memory gain
  • Calculate average of runs
  • Statistic of results: warninng if they are bad
  • Time weights for mock calls

Author

Yegor Tokmakov - yegor@tokmakov.biz
See also the list of contributors who participated in this project., (*8)

License

PHPRTest is licensed under the MIT License - see the LICENSE file for details, (*9)

The Versions

30/06 2015

dev-master

9999999-dev

Simple resources usage tests for PHP applications

  Sources   Download

MIT

The Requires

 

The Development Requires

test performance resources

30/06 2015

0.2.0

0.2.0.0

Simple resources usage tests for PHP applications

  Sources   Download

MIT

The Requires

 

The Development Requires

test performance resources

13/06 2015

0.1.2

0.1.2.0

Simple resources usage tests for PHP applications

  Sources   Download

MIT

The Requires

 

The Development Requires

test performance resources

09/06 2015

0.1.1

0.1.1.0

Simple resources usage tests for PHP applications

  Sources   Download

MIT

The Requires

 

The Development Requires

test performance resources

09/06 2015

0.1

0.1.0.0

Simple resources usage tests for PHP applications

  Sources   Download

MIT

The Requires

 

The Development Requires

test performance resources