1
0
mirror of https://github.com/xPaw/PHP-Source-Query.git synced 2026-05-18 13:53:35 +02:00

Make test mock a queue

This commit is contained in:
Pavel Djundik
2015-10-22 00:26:31 +03:00
parent c001fe6633
commit 4a73f14902
2 changed files with 21 additions and 7 deletions
+17 -7
View File
@@ -6,7 +6,19 @@
class TestableSocket extends BaseSocket
{
public $NextOutput = '';
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( )
{
@@ -25,15 +37,13 @@
public function Read( $Length = 1400 )
{
if( strlen( $this->NextOutput ) === 0 )
if( $this->PacketQueue->Count === 0 )
{
throw new InvalidPacketException( 'Buffer is empty', InvalidPacketException::BUFFER_EMPTY );
}
$Buffer = new Buffer( );
$Buffer->Set( $this->NextOutput );
$this->NextOutput = '';
$Buffer->Set( $this->PacketQueue->pop() );
$this->ReadInternal( $Buffer, [ $this, 'Sherlock' ] );
@@ -68,7 +78,7 @@
*/
public function testGetInfo( $RawInput, $ExpectedOutput )
{
$this->Socket->NextOutput = $RawInput;
$this->Socket->Queue( $RawInput );
$RealOutput = $this->SourceQuery->GetInfo();
@@ -102,7 +112,7 @@
*/
public function testBadGetInfo( $Data )
{
$this->Socket->NextOutput = $Data;
$this->Socket->Queue( $Data );
$this->SourceQuery->GetInfo();
}