<commit_before><?php
class ClientTest extends PHPUnit_Framework_TestCase {

    public function setUp()
    {
        $this->fake_uri = 'foo://bar';
    }

    public function tearDown()
    {
        Spray::reset();
    }

    private function stubResponse($body)
    {
        Spray::stub($this->fake_uri, array('raw' => $body));
    }

    public function getEmptyRequest()
    {
        $request = $this->getMock('Object', array('getJSON','getArray'));
        $request->expects($this->any())
                ->method('getJSON')
                ->will($this->returnValue(null));
        $request->expects($this->any())
                ->method('getArray')
                ->will($this->returnValue(null));
        return $request;
    }

    public function getEmptyResponse()
    {
        return $this->getMock('Object');
    }

    public function getMockClient($methods = array(), $returns_once = null)
    {
        $client = $this->getMock('Junior\Client',
                                 $methods,
                                 array(),
                                 '',
                                 false);

        if ($returns_once !== null) {
            $client->expects($this->once())
                   ->method('send')
                   ->will($this->returnValue($returns_once));
        }

        return $client;
    }

    public function testSendRequestGoodId()
    {
        $request = $this->getEmptyRequest();
        $request->id = 10;

        $response = $this->getEmptyResponse();
        $response->id = 10;
        $response->result = 'foo';

        $client = $this->getMockClient(array('send'), $response);

        $this->assertEquals('foo', $client->sendRequest($request));
    }

    public function testSendRequestBadId()
    {
        $request = $this->getEmptyRequest();
        $request->id = 10;

        $response = $this->getEmptyResponse();
        $response->id = 11;

        $client = $this->getMockClient(array('send'), $response);

        $this->setExpectedException('Junior\Clientside\Exception');

        $client->sendRequest($request);
    }

    public function testSendNotifyGood()
    {
        $request = $this->getEmptyRequest();
        $request->id = null;

        $client = $this->getMockClient(array('send'), true);

        $this->assertTrue($client->sendNotify($request));
    }

    public function testSendNotifyBad()
    {
        $request = $this->getEmptyRequest();
        $request->id = 10;

        $client = $this->getMockClient(array('send'));
        $client->expects($this->never())->method('send');

        $this->setExpectedException('Junior\Clientside\Exception');

        $client->sendNotify($request);
    }
<commit_msg>write test for pull request #8<commit_after><?php
class ClientTest extends PHPUnit_Framework_TestCase {

    public function setUp()
    {
        $this->fake_uri = 'foo://bar';
    }

    public function tearDown()
    {
        Spray::reset();
    }

    private function stubResponse($body)
    {
        Spray::stub($this->fake_uri, array('raw' => $body));
    }

    public function getEmptyRequest()
    {
        $request = $this->getMock('Object', array('getJSON','getArray'));
        $request->expects($this->any())
                ->method('getJSON')
                ->will($this->returnValue(null));
        $request->expects($this->any())
                ->method('getArray')
                ->will($this->returnValue(null));
        return $request;
    }

    public function getEmptyResponse()
    {
        return $this->getMock('Object');
    }

    public function getMockClient($methods = array(), $returns_once = null)
    {
        $client = $this->getMock('Junior\Client',
                                 $methods,
                                 array(),
                                 '',
                                 false);

        if ($returns_once !== null) {
            $client->expects($this->once())
                   ->method('send')
                   ->will($this->returnValue($returns_once));
        }

        return $client;
    }

    public function testSendRequestGoodId()
    {
        $request = $this->getEmptyRequest();
        $request->id = 10;

        $response = $this->getEmptyResponse();
        $response->id = 10;
        $response->result = 'foo';

        $client = $this->getMockClient(array('send'), $response);

        $this->assertEquals('foo', $client->sendRequest($request));
    }

    public function testSendRequestBadId()
    {
        $request = $this->getEmptyRequest();
        $request->id = 10;

        $response = $this->getEmptyResponse();
        $response->id = 11;

        $client = $this->getMockClient(array('send'), $response);

        $this->setExpectedException('Junior\Clientside\Exception');

        $client->sendRequest($request);
    }

    public function testReceiveErrorCodeZero()
    {
        $request = $this->getEmptyRequest();
        $request->id = 11;

        $response = $this->getEmptyResponse();
        $response->id = 11;
        $response->error_code = 0;

        $client = $this->getMockClient(array('send'), $response);

        $this->setExpectedException('Junior\Clientside\Exception');

        $client->sendRequest($request);
    }

    public function testSendNotifyGood()
    {
        $request = $this->getEmptyRequest();
        $request->id = null;

        $client = $this->getMockClient(array('send'), true);

        $this->assertTrue($client->sendNotify($request));
    }

    public function testSendNotifyBad()
    {
        $request = $this->getEmptyRequest();
        $request->id = 10;

        $client = $this->getMockClient(array('send'));
        $client->expects($this->never())->method('send');

        $this->setExpectedException('Junior\Clientside\Exception');

        $client->sendNotify($request);
    }

{'fraction_non_alphanumeric': 0.16056529882513196, 'fraction_numerical': 0.0044270389919972754, 'mean_word_length': 2.0673629242819844, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3379519', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1576, 'n_words': 253}