<commit_before><?php

namespace Tideways;

class ProfilerTest extends \PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        if (function_exists('tideways_prepend_overwritten') && tideways_prepend_overwritten()) {
            $this->markTestSkipped('Cannot run tests when tideways is installed and loaded globally. Run with -dtideways.auto_prepend_library=0');
        }
        \Tideways\Profiler::stop();
        \Tideways\Profiler::setBackend(null);

        if (\Tideways\Profiler::isStarted()) {
            $this->fail('Profiler is already running');
        }
        unset(
            $_SERVER['HTTP_X_TIDEWAYS_PROFILER'],
            $_SERVER['HTTP_X_TW_ROOTID'],
            $_SERVER['HTTP_X_TW_SPANID'],
            $_SERVER['HTTP_X_TW_TRACEID'],
            $_SERVER['REMOTE_ADDR'],
            $_SERVER['HTTP_X_FORWARDED_FOR']
        );
    }

    public function testStartStopProfile()
    {
        $alwaysSample = 100;

        $backend = self::createBackend();
        $backend->expects($this->once())->method('socketStore');

        \Tideways\Profiler::start('foo', $alwaysSample);
        \Tideways\Profiler::setTransactionName(__CLASS__ . '::' . __METHOD__);

        $this->assertTrue(\Tideways\Profiler::isProfiling());
        $this->assertTrue(\Tideways\Profiler::isStarted());

        \Tideways\Profiler::stop();

        $this->assertFalse(\Tideways\Profiler::isProfiling());<commit_msg>Fix test<commit_after><?php

namespace Tideways;

class ProfilerTest extends \PHPUnit_Framework_TestCase
{
    public function setUp()
    {
        if (function_exists('tideways_prepend_overwritten') && tideways_prepend_overwritten()) {
            $this->markTestSkipped('Cannot run tests when tideways is installed and loaded globally. Run with -dtideways.auto_prepend_library=0');
        }
        \Tideways\Profiler::stop();
        \Tideways\Profiler::setBackend(null);

        if (\Tideways\Profiler::isStarted()) {
            $this->fail('Profiler is already running');
        }
        unset(
            $_SERVER['HTTP_X_TIDEWAYS_PROFILER'],
            $_SERVER['HTTP_X_TW_ROOTID'],
            $_SERVER['HTTP_X_TW_SPANID'],
            $_SERVER['HTTP_X_TW_TRACEID'],
            $_SERVER['REMOTE_ADDR'],
            $_SERVER['HTTP_X_FORWARDED_FOR']
        );
    }

    public function testStartStopProfile()
    {
        $alwaysSample = 100;

        $backend = self::createBackend();
        $backend->expects($this->once())->method('socketStore');

        \Tideways\Profiler::start('foo', $alwaysSample);
        \Tideways\Profiler::setTransactionName(__CLASS__ . '::' . __METHOD__);

        $this->assertTrue(\Tideways\Profiler::isTracing());
        $this->assertTrue(\Tideways\Profiler::isStarted());

        \Tideways\Profiler::stop();

        $this->assertFalse(\Tideways\Profiler::isTracing());
{'fraction_non_alphanumeric': 0.14200769499825114, 'fraction_numerical': 0.0027981811822315496, 'mean_word_length': 2.9178082191780823, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '645548', 'n_tokens_mistral': 884, 'n_tokens_neox': 887, 'n_words': 114}