<commit_before><?php
	use xPaw\SourceQuery\BaseSocket;
	use xPaw\SourceQuery\Exception\InvalidPacketException;
	use xPaw\SourceQuery\SourceQuery;
	use xPaw\SourceQuery\Buffer;
	
	class TestableSocket extends BaseSocket
	{
		private $PacketQueue;
		
		public function __construct( )
		{
			$this->PacketQueue = new \SplQueue();
			$this->PacketQueue->setIteratorMode( \SplDoublyLinkedList::IT_MODE_DELETE );
			
		}
		
		public function Queue( $Data )
		{
			$this->PacketQueue->push( $Data );
		}
		
		public function Close( )
		{
			//
		}
		
		public function Open( $Ip, $Port, $Timeout, $Engine )
		{
			//
		}
		
		public function Write( $Header, $String = '' )
		{
			//
		}
		
		public function Read( $Length = 1400 )
		{
			if( $this->PacketQueue->Count === 0 )
			{
				throw new InvalidPacketException( 'Buffer is empty', InvalidPacketException::BUFFER_EMPTY );
			}
			
			$Buffer = new Buffer( );
			$Buffer->Set( $this->PacketQueue->pop() );
			
			$this->ReadInternal( $Buffer, [ $this, 'Sherlock' ] );
			
			return $Buffer;
		}
		
		public function Sherlock( $Buffer, $Length )
		{
			return false;
		}
	}
	
	class SourceQueryTests extends PHPUnit_Framework_TestCase
	{
		private $Socket;
		private $SourceQuery;
		
		public function setUp()
		{
			$this->Socket = new TestableSocket();
			$this->SourceQuery = new SourceQuery( $this->Socket );
			$this->SourceQuery->Connect( 1, 2 );
		}
		
		public function tearDown()
		{
			$this->SourceQuery->Disconnect();
		}
		
		/**
		 * @dataProvider InfoProvider
		 */
		public function testGetInfo( $RawInput, $ExpectedOutput )
		{
			$this->Socket->Queue( $RawInput );
			
			$RealOutput = $this->SourceQuery->GetInfo();
			
			foreach( $ExpectedOutput as $Key => $ExpectedValue )
			{
				$this->assertEquals( $ExpectedValue, $RealOutput[ $Key ], $Key );
			}
		}<commit_msg>Add timeout and not connected test<commit_after><?php
	use xPaw\SourceQuery\BaseSocket;
	use xPaw\SourceQuery\Exception\InvalidPacketException;
	use xPaw\SourceQuery\SourceQuery;
	use xPaw\SourceQuery\Buffer;
	
	class TestableSocket extends BaseSocket
	{
		private $PacketQueue;
		
		public function __construct( )
		{
			$this->PacketQueue = new \SplQueue();
			$this->PacketQueue->setIteratorMode( \SplDoublyLinkedList::IT_MODE_DELETE );
			
		}
		
		public function Queue( $Data )
		{
			$this->PacketQueue->push( $Data );
		}
		
		public function Close( )
		{
			//
		}
		
		public function Open( $Ip, $Port, $Timeout, $Engine )
		{
			//
		}
		
		public function Write( $Header, $String = '' )
		{
			//
		}
		
		public function Read( $Length = 1400 )
		{
			if( $this->PacketQueue->Count === 0 )
			{
				throw new InvalidPacketException( 'Buffer is empty', InvalidPacketException::BUFFER_EMPTY );
			}
			
			$Buffer = new Buffer( );
			$Buffer->Set( $this->PacketQueue->pop() );
			
			$this->ReadInternal( $Buffer, [ $this, 'Sherlock' ] );
			
			return $Buffer;
		}
		
		public function Sherlock( $Buffer, $Length )
		{
			return false;
		}
	}
	
	class SourceQueryTests extends PHPUnit_Framework_TestCase
	{
		private $Socket;
		private $SourceQuery;
		
		public function setUp()
		{
			$this->Socket = new TestableSocket();
			$this->SourceQuery = new SourceQuery( $this->Socket );
			$this->SourceQuery->Connect( 1, 2 );
		}
		
		public function tearDown()
		{
			$this->SourceQuery->Disconnect();
			
			unset( $this->SourceQuery );
		}
		
		/**
		 * @expectedException xPaw\SourceQuery\Exception\InvalidArgumentException
		 */
		public function testInvalidTimeout()
		{
			$SourceQuery = new SourceQuery( );
			$SourceQuery->Connect( 1, 2, -1 );
		}
		
		/**
		 * @expectedException xPaw\SourceQuery\Exception\SocketException
		 */
		public function testNotConnectedGetInfo()
		{
			$this->SourceQuery->Disconnect();
			$this->SourceQuery->GetInfo();
		}
		
		/**
		 * @expectedException xPaw\SourceQuery\Exception\SocketException
		 */
		public function testNotConnectedPing()
		{
			$this->SourceQuery->Disconnect();
			$this->SourceQuery->Ping();
		}
		
		/**
		 * @expectedException xPaw\SourceQuery\Exception\SocketException
		 */
		public function testNotConnectedGetPlayers()
		{
			$this->SourceQuery->Disconnect();
			$this->SourceQuery->GetPlayers();
		}
		
		/**
		 * @expectedException xPaw\SourceQuery\Exception\SocketException
		 */
		public function testNotConnectedGetRules()
		{
			$this->SourceQuery->Disconnect();
			$this->SourceQuery->GetRules();
		}
		
		/**
		 * @dataProvider InfoProvider
		 */
		public function testGetInfo( $RawInput, $ExpectedOutput )
		{
			$this->Socket->Queue( $RawInput );
			
			$RealOutput = $this->SourceQuery->GetInfo();
			
			foreach( $ExpectedOutput as $Key => $ExpectedValue )
			{
				$this->assertEquals( $ExpectedValue, $RealOutput[ $Key ], $Key );
			}
		}
{'fraction_non_alphanumeric': 0.14180826515628278, 'fraction_numerical': 0.0035661841829242712, 'mean_word_length': 3.18612818261633, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 69, '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': '5766199', 'n_tokens_mistral': 1882, 'n_tokens_neox': 1493, 'n_words': 293}