<commit_before><?php

namespace Sabre\HTTP;

class MessageTest extends \PHPUnit_Framework_TestCase {

    function testConstruct() {

        $message = new MessageMock();
        $this->assertInstanceOf('Sabre\HTTP\Message', $message);

    }

    function testStreamBody() {

        $body = 'foo';
        $h = fopen('php://memory', 'r+');
        fwrite($h, $body);
        rewind($h);

        $message = new MessageMock();
        $message->setBody($h);

        $this->assertEquals($body, $message->getBodyAsString());
        rewind($h);
        $this->assertEquals($body, stream_get_contents($message->getBodyAsStream()));
        rewind($h);
        $this->assertEquals($body, stream_get_contents($message->getBody()));

    }

    function testStringBody() {

        $body = 'foo';

        $message = new MessageMock();
        $message->setBody($body);

        $this->assertEquals($body, $message->getBodyAsString());
        $this->assertEquals($body, stream_get_contents($message->getBodyAsStream()));
        $this->assertEquals($body, $message->getBody());

    }


    function testGetEmptyBodyStream() {

        $message = new MessageMock();
        $body = $message->getBodyAsStream();

        $this->assertEquals('', stream_get_contents($body));

    }

    function testGetEmptyBodyString() {

        $message = new MessageMock();
        $body = $message->getBodyAsString();

        $this->assertEquals('', $body);

    }

    function testHeaders() {

        $message = new MessageMock();
        $message->setHeader('X-Foo', 'bar');

        // Testing caselessness
        $this->assertEquals('bar', $message->getHeader('X-Foo'));
        $this->assertEquals('bar', $message->getHeader('x-fOO'));

        $this->assertTrue(
            $message->removeHeader('X-FOO')
        );
        $this->assertNull($message->getHeader('X-Foo'));
        $this->assertFalse(
            $message->removeHeader('X-FOO')
        );

    }

    function testSendBody() {

        $message = new MessageMock();

        // String
        $message->setBody('foo');

        // Stream
        $h = fopen('php://memory','r+');
        fwrite($h,'bar');
        rewind($h);
        $message->setBody($h);

        $body = $message->getBody();
        rewind($body);

        $this->assertEquals('bar', stream_get_contents($body));

    }

    function testSetHeaders() {

        $message = new MessageMock();
        $message->setHeaders([
            'a' => 'b',
        ]);
        $message->setHeaders([
            'c' => 'd',
        ]);
        $this->assertEquals('b', $message->getHeader('a'));

    }

    function testAddHeaders() {

        $message = new MessageMock();
        $message->addHeaders([
            'a' => 'b',
        ]);
        $message->addHeaders([
            'c' => 'd',
        ]);
        $this->assertEquals('b', $message->getHeader('a'));<commit_msg>Clearer tests.<commit_after><?php

namespace Sabre\HTTP;

class MessageTest extends \PHPUnit_Framework_TestCase {

    function testConstruct() {

        $message = new MessageMock();
        $this->assertInstanceOf('Sabre\HTTP\Message', $message);

    }

    function testStreamBody() {

        $body = 'foo';
        $h = fopen('php://memory', 'r+');
        fwrite($h, $body);
        rewind($h);

        $message = new MessageMock();
        $message->setBody($h);

        $this->assertEquals($body, $message->getBodyAsString());
        rewind($h);
        $this->assertEquals($body, stream_get_contents($message->getBodyAsStream()));
        rewind($h);
        $this->assertEquals($body, stream_get_contents($message->getBody()));

    }

    function testStringBody() {

        $body = 'foo';

        $message = new MessageMock();
        $message->setBody($body);

        $this->assertEquals($body, $message->getBodyAsString());
        $this->assertEquals($body, stream_get_contents($message->getBodyAsStream()));
        $this->assertEquals($body, $message->getBody());

    }


    function testGetEmptyBodyStream() {

        $message = new MessageMock();
        $body = $message->getBodyAsStream();

        $this->assertEquals('', stream_get_contents($body));

    }

    function testGetEmptyBodyString() {

        $message = new MessageMock();
        $body = $message->getBodyAsString();

        $this->assertEquals('', $body);

    }

    function testHeaders() {

        $message = new MessageMock();
        $message->setHeader('X-Foo', 'bar');

        // Testing caselessness
        $this->assertEquals('bar', $message->getHeader('X-Foo'));
        $this->assertEquals('bar', $message->getHeader('x-fOO'));

        $this->assertTrue(
            $message->removeHeader('X-FOO')
        );
        $this->assertNull($message->getHeader('X-Foo'));
        $this->assertFalse(
            $message->removeHeader('X-FOO')
        );

    }

    function testSetHeaders() {

        $message = new MessageMock();

        $headers = [
            'X-Foo' => '1',
            'X-Bar' => '2',
        ];

        $message->setHeaders($headers);
        $this->assertEquals($headers, $message->getHeaders());

        $message->setHeaders([
            'X-Foo' => ['3','4'],
            'X-Bar' => '5',
        ]);

        $expected = [
            'X-Foo' => '3,4',
            'X-Bar' => '5',
        ];

        $this->assertEquals($expected, $message->getHeaders());

    }

    function testAddHeaders() {

        $message = new MessageMock();

        $headers = [
            'X-Foo' => '1',
            'X-Bar' => '2',
        ];

        $message->addHeaders($headers);
        $this->assertEquals($headers, $message->getHeaders());

        $message->addHeaders([
            'X-Foo' => ['3','4'],
            'X-Bar' => '5',
        ]);

        $expected = [
            'X-Foo' => '1,3,4',
            'X-Bar' => '2,5',
        ];

        $this->assertEquals($expected, $message->getHeaders());

    }

    function testSendBody() {

        $message = new MessageMock();

        // String
        $message->setBody('foo');

        // Stream
        $h = fopen('php://memory','r+');
        fwrite($h,'bar');
        rewind($h);
        $message->setBody($h);

        $body = $message->getBody();
        rewind($body);

        $this->assertEquals('bar', stream_get_contents($body));
{'fraction_non_alphanumeric': 0.18610891870560378, 'fraction_numerical': 0.002841357537490134, 'mean_word_length': 2.172759138708062, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 107, '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': '4482213', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1794, 'n_words': 284}