mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 09:54:17 +02:00
cleanup and tests
This commit is contained in:
parent
ae39548ddb
commit
05f48fd0a0
7 changed files with 110 additions and 25 deletions
27
tests/Data/DemoPlayerTest.php
Normal file
27
tests/Data/DemoPlayerTest.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test\Data;
|
||||
|
||||
use Demostf\API\Data\DemoPlayer;
|
||||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class DemoPlayerTest extends TestCase {
|
||||
public function testParseSerialize() {
|
||||
$data = [
|
||||
'id' => 1,
|
||||
'user_id' => 2,
|
||||
'name' => 'foo',
|
||||
'team' => 'red',
|
||||
'class' => 'sniper',
|
||||
'steamid' => 'asd',
|
||||
'avatar' => 'asd.png',
|
||||
'kills' => 5,
|
||||
'assists' => 3,
|
||||
'deaths' => 7
|
||||
];
|
||||
|
||||
$demoPlayer = DemoPlayer::fromRow($data);
|
||||
|
||||
$this->assertEquals($data, $demoPlayer->jsonSerialize());
|
||||
}
|
||||
}
|
||||
32
tests/Demo/DemoStoreTest.php
Normal file
32
tests/Demo/DemoStoreTest.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test\Data;
|
||||
|
||||
use Demostf\API\Demo\DemoStore;
|
||||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class DemoStoreTest extends TestCase {
|
||||
public function testStore() {
|
||||
$targetDir = tempnam(sys_get_temp_dir(), 'dummy_target_');
|
||||
unlink($targetDir);
|
||||
mkdir($targetDir);
|
||||
|
||||
$demoStore = new DemoStore($targetDir, 'static.example.com');
|
||||
|
||||
$file = tempnam(sys_get_temp_dir(), 'dummy_');
|
||||
file_put_contents($file, 'foobar');
|
||||
|
||||
$url = $demoStore->store($file, 'foodemo.dem');
|
||||
|
||||
$this->assertStringEndsWith('/foodemo.dem', $url);
|
||||
$this->assertStringStartsWith('https://static.example.com/', $url);
|
||||
|
||||
$subPath = str_replace('https://static.example.com/', '', $url);
|
||||
|
||||
$this->assertStringEqualsFile($targetDir . '/' . $subPath, 'foobar');
|
||||
unlink($targetDir . '/' . $subPath);
|
||||
rmdir(dirname($targetDir . '/' . $subPath));
|
||||
rmdir(dirname($targetDir . '/' . $subPath, 2));
|
||||
rmdir($targetDir);
|
||||
}
|
||||
}
|
||||
|
|
@ -55,4 +55,12 @@ class HeaderParserTest extends TestCase {
|
|||
$parser = new HeaderParser();
|
||||
$parser->parseHeader(__FILE__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testNonExisting() {
|
||||
$parser = new HeaderParser();
|
||||
$parser->parseHeader('/non/existing');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use Demostf\API\Demo\RawParser;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class ParserTest extends TestCase {
|
||||
/** @var RawParser */
|
||||
/** @var RawParser|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $rawParser;
|
||||
|
||||
public function setUp() {
|
||||
|
|
@ -34,4 +34,22 @@ class ParserTest extends TestCase {
|
|||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testFailedParse() {
|
||||
/** @var RawParser|\PHPUnit_Framework_MockObject_MockObject $rawParser */
|
||||
$rawParser = $this->getMockBuilder(RawParser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$parser = new Parser($rawParser);
|
||||
|
||||
$rawParser->expects($this->any())
|
||||
->method('parse')
|
||||
->willReturn(null);
|
||||
|
||||
$parser->analyse('foo');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue