<commit_before><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2010, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace lithium\tests\cases\util\socket;

use \lithium\tests\mocks\util\socket\MockStream;

class StreamTest extends \lithium\test\Unit {

	protected $_testConfig = array(
		'persistent' => false,
		'protocol' => 'tcp',
		'host' => 'localhost',
		'login' => 'root',
		'password' => '',
		'port' => 80,
		'timeout' => 2
	);

	public function testAllMethodsNoConnection() {
		$stream = new MockStream(array('protocol' => null));
		$this->assertFalse($stream->open());
		$this->assertTrue($stream->close());
		$this->assertFalse($stream->timeout(2));
		$this->assertFalse($stream->encoding('UTF-8'));
		$this->assertFalse($stream->write(null));
		$this->assertFalse($stream->read());
	}

	public function testOpen() {
		$stream = new MockStream($this->_testConfig);
		$result = $stream->open();
		$this->assertTrue($result);

		$result = $stream->resource();
		$this->assertTrue(is_resource($result));
	}

	public function testClose() {
		$stream = new MockStream($this->_testConfig);
		$result = $stream->open();
		$this->assertTrue($result);

		$result = $stream->close();
		$this->assertTrue($result);

		$result = $stream->resource();
		$this->assertFalse(is_resource($result));
	}

	public function testTimeout() {
		$stream = new MockStream($this->_testConfig);
		$result = $stream->open();
		$stream->timeout(10);
		$result = $stream->resource();
		$this->assertTrue(is_resource($result));
	}

	public function testEncoding() {
		$stream = new MockStream($this->_testConfig);
		$result = $stream->open();
		$stream->encoding('UTF-8');
		$result = $stream->resource();
		$this->assertTrue(is_resource($result));
	}

	public function testWriteAndRead() {
		$stream = new MockStream($this->_testConfig);
		$result = $stream->open();
		$data = "GET / HTTP/1.1\r\n";
		$data .= "Host: localhost\r\n";
		$data .= "Connection: Close\r\n\r\n";
		$this->assertTrue($stream->write($data));

		$result = $stream->read();
		$this->assertPattern("/^HTTP/", $result);
	}
}

?><commit_msg>Adding test coverage for `util\socket\Stream`<commit_after><?php
/**
 * Lithium: the most rad php framework
 *
 * @copyright     Copyright 2010, Union of RAD (http://union-of-rad.org)
 * @license       http://opensource.org/licenses/bsd-license.php The BSD License
 */

namespace lithium\tests\cases\util\socket;

use \lithium\tests\mocks\util\socket\MockStream;

class StreamTest extends \lithium\test\Unit {

	protected $_testConfig = array(
		'persistent' => false,
		'protocol' => 'tcp',
		'host' => 'localhost',
		'login' => 'root',
		'password' => '',
		'port' => 80,
		'timeout' => 2
	);

	public function testAllMethodsNoConnection() {
		$stream = new MockStream(array('protocol' => null));
		$this->assertFalse($stream->open());
		$this->assertTrue($stream->close());
		$this->assertFalse($stream->timeout(2));
		$this->assertFalse($stream->encoding('UTF-8'));
		$this->assertFalse($stream->write(null));
		$this->assertFalse($stream->read());
		$this->assertTrue($stream->eof());
		$this->assertNull($stream->send(''));
	}

	public function testOpen() {
		$stream = new MockStream($this->_testConfig);
		$result = $stream->open();
		$this->assertTrue($result);

		$result = $stream->resource();
		$this->assertTrue(is_resource($result));
	}

	public function testClose() {
		$stream = new MockStream($this->_testConfig);
		$result = $stream->open();
		$this->assertTrue($result);

		$result = $stream->close();
		$this->assertTrue($result);

		$result = $stream->resource();
		$this->assertFalse(is_resource($result));
	}

	public function testTimeout() {
		$stream = new MockStream($this->_testConfig);
		$result = $stream->open();
		$stream->timeout(10);
		$result = $stream->resource();
		$this->assertTrue(is_resource($result));
	}

	public function testEncoding() {
		$stream = new MockStream($this->_testConfig);
		$result = $stream->open();
		$stream->encoding('UTF-8');
		$result = $stream->resource();
		$this->assertTrue(is_resource($result));

		$stream = new MockStream($this->_testConfig + array('encoding' => 'UTF-8'));
		$result = $stream->open();
		$result = $stream->resource();
		$this->assertTrue(is_resource($result));
	}

	public function testWriteAndRead() {
		$stream = new MockStream($this->_testConfig);
		$result = $stream->open();
		$data = "GET / HTTP/1.1\r\n";
		$data .= "Host: localhost\r\n";
		$data .= "Connection: Close\r\n\r\n";
		$this->assertTrue($stream->write($data));

		$result = $stream->eof();
		$this->assertFalse($result);

		$result = $stream->read();
		$this->assertPattern("/^HTTP/", $result);
	}

	public function testSend() {
		$stream = new MockStream($this->_testConfig);
		$result = $stream->open();
		$data = "GET / HTTP/1.1\r\n";
		$data .= "Host: localhost\r\n";
		$data .= "Connection: Close\r\n\r\n";

		$result = $stream->send($data, array('classes' => array('response' => '\lithium\http\Response')));
		$this->assertNotEqual(null, $result);
	}
}

?>
{'fraction_non_alphanumeric': 0.21248780487804877, 'fraction_numerical': 0.006048780487804878, 'mean_word_length': 4.5476190476190474, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 118, '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': '3015915', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1698, 'n_words': 301}