PHPackages                             subiabre/phpmetro - 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. subiabre/phpmetro

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

subiabre/phpmetro
=================

Statistical analysis for PHP code

1.1.8(5y ago)1033[1 PRs](https://github.com/subiabre/phpmetro/pulls)MITPHPCI failing

Since Feb 14Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/subiabre/phpmetro)[ Packagist](https://packagist.org/packages/subiabre/phpmetro)[ RSS](/packages/subiabre-phpmetro/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (3)Versions (19)Used By (0)

PHPMetro
========

[](#phpmetro)

Streamlined statistical sampling and analysis of results.

[![PHPMetro logo](https://user-images.githubusercontent.com/61125897/75801933-35e8d280-5d7c-11ea-9eab-8f788f97a0d9.png)](https://user-images.githubusercontent.com/61125897/75801933-35e8d280-5d7c-11ea-9eab-8f788f97a0d9.png)

[![License](https://camo.githubusercontent.com/a4f5efdc254c28d423990397a8c8226f203c7f5d57dfe884287a802ea8b22b67/68747470733a2f2f706f7365722e707567782e6f72672f73756269616272652f7068706d6574726f2f6c6963656e7365)](https://packagist.org/packages/subiabre/phpmetro)[![Latest Stable Version](https://camo.githubusercontent.com/50abbd035d5b0f70d3409170db757bfacfebf309a1bffde75e5f8d2f4ed71a7f/68747470733a2f2f706f7365722e707567782e6f72672f73756269616272652f7068706d6574726f2f76657273696f6e)](https://packagist.org/packages/subiabre/phpmetro)[![CI](https://github.com/subiabre/phpmetro/workflows/CI/badge.svg?branch=master)](https://github.com/subiabre/phpmetro/workflows/CI/badge.svg?branch=master)[![codecov](https://camo.githubusercontent.com/3a2c0cfc1a7d521287ca24d607fde4d3ee9185a594cfc53e04ae2be70aee42ee/68747470733a2f2f636f6465636f762e696f2f67682f73756269616272652f7068706d6574726f2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/subiabre/phpmetro)[![Latest Unstable Version](https://camo.githubusercontent.com/10263dc577e934dafbbc680066b05bba155747e2126e6450a62edfd77dea3e4e/68747470733a2f2f706f7365722e707567782e6f72672f73756269616272652f7068706d6574726f2f762f756e737461626c65)](//packagist.org/packages/subiabre/phpmetro)[![Total Downloads](https://camo.githubusercontent.com/fecd3769da23cdc124bb6e9a4571bf26edf7cf57423c993a58f65be3188595d8/68747470733a2f2f706f7365722e707567782e6f72672f73756269616272652f7068706d6574726f2f646f776e6c6f616473)](https://packagist.org/packages/subiabre/phpmetro)

PHPMetro provides the foundation to perform sampling and analysis of data in a PHPUnit-like fashion, aiming to make it as easy as possible for PHP developers to compose analysis suites and get statistical results.

1. [About](#About)
2. [Requirements](#Requirements)
3. [Installation](#Installation)
4. [Configuration](#Configuration)
5. [Usage (basic tutorial)](#Usage)
6. [Support](#Support)

---

About
-----

[](#about)

I created this package on winter 2019 because I was working on a project that required me to not only perform unit and functional tests of my code, but to also create and perform several statistical analyses of my code. PHPMetro was my response to that requirement.

> **WARNING**: Despite the origin of this project being that of a professional environment, it's not granted to be suitable for all production environments.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.2\*
- [Composer](https://getcomposer.org)

\*Package should be compatible with older versions of PHP down to 5.x, but it's not granted.

Installation
------------

[](#installation)

PHPMetro is distributed on [packagist](https://packagist.org/packages/subiabre/phpmetro).

```
$ composer require --dev subiabre/phpmetro
```

Once installed you'll get the phpmetro binary in your bin folder, by default **vendor/bin**. After installation you'll want to run `composer suggests subiabre/phpmetro` to see some more libraries you'll find useful when writing your analyses, as PHPMetro only contains a basic toolset for describing analysis cases with an specific workflow, and a runner to perform all our analyses based on a given configuration.

Configuration
-------------

[](#configuration)

PHPMetro **needs** to be fed a `.xml` config file on run. This file will tell where to search for our Analysis classes and how to run them.

### Getting the template configuration

[](#getting-the-template-configuration)

Easiest way is to copy to the root of your project the example config file at your vendor folder:

```
$ cp vendor/subiabre/phpmetro/phpmetro.xml phpmetro.xml
```

The binary will automatically search for any `phpmetro.xml` at the root folder and load it unless you specify a location, you can use that to use and run several different configurations and suites.

```
$ ./vendor/bin/phpmetro path/to/config.xml
```

### Configuring

[](#configuring)

The *.xml* config file specifies general run directives for the PHPMetro binary as well as defines the analyses by suite groups.

The default file can be environment specific: `phpmetro.xml.local` will override `phpmetro.xml.dist` and this will override `phpmetro.xml`.

1. [Configuring PHPMetro](#Configuring-PHPMetro)
2. [Configuring Suites](#Configuring-Suites)

#### Configuring PHPMetro

[](#configuring-phpmetro)

```

    ...

```

The two attributes you see are required and they mean:

- **verbose**: When set to "true" PHPMetro will display additional run info. Equals to running the command with the `-v` flag.

There are no more run configurations. The runner will automatically fetch files from the suites you define. You can set more configurations per suite.

#### Configuring Suites

[](#configuring-suites)

```

        MyApp\Tests\Metro
        tests/Metro

```

Suites must be inside the `` tag. Each suite accepts the following attributes:

- **name**: The display name of the suite. Required.
- **suffix**: Any combinations of letters that the analysis class files use as suffix. Optional. Defaults to "Analysis".
- **ignore**: When set to "true" it will indicate the runner to skip the execution of that suite. Optional. Defaults to "false".

> **NOTE**: Suffixes don't necessarily have to include the '.php' file extension. In fact the suite right-trims it from the suffix.

Inside each suite there must be two more tags specificating:

- **namespace**: The common namespace for the suite classes.
- **directory**: The folder where all the classes are at.

> **NOTE**: You must adhere to the [PSR-4](https://getcomposer.org/doc/04-schema.md#psr-4) specification when filenaming your Analyses. If you have an Analysis with the namespace `MyApp\Tests\Foo\BarAnalysis`, for this class to be properly identified by PHPMetro it will have to be located at `tests/Foo/BarAnalysis.php`.

Usage
-----

[](#usage)

Say you have your own random number generator, `MyApp\RandomNumber`, and want to see some statistics about it. PHPMetro is your package for that! Let's put it under "Analysis".

### Creating an Analysis class

[](#creating-an-analysis-class)

An *Analysis* is an special class that extends from `AnalysisCase` and contains a set up with samples and several tests over the samples.

```
