From 4a73f14902534dc04d3cbf8d37b6577112dda47d Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 22 Oct 2015 00:26:31 +0300 Subject: [PATCH] Make test mock a queue --- SourceQuery/BaseSocket.php | 4 ++++ Tests/Tests.php | 24 +++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/SourceQuery/BaseSocket.php b/SourceQuery/BaseSocket.php index 7ef4d8d..331d791 100644 --- a/SourceQuery/BaseSocket.php +++ b/SourceQuery/BaseSocket.php @@ -12,10 +12,14 @@ namespace xPaw\SourceQuery; + use xPaw\SourceQuery\Exception\InvalidPacketException; + /** * Base socket interface * * @package xPaw\SourceQuery + * + * @uses xPaw\SourceQuery\Exception\InvalidPacketException */ abstract class BaseSocket { diff --git a/Tests/Tests.php b/Tests/Tests.php index aa24dc9..0aae42d 100644 --- a/Tests/Tests.php +++ b/Tests/Tests.php @@ -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(); }