Add some GetInfo tests

pull/94/head
Pavel Djundik 9 years ago
parent af50a4a33a
commit 29597ff1b6

@ -1,6 +1,7 @@
sudo: false sudo: false
language: php language: php
php: php:
- 5.5
- 5.6 - 5.6
- hhvm - hhvm
- nightly - nightly
@ -11,6 +12,6 @@ notifications:
install: install:
- composer install --dev --no-interaction - composer install --dev --no-interaction
script: script:
- phpunit --configuration Tests/.phpunit.xml --verbose - phpunit --configuration Tests/.phpunit.xml
after_script: after_script:
- ./.codeclimate.sh - ./.codeclimate.sh

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true"> <phpunit colors="true"
bootstrap="../SourceQuery/bootstrap.php"
verbose="true">
<testsuites> <testsuites>
<testsuite name="Tests"> <testsuite name="Tests">
<file>./Tests.php</file> <file>./Tests.php</file>

@ -0,0 +1,21 @@
{
"Protocol": 17,
"HostName": "BombGame by xPaw & Co.",
"Map": "de_dust2",
"ModDir": "csgo",
"ModDesc": "Counter-Strike: Global Offensive",
"AppID": 730,
"Players": 0,
"MaxPlayers": 16,
"Bots": 0,
"Dedicated": "d",
"Os": "l",
"Password": false,
"Secure": true,
"Version": "1.35.0.7",
"ExtraDataFlags": 177,
"GamePort": 27036,
"SteamID": 90097713628897284,
"GameTags": "empty,*grp:1105381i,bombgame,secure",
"GameID": 730
}

@ -0,0 +1 @@
ffffffff4911426f6d6247616d652062792078506177202620436f2e0064655f6475737432006373676f00436f756e7465722d537472696b653a20476c6f62616c204f6666656e7369766500da02001000646c0001312e33352e302e3700b19c6904e0eca764174001656d7074792c2a6772703a31313035333831692c626f6d6267616d652c73656375726500da02000000000000

@ -0,0 +1,21 @@
{
"Protocol": 17,
"HostName": "Город Инноваций | Русский DarkRP",
"Map": "rp_bangclaw",
"ModDir": "garrysmod",
"ModDesc": "DarkRP",
"AppID": 4000,
"Players": 33,
"MaxPlayers": 40,
"Bots": 0,
"Dedicated": "d",
"Os": "l",
"Password": false,
"Secure": true,
"Version": "15.08.10",
"ExtraDataFlags": 177,
"GamePort": 27015,
"SteamID": 90097724371517447,
"GameTags": " gm:darkrp",
"GameID": 4000
}

@ -0,0 +1 @@
ffffffff4911d093d0bed180d0bed0b420d098d0bdd0bdd0bed0b2d0b0d186d0b8d0b9207c20d0a0d183d181d181d0bad0b8d0b9204461726b52500072705f62616e67636c6177006761727279736d6f64004461726b525000a00f212800646c000131352e30382e313000b1876907403c286717400120676d3a6461726b727000a00f000000000000

@ -0,0 +1,23 @@
{
"Protocol": 17,
"HostName": " FirePowered.org | Unusual Trade | !jackpot",
"Map": "trade_unusual_center_v3",
"ModDir": "tf",
"ModDesc": "Unusual Trading",
"AppID": 440,
"Players": 32,
"MaxPlayers": 32,
"Bots": 0,
"Dedicated": "d",
"Os": "l",
"Password": false,
"Secure": true,
"Version": "3032525",
"ExtraDataFlags": 241,
"GamePort": 27045,
"SteamID": 85568392920039468,
"SpecPort": 27050,
"SpecName": "ScamCam",
"GameTags": "FirePowered,alltalk,backpack.tf,increased_maxplayers,no_ads,noads,nopinion,norespawntime,trade,trading,unusual",
"GameID": 440
}

@ -0,0 +1 @@
ffffffff49112046697265506f77657265642e6f7267207c20556e757375616c205472616465207c20216a61636b706f740074726164655f756e757375616c5f63656e7465725f763300746600556e757375616c2054726164696e6700b801202000646c00013330333235323500f1a5692c00000000003001aa695363616d43616d0046697265506f77657265642c616c6c74616c6b2c6261636b7061636b2e74662c696e637265617365645f6d6178706c61796572732c6e6f5f6164732c6e6f6164732c6e6f70696e696f6e2c6e6f7265737061776e74696d652c74726164652c74726164696e672c756e757375616c00b801000000000000

@ -0,0 +1,19 @@
{
"Protocol": 7,
"HostName": "RKSzone.com | US Chicago | The Ship | Hunt",
"Map": "atalanta",
"ModDir": "ship",
"ModDesc": "The Ship",
"AppID": 2400,
"Players": 27,
"MaxPlayers": 32,
"Bots": 16,
"Dedicated": "d",
"Os": "w",
"Password": false,
"Secure": true,
"GameMode": 0,
"WitnessCount": 2,
"WitnessTime": 5,
"Version": "1.0.0.16"
}

@ -0,0 +1 @@
ffffffff4907524b537a6f6e652e636f6d207c205553204368696361676f207c205468652053686970207c2048756e74006174616c616e746100736869700054686520536869700060091b201064770001000205312e302e302e313600

@ -1,9 +1,8 @@
<?php <?php
require __DIR__ . '/../SourceQuery/bootstrap.php';
use xPaw\SourceQuery\BaseSocket; use xPaw\SourceQuery\BaseSocket;
use xPaw\SourceQuery\Exception\InvalidPacketException; use xPaw\SourceQuery\Exception\InvalidPacketException;
use xPaw\SourceQuery\SourceQuery; use xPaw\SourceQuery\SourceQuery;
use xPaw\SourceQuery\Buffer;
class TestableSocket extends BaseSocket class TestableSocket extends BaseSocket
{ {
@ -36,8 +35,15 @@
$this->NextOutput = ''; $this->NextOutput = '';
$this->ReadInternal( $Buffer, $this->Sherlock );
return $Buffer; return $Buffer;
} }
private function Sherlock( $Buffer, $Length )
{
return false;
}
} }
class SourceQueryTests extends PHPUnit_Framework_TestCase class SourceQueryTests extends PHPUnit_Framework_TestCase
@ -66,13 +72,51 @@
$RealOutput = $this->SourceQuery->GetInfo(); $RealOutput = $this->SourceQuery->GetInfo();
$this->assertEquals( $ExpectedOutput, $RealOutput ); foreach( $ExpectedOutput as $Key => $ExpectedValue )
{
$this->assertEquals( $ExpectedValue, $RealOutput[ $Key ], $Key );
}
} }
public function InfoProvider() public function InfoProvider()
{ {
// read from Tests/Info/ folder $DataProvider = [];
$Files = glob( __DIR__ . '/Info/*.raw', GLOB_ERR );
foreach( $Files as $File )
{
$DataProvider[] =
[
hex2bin( trim( file_get_contents( $File ) ) ),
json_decode( file_get_contents( str_replace( '.raw', '.json', $File ) ), true )
];
}
return $DataProvider;
}
/**
* @expectedException xPaw\SourceQuery\Exception\InvalidPacketException
* @dataProvider BadInfoProvider
*/
public function testBadGetInfo( $Data )
{
$this->Socket->NextOutput = $Data;
return [ [ '', '' ] ]; $this->SourceQuery->GetInfo();
}
public function BadInfoProvider( )
{
return
[
[ "" ],
[ "\xff\xff\xff\xff" ], // No type
[ "\xff\xff\xff\xff\x49" ], // Correct type, but no data after
[ "\xff\xff\xff\xff\x6D" ], // Old info packet, but tests are done for source
[ "\xff\xff\xff\xff\x11" ], // Wrong type
[ "\xff" ], // Should be 4 bytes, but it's 1
];
} }
} }

@ -29,7 +29,7 @@
}, },
"require-dev": "require-dev":
{ {
"phpunit/phpunit": "5.0.*", "phpunit/phpunit": "4.8.*",
"codeclimate/php-test-reporter": "dev-master" "codeclimate/php-test-reporter": "dev-master"
}, },
"autoload": "autoload":

Loading…
Cancel
Save