mirror of
https://github.com/xPaw/PHP-Source-Query.git
synced 2026-06-08 01:46:00 +02:00
Make test mock a queue
This commit is contained in:
@@ -12,10 +12,14 @@
|
|||||||
|
|
||||||
namespace xPaw\SourceQuery;
|
namespace xPaw\SourceQuery;
|
||||||
|
|
||||||
|
use xPaw\SourceQuery\Exception\InvalidPacketException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base socket interface
|
* Base socket interface
|
||||||
*
|
*
|
||||||
* @package xPaw\SourceQuery
|
* @package xPaw\SourceQuery
|
||||||
|
*
|
||||||
|
* @uses xPaw\SourceQuery\Exception\InvalidPacketException
|
||||||
*/
|
*/
|
||||||
abstract class BaseSocket
|
abstract class BaseSocket
|
||||||
{
|
{
|
||||||
|
|||||||
+17
-7
@@ -6,7 +6,19 @@
|
|||||||
|
|
||||||
class TestableSocket extends BaseSocket
|
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( )
|
public function Close( )
|
||||||
{
|
{
|
||||||
@@ -25,15 +37,13 @@
|
|||||||
|
|
||||||
public function Read( $Length = 1400 )
|
public function Read( $Length = 1400 )
|
||||||
{
|
{
|
||||||
if( strlen( $this->NextOutput ) === 0 )
|
if( $this->PacketQueue->Count === 0 )
|
||||||
{
|
{
|
||||||
throw new InvalidPacketException( 'Buffer is empty', InvalidPacketException::BUFFER_EMPTY );
|
throw new InvalidPacketException( 'Buffer is empty', InvalidPacketException::BUFFER_EMPTY );
|
||||||
}
|
}
|
||||||
|
|
||||||
$Buffer = new Buffer( );
|
$Buffer = new Buffer( );
|
||||||
$Buffer->Set( $this->NextOutput );
|
$Buffer->Set( $this->PacketQueue->pop() );
|
||||||
|
|
||||||
$this->NextOutput = '';
|
|
||||||
|
|
||||||
$this->ReadInternal( $Buffer, [ $this, 'Sherlock' ] );
|
$this->ReadInternal( $Buffer, [ $this, 'Sherlock' ] );
|
||||||
|
|
||||||
@@ -68,7 +78,7 @@
|
|||||||
*/
|
*/
|
||||||
public function testGetInfo( $RawInput, $ExpectedOutput )
|
public function testGetInfo( $RawInput, $ExpectedOutput )
|
||||||
{
|
{
|
||||||
$this->Socket->NextOutput = $RawInput;
|
$this->Socket->Queue( $RawInput );
|
||||||
|
|
||||||
$RealOutput = $this->SourceQuery->GetInfo();
|
$RealOutput = $this->SourceQuery->GetInfo();
|
||||||
|
|
||||||
@@ -102,7 +112,7 @@
|
|||||||
*/
|
*/
|
||||||
public function testBadGetInfo( $Data )
|
public function testBadGetInfo( $Data )
|
||||||
{
|
{
|
||||||
$this->Socket->NextOutput = $Data;
|
$this->Socket->Queue( $Data );
|
||||||
|
|
||||||
$this->SourceQuery->GetInfo();
|
$this->SourceQuery->GetInfo();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user