1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-03 18:04:08 +02:00

split parser and add tests

This commit is contained in:
Robin Appelman 2017-04-08 23:25:33 +02:00
commit ae39548ddb
11 changed files with 1801 additions and 102 deletions

View file

@ -0,0 +1,58 @@
<?php declare(strict_types=1);
namespace Demostf\API\Test\Providers;
use Demostf\API\Demo\Header;
use Demostf\API\Demo\HeaderParser;
use Demostf\API\Test\TestCase;
class HeaderParserTest extends TestCase {
public function testParseFile() {
$parser = new HeaderParser();
$expected = new Header([
'type' => 'HL2DEMO',
'version' => 3,
'protocol' => 24,
'server' => 'UGC Highlander Match',
'nick' => 'SourceTV Demo',
'map' => 'koth_product_rc8',
'game' => 'tf',
'duration' => 778.4849853515625,
'ticks' => 51899,
'frames' => 25703,
'sigon' => 818263
]);
$parsed = $parser->parseHeader(__DIR__ . '/../data/product.dem');
$this->assertEquals($expected->getServer(), $parsed->getServer());
$this->assertEquals($expected->getDuration(), $parsed->getDuration());
$this->assertEquals($expected->getTicks(), $parsed->getTicks());
$this->assertEquals($expected->getFrames(), $parsed->getFrames());
$this->assertEquals($expected->getGame(), $parsed->getGame());
$this->assertEquals($expected->getMap(), $parsed->getMap());
$this->assertEquals($expected->getNick(), $parsed->getNick());
$this->assertEquals($expected->getProtocol(), $parsed->getProtocol());
$this->assertEquals($expected->getSigon(), $parsed->getSigon());
$this->assertEquals($expected->getType(), $parsed->getType());
$this->assertEquals($expected->getVersion(), $parsed->getVersion());
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Not an HL2 demo
*/
public function testNonDemoShort() {
$parser = new HeaderParser();
$parser->parseString("short");
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Not an HL2 demo
*/
public function testNonDemoLong() {
$parser = new HeaderParser();
$parser->parseHeader(__FILE__);
}
}

37
tests/Demo/ParserTest.php Normal file
View file

@ -0,0 +1,37 @@
<?php declare(strict_types=1);
namespace Demostf\API\Test\Providers;
use Demostf\API\Demo\Parser;
use Demostf\API\Demo\RawParser;
use Demostf\API\Test\TestCase;
class ParserTest extends TestCase {
/** @var RawParser */
private $rawParser;
public function setUp() {
parent::setUp();
$this->rawParser = $this->getMockBuilder(RawParser::class)
->disableOriginalConstructor()
->getMock();
$this->rawParser->expects($this->any())
->method('parse')
->will($this->returnCallback(function ($path) {
$jsonPath = str_replace('.dem', '-raw.json', $path);
return json_decode(file_get_contents($jsonPath), true);
}));
}
public function testAnalyse() {
$parser = new Parser($this->rawParser);
$result = $parser->analyse(__DIR__ . '/../data/product.dem');
$expected = json_decode(file_get_contents(__DIR__ . '/../data/product-analyse.json'), true);
$this->assertEquals($expected, $result);
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

BIN
tests/data/product.dem Normal file

Binary file not shown.