PHP code example of subiabre / phpmetro

1. Go to this page and download the library: Download subiabre/phpmetro library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

subiabre / phpmetro example snippets



# tests/RandomNumber/RandomNumberAnalysis.php
namespace MyApp\Tests\RandomNumber;

use MyApp\RandomNumber;
use PHPMetro\Analysis\AnalysisCase;

class RandomNumberAnalysis extends AnalysisCase
{
    # ...
}

public function setUp(): void
{
    $this->addSample('RandomNumber', 100, function(): int {
        $randomNumber = new RandomNumber();

        return $randomNumber->new();
    });
}


# tests/RandomNumber/RandomNumberAnalysis.php
namespace MyApp\Tests\RandomNumber;

// MathPHP provides nice maths
use MathPHP\Statistics\Average;

use MyApp\RandomNumber;
use PHPMetro\Analysis\AnalysisCase;

class RandomNumberAnalysis extends AnalysisCase
{
    public function setUp(): void
    {
        $this->addSample('RandomNumbers', 100, function() {
            $randomNumber = new RandomNumber();

            return $randomNumber->new();
        });
    }

    public function testMedianAverage(): int
    {
        $sample = $this->getSample('RandomNumbers');

        return Average::median($sample);
    }
}
xml
<suites>
    <suite
        name="My Analysis Suite"
        suffix="Suffix"
        ignore="false"
    >
        <namespace>MyApp\Tests\Metro</namespace>
        <directory>tests/Metro</directory>
    </suite>
</suites>