<commit_before><?php
namespace Test\Statsd\Client;

use Statsd\Client\RelativeTimer;
use Statsd\Client;

class RelativeTimerTest extends \PHPUnit_Framework_TestCase
{
    public function testGetters()
    {
        $client = new Client();
        $timer = new RelativeTimer($client, 1500);
        $this->assertSame($client, $timer->getClient());
        $this->assertEquals(1500, $timer->getReferenceTimestamp());
    }

    public function testDefaultReferenceIsNow()
    {
        $testStart = microtime(true);
        $timer = new RelativeTimer(new Client());
        $this->assertGreaterThanOrEqual($testStart, $timer->getReferenceTimestamp());
    }

    public function testSendReturnsTimerSelfReferenceForFluentApi()
    {
        $timer = new RelativeTimer($this->createClientWithMockedSocket());
        $this->assertSame($timer, $timer->send('foo.bar'));
    }

    private function createClientWithMockedSocket()
    {<commit_msg>Add a test for RelativeTimer send() to make sure it sends metrics<commit_after><?php
namespace Test\Statsd\Client;

use Statsd\Client\RelativeTimer;
use Statsd\Client;

class RelativeTimerTest extends \PHPUnit_Framework_TestCase
{
    public function testGetters()
    {
        $client = new Client();
        $timer = new RelativeTimer($client, 1500);
        $this->assertSame($client, $timer->getClient());
        $this->assertEquals(1500, $timer->getReferenceTimestamp());
    }

    public function testDefaultReferenceIsNow()
    {
        $testStart = microtime(true);
        $timer = new RelativeTimer(new Client());
        $this->assertGreaterThanOrEqual($testStart, $timer->getReferenceTimestamp());
    }

    public function testSendDurationSinceReference()
    {
        $self = $this;

        $sockMock = $this->mockConnection();
        $sockMock->expects($this->once())->method('send')
            ->with(
                $this->matchesRegularExpression('/^foo\.bar\:\d{1,2}\|ms/')
            );

        $client =  new Client(array('connection' => $sockMock));

        $timer = new RelativeTimer($client);
        $timer->send('foo.bar');
    }

    public function testSendReturnsTimerSelfReferenceForFluentApi()
    {
        $timer = new RelativeTimer($this->createClientWithMockedSocket());
        $this->assertSame($timer, $timer->send('foo.bar'));
    }

    private function createClientWithMockedSocket()
    {
{'fraction_non_alphanumeric': 0.1350104821802935, 'fraction_numerical': 0.007547169811320755, 'mean_word_length': 3.3381818181818184, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '2000563', 'n_tokens_mistral': 686, 'n_tokens_neox': 645, 'n_words': 123}