PHP code example of atoum / blackfire-extension

1. Go to this page and download the library: Download atoum/blackfire-extension 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/ */

    

atoum / blackfire-extension example snippets


namespace Tests\Units;

use Example as TestedClass;

use atoum;

class Example extends atoum
{
    public function testExemple()
    {
        $this
            ->blackfire
                ->assert('main.wall_time < 2s', "Temps d'execution")
                ->profile(function() {
                    sleep(4); //just to make the test fail

                    //some code to profile
                    // ...

                    //you also can run atoum assertions inside this callable
                    //but beware, atoum's logic will also be profiled.
                    $this->boolean(true)->isTrue();
                })
        ;
    }
}




// .atoum.php

ension(mageekguy\atoum\blackfire\extension::class)
    ->setClientConfiguration(new \Blackfire\ClientConfiguration($_ENV['BLACKFIRE_CLIENT_ID'], $_ENV['BLACKFIRE_CLIENT_TOKEN']))
    ->addToRunner($runner)
;

$this
    ->blackfire
        ->defineMetric(new \Blackfire\Profile\Metric("example_method_calls", "=Example::method"))
        ->assert("metrics.example_method_calls.count < 10")
        ->profile(function() {
            $testedClass = new TestedClass();
            for ($i = 0; $i < 8; $i++) {
                $testedClass->method();
            }
        })
;

$this
    ->given(
        $profileConfiguration = new \Blackfire\Profile\Configuration(),
        $profileConfiguration->setTitle('Profile configuration title'),
        $testedClass = new TestedClass()
    )
    ->blackfire
        ->setConfiguration($profileConfiguration)
        ->assert("main.peak_memory < 10mb")
        ->profile(function() use ($testedClass) {
            $testedClass->method();
        })
;

$this
    ->given(
      $config = new \Blackfire\ClientConfiguration($_ENV['BLACKFIRE_CLIENT_ID'], $_ENV['BLACKFIRE_CLIENT_TOKEN']);
      $client = new \Blackfire\Client($config);
    )
    ->blackfire(client)
        ->assert('main.wall_time < 2s')
        ->profile(function() {
            //code to profile
        })
;

    /**
     * @extensions blackfire
     */
    public function testExemple()
    {
        $this
            ->blackfire($this->getBlackfireClient())
                ->defineMetric(new \Blackfire\Profile\Metric("example_method_calls", "=Example::method"))
                ->assert("metrics.example_method_calls.count < 10")
                ->profile(function() {
                    $testedClass = new TestedClass();
                    for ($i = 0; $i < 8; $i++) {
                        $testedClass->method();
                    }
                })
        ;
    }