mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 09:54:17 +02:00
Add php-cs-fixer
This commit is contained in:
parent
e00e6ece5f
commit
309ae17036
54 changed files with 4900 additions and 4106 deletions
|
|
@ -6,22 +6,22 @@ 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
|
||||
];
|
||||
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);
|
||||
$demoPlayer = DemoPlayer::fromRow($data);
|
||||
|
||||
$this->assertEquals($data, $demoPlayer->jsonSerialize());
|
||||
}
|
||||
$this->assertEquals($data, $demoPlayer->jsonSerialize());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,95 +18,96 @@ use Demostf\API\Providers\UserProvider;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class DemoSaverTest extends TestCase {
|
||||
public function testSave() {
|
||||
public function testSave() {
|
||||
$steamId1 = $this->getSteamId('1234567', 'user1');
|
||||
$steamId2 = $this->getSteamId('2345678', 'user2');
|
||||
|
||||
$steamId1 = $this->getSteamId('1234567', 'user1');
|
||||
$steamId2 = $this->getSteamId('2345678', 'user2');
|
||||
$userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$demoProvider = new DemoProvider($this->getDatabaseConnection());
|
||||
$chatProvider = new ChatProvider($this->getDatabaseConnection());
|
||||
|
||||
$userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$demoProvider = new DemoProvider($this->getDatabaseConnection());
|
||||
$chatProvider = new ChatProvider($this->getDatabaseConnection());
|
||||
$userProvider->store($steamId1);
|
||||
$userProvider->store($steamId2);
|
||||
|
||||
$userProvider->store($steamId1);
|
||||
$userProvider->store($steamId2);
|
||||
$upload = new Upload(
|
||||
'foodemo',
|
||||
'DER',
|
||||
'ULB',
|
||||
$userProvider->getUserId('2345678'),
|
||||
'securehash'
|
||||
);
|
||||
|
||||
$upload = new Upload(
|
||||
'foodemo',
|
||||
'DER',
|
||||
'ULB',
|
||||
$userProvider->getUserId('2345678'),
|
||||
'securehash'
|
||||
);
|
||||
$header = new Header(
|
||||
'HL2DEMO',
|
||||
12,
|
||||
13,
|
||||
'My Server',
|
||||
'STV',
|
||||
'pl_badwater',
|
||||
'tf',
|
||||
60,
|
||||
60 * 60,
|
||||
2,
|
||||
1
|
||||
);
|
||||
|
||||
$header = new Header(
|
||||
'HL2DEMO',
|
||||
12,
|
||||
13,
|
||||
'My Server',
|
||||
'STV',
|
||||
'pl_badwater',
|
||||
'tf',
|
||||
60,
|
||||
60 * 60,
|
||||
2,
|
||||
1
|
||||
);
|
||||
$parsed = new ParsedDemo(
|
||||
2,
|
||||
3,
|
||||
[
|
||||
new ChatMessage('user1', 12, 'msg1'),
|
||||
new ChatMessage('user2', 13, 'msg2')
|
||||
],
|
||||
[
|
||||
new ParsedPlayer('user1', 1, '1234567', 'red', 'scout'),
|
||||
new ParsedPlayer('user2', 2, '2345678', 'blue', 'soldier'),
|
||||
],
|
||||
[
|
||||
new ParsedKill(1, 0, 2, 'pan'),
|
||||
new ParsedKill(1, 2, 2, 'pan'),
|
||||
new ParsedKill(2, 0, 1, 'pan'),
|
||||
]
|
||||
);
|
||||
|
||||
$parsed = new ParsedDemo(2, 3,
|
||||
[
|
||||
new ChatMessage('user1', 12, 'msg1'),
|
||||
new ChatMessage('user2', 13, 'msg2')
|
||||
],
|
||||
[
|
||||
new ParsedPlayer('user1', 1, '1234567', 'red', 'scout'),
|
||||
new ParsedPlayer('user2', 2, '2345678', 'blue', 'soldier'),
|
||||
],
|
||||
[
|
||||
new ParsedKill(1, 0, 2, 'pan'),
|
||||
new ParsedKill(1, 2, 2, 'pan'),
|
||||
new ParsedKill(2, 0, 1, 'pan'),
|
||||
]
|
||||
);
|
||||
$saver = new DemoSaver(
|
||||
new KillProvider($this->getDatabaseConnection()),
|
||||
new PlayerProvider($this->getDatabaseConnection()),
|
||||
$chatProvider,
|
||||
$userProvider,
|
||||
$demoProvider
|
||||
);
|
||||
|
||||
$saver = new DemoSaver(
|
||||
new KillProvider($this->getDatabaseConnection()),
|
||||
new PlayerProvider($this->getDatabaseConnection()),
|
||||
$chatProvider,
|
||||
$userProvider,
|
||||
$demoProvider
|
||||
);
|
||||
$storedDemo = new StoredDemo('http://example.com/foo', 'foo', 'example');
|
||||
|
||||
$storedDemo = new StoredDemo('http://example.com/foo', 'foo', 'example');
|
||||
$demoId = $saver->saveDemo($parsed, $header, $storedDemo, $upload);
|
||||
|
||||
$demoId = $saver->saveDemo($parsed, $header, $storedDemo, $upload);
|
||||
$retrievedDemo = $demoProvider->get($demoId, true);
|
||||
|
||||
$retrievedDemo = $demoProvider->get($demoId, true);
|
||||
$this->assertEquals(2, $retrievedDemo->getPlayerCount());
|
||||
$this->assertEquals(2, $retrievedDemo->getRedScore());
|
||||
$this->assertEquals(3, $retrievedDemo->getBlueScore());
|
||||
$this->assertEquals('DER', $retrievedDemo->getRed());
|
||||
$this->assertEquals('ULB', $retrievedDemo->getBlue());
|
||||
|
||||
$this->assertEquals(2, $retrievedDemo->getPlayerCount());
|
||||
$this->assertEquals(2, $retrievedDemo->getRedScore());
|
||||
$this->assertEquals(3, $retrievedDemo->getBlueScore());
|
||||
$this->assertEquals('DER', $retrievedDemo->getRed());
|
||||
$this->assertEquals('ULB', $retrievedDemo->getBlue());
|
||||
$this->assertEquals('user2', $retrievedDemo->getUploaderUser()->getName());
|
||||
|
||||
$this->assertEquals('user2', $retrievedDemo->getUploaderUser()->getName());
|
||||
$this->assertEquals('user2', $retrievedDemo->getPlayers()[0]->getName());
|
||||
$this->assertEquals(1, $retrievedDemo->getPlayers()[0]->getKills());
|
||||
$this->assertEquals(1, $retrievedDemo->getPlayers()[0]->getAssists());
|
||||
$this->assertEquals(2, $retrievedDemo->getPlayers()[0]->getDeaths());
|
||||
$this->assertEquals('blue', $retrievedDemo->getPlayers()[0]->getTeam());
|
||||
$this->assertEquals('soldier', $retrievedDemo->getPlayers()[0]->getClass());
|
||||
|
||||
$this->assertEquals('user2', $retrievedDemo->getPlayers()[0]->getName());
|
||||
$this->assertEquals(1, $retrievedDemo->getPlayers()[0]->getKills());
|
||||
$this->assertEquals(1, $retrievedDemo->getPlayers()[0]->getAssists());
|
||||
$this->assertEquals(2, $retrievedDemo->getPlayers()[0]->getDeaths());
|
||||
$this->assertEquals('blue', $retrievedDemo->getPlayers()[0]->getTeam());
|
||||
$this->assertEquals('soldier', $retrievedDemo->getPlayers()[0]->getClass());
|
||||
$this->assertEquals('user1', $retrievedDemo->getPlayers()[1]->getName());
|
||||
$this->assertEquals(2, $retrievedDemo->getPlayers()[1]->getKills());
|
||||
$this->assertEquals(0, $retrievedDemo->getPlayers()[1]->getAssists());
|
||||
$this->assertEquals(1, $retrievedDemo->getPlayers()[1]->getDeaths());
|
||||
$this->assertEquals('red', $retrievedDemo->getPlayers()[1]->getTeam());
|
||||
$this->assertEquals('scout', $retrievedDemo->getPlayers()[1]->getClass());
|
||||
|
||||
$this->assertEquals('user1', $retrievedDemo->getPlayers()[1]->getName());
|
||||
$this->assertEquals(2, $retrievedDemo->getPlayers()[1]->getKills());
|
||||
$this->assertEquals(0, $retrievedDemo->getPlayers()[1]->getAssists());
|
||||
$this->assertEquals(1, $retrievedDemo->getPlayers()[1]->getDeaths());
|
||||
$this->assertEquals('red', $retrievedDemo->getPlayers()[1]->getTeam());
|
||||
$this->assertEquals('scout', $retrievedDemo->getPlayers()[1]->getClass());
|
||||
|
||||
$this->assertEquals([
|
||||
new ChatMessage('user1', 12, 'msg1'),
|
||||
new ChatMessage('user2', 13, 'msg2')
|
||||
], $chatProvider->getChat($demoId));
|
||||
}
|
||||
$this->assertEquals([
|
||||
new ChatMessage('user1', 12, 'msg1'),
|
||||
new ChatMessage('user2', 13, 'msg2')
|
||||
], $chatProvider->getChat($demoId));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,26 +6,26 @@ 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);
|
||||
public function testStore() {
|
||||
$targetDir = tempnam(sys_get_temp_dir(), 'dummy_target_');
|
||||
unlink($targetDir);
|
||||
mkdir($targetDir);
|
||||
|
||||
$demoStore = new DemoStore($targetDir, 'static.example.com');
|
||||
$demoStore = new DemoStore($targetDir, 'static.example.com');
|
||||
|
||||
$file = tempnam(sys_get_temp_dir(), 'dummy_');
|
||||
file_put_contents($file, 'foobar');
|
||||
$file = tempnam(sys_get_temp_dir(), 'dummy_');
|
||||
file_put_contents($file, 'foobar');
|
||||
|
||||
$storedDemo = $demoStore->store($file, 'foodemo.dem');
|
||||
$storedDemo = $demoStore->store($file, 'foodemo.dem');
|
||||
|
||||
$this->assertStringEndsWith('/foodemo.dem', $storedDemo->getUrl());
|
||||
$this->assertStringStartsWith('https://static.example.com/', $storedDemo->getUrl());
|
||||
$this->assertEquals('static', $storedDemo->getBackend());
|
||||
$this->assertStringEndsWith('/foodemo.dem', $storedDemo->getUrl());
|
||||
$this->assertStringStartsWith('https://static.example.com/', $storedDemo->getUrl());
|
||||
$this->assertEquals('static', $storedDemo->getBackend());
|
||||
|
||||
$this->assertStringEqualsFile($storedDemo->getPath(), 'foobar');
|
||||
unlink($storedDemo->getPath());
|
||||
rmdir(dirname($storedDemo->getPath()));
|
||||
rmdir(dirname($storedDemo->getPath(), 2));
|
||||
rmdir($targetDir);
|
||||
}
|
||||
$this->assertStringEqualsFile($storedDemo->getPath(), 'foobar');
|
||||
unlink($storedDemo->getPath());
|
||||
rmdir(dirname($storedDemo->getPath()));
|
||||
rmdir(dirname($storedDemo->getPath(), 2));
|
||||
rmdir($targetDir);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,60 +7,60 @@ use Demostf\API\Demo\HeaderParser;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class HeaderParserTest extends TestCase {
|
||||
public function testParseFile() {
|
||||
$parser = new HeaderParser();
|
||||
public function testParseFile() {
|
||||
$parser = new HeaderParser();
|
||||
|
||||
$expected = new Header(
|
||||
'HL2DEMO',
|
||||
3,
|
||||
24,
|
||||
'UGC Highlander Match',
|
||||
'SourceTV Demo',
|
||||
'koth_product_rc8',
|
||||
'tf',
|
||||
778.4849853515625,
|
||||
51899,
|
||||
25703,
|
||||
818263
|
||||
);
|
||||
$parsed = $parser->parseHeader(__DIR__ . '/../data/product.dem');
|
||||
$expected = new Header(
|
||||
'HL2DEMO',
|
||||
3,
|
||||
24,
|
||||
'UGC Highlander Match',
|
||||
'SourceTV Demo',
|
||||
'koth_product_rc8',
|
||||
'tf',
|
||||
778.4849853515625,
|
||||
51899,
|
||||
25703,
|
||||
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());
|
||||
}
|
||||
$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 testNonDemoShort() {
|
||||
$parser = new HeaderParser();
|
||||
$parser->parseString("short");
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Not an HL2 demo
|
||||
*/
|
||||
public function testNonDemoLong() {
|
||||
$parser = new HeaderParser();
|
||||
$parser->parseHeader(__FILE__);
|
||||
}
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Not an HL2 demo
|
||||
*/
|
||||
public function testNonDemoLong() {
|
||||
$parser = new HeaderParser();
|
||||
$parser->parseHeader(__FILE__);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testNonExisting() {
|
||||
$parser = new HeaderParser();
|
||||
$parser->parseHeader('/non/existing');
|
||||
}
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testNonExisting() {
|
||||
$parser = new HeaderParser();
|
||||
$parser->parseHeader('/non/existing');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,87 +7,87 @@ use Demostf\API\Demo\RawParser;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class ParserTest extends TestCase {
|
||||
/** @var RawParser|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $rawParser;
|
||||
/** @var RawParser|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $rawParser;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->rawParser = $this->getMockBuilder(RawParser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$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);
|
||||
}));
|
||||
}
|
||||
$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);
|
||||
public function testAnalyse() {
|
||||
$parser = new Parser($this->rawParser);
|
||||
|
||||
$result = $parser->analyse(__DIR__ . '/../data/product.dem');
|
||||
$result = $parser->analyse(__DIR__ . '/../data/product.dem');
|
||||
|
||||
$expectedRaw = json_decode(file_get_contents(__DIR__ . '/../data/product-analyse.json'), true);
|
||||
$expectedRaw = json_decode(file_get_contents(__DIR__ . '/../data/product-analyse.json'), true);
|
||||
|
||||
$expectedChat = $expectedRaw['chat'];
|
||||
$this->assertCount(count($expectedChat), $result->getChat());
|
||||
$this->assertEquals($expectedChat[0]['text'], $result->getChat()[0]->getMessage());
|
||||
$this->assertEquals($expectedChat[0]['time'], $result->getChat()[0]->getTime());
|
||||
$this->assertEquals($expectedChat[0]['from'], $result->getChat()[0]->getUser());
|
||||
$expectedChat = $expectedRaw['chat'];
|
||||
$this->assertCount(count($expectedChat), $result->getChat());
|
||||
$this->assertEquals($expectedChat[0]['text'], $result->getChat()[0]->getMessage());
|
||||
$this->assertEquals($expectedChat[0]['time'], $result->getChat()[0]->getTime());
|
||||
$this->assertEquals($expectedChat[0]['from'], $result->getChat()[0]->getUser());
|
||||
|
||||
$this->assertEquals($expectedRaw['score']['red'], $result->getRedScore());
|
||||
$this->assertEquals($expectedRaw['score']['blue'], $result->getBlueScore());
|
||||
$this->assertEquals($expectedRaw['score']['red'], $result->getRedScore());
|
||||
$this->assertEquals($expectedRaw['score']['blue'], $result->getBlueScore());
|
||||
|
||||
$expectedPlayers = $expectedRaw['players'];
|
||||
$this->assertCount(count($expectedPlayers), $result->getPlayers());
|
||||
$this->assertEquals($expectedPlayers[0]['name'], $result->getPlayers()[0]->getName());
|
||||
$this->assertEquals($expectedPlayers[0]['demo_user_id'], $result->getPlayers()[0]->getDemoUserId());
|
||||
$this->assertEquals($expectedPlayers[0]['team'], $result->getPlayers()[0]->getTeam());
|
||||
$this->assertEquals($expectedPlayers[0]['class'], $result->getPlayers()[0]->getClass());
|
||||
$this->assertEquals($parser->convertSteamIdToCommunityId($expectedPlayers[0]['steam_id']), $result->getPlayers()[0]->getSteamId());
|
||||
$expectedPlayers = $expectedRaw['players'];
|
||||
$this->assertCount(count($expectedPlayers), $result->getPlayers());
|
||||
$this->assertEquals($expectedPlayers[0]['name'], $result->getPlayers()[0]->getName());
|
||||
$this->assertEquals($expectedPlayers[0]['demo_user_id'], $result->getPlayers()[0]->getDemoUserId());
|
||||
$this->assertEquals($expectedPlayers[0]['team'], $result->getPlayers()[0]->getTeam());
|
||||
$this->assertEquals($expectedPlayers[0]['class'], $result->getPlayers()[0]->getClass());
|
||||
$this->assertEquals($parser->convertSteamIdToCommunityId($expectedPlayers[0]['steam_id']), $result->getPlayers()[0]->getSteamId());
|
||||
|
||||
$expectedKills = $expectedRaw['kills'];
|
||||
$this->assertCount(count($expectedKills), $result->getKills());
|
||||
$this->assertEquals((int)$expectedKills[0]['killer'], $result->getKills()[0]->getAttackerDemoId());
|
||||
$this->assertEquals((int)$expectedKills[0]['assister'], $result->getKills()[0]->getAssisterDemoId());
|
||||
$this->assertEquals((int)$expectedKills[0]['victim'], $result->getKills()[0]->getVictimDemoId());
|
||||
$this->assertEquals($expectedKills[0]['weapon'], $result->getKills()[0]->getWeapon());
|
||||
}
|
||||
$expectedKills = $expectedRaw['kills'];
|
||||
$this->assertCount(count($expectedKills), $result->getKills());
|
||||
$this->assertEquals((int)$expectedKills[0]['killer'], $result->getKills()[0]->getAttackerDemoId());
|
||||
$this->assertEquals((int)$expectedKills[0]['assister'], $result->getKills()[0]->getAssisterDemoId());
|
||||
$this->assertEquals((int)$expectedKills[0]['victim'], $result->getKills()[0]->getVictimDemoId());
|
||||
$this->assertEquals($expectedKills[0]['weapon'], $result->getKills()[0]->getWeapon());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testFailedParse() {
|
||||
/** @var RawParser|\PHPUnit_Framework_MockObject_MockObject $rawParser */
|
||||
$rawParser = $this->getMockBuilder(RawParser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testFailedParse() {
|
||||
/** @var RawParser|\PHPUnit_Framework_MockObject_MockObject $rawParser */
|
||||
$rawParser = $this->getMockBuilder(RawParser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$parser = new Parser($rawParser);
|
||||
$parser = new Parser($rawParser);
|
||||
|
||||
$rawParser->expects($this->any())
|
||||
->method('parse')
|
||||
->willReturn(null);
|
||||
$rawParser->expects($this->any())
|
||||
->method('parse')
|
||||
->willReturn(null);
|
||||
|
||||
$parser->analyse('foo');
|
||||
}
|
||||
$parser->analyse('foo');
|
||||
}
|
||||
|
||||
public function testConvertSteamIdToCommunityId() {
|
||||
$parser = new Parser($this->rawParser);
|
||||
public function testConvertSteamIdToCommunityId() {
|
||||
$parser = new Parser($this->rawParser);
|
||||
|
||||
$steamId64 = $parser->convertSteamIdToCommunityId('STEAM_0:0:12345');
|
||||
$this->assertEquals('76561197960290418', $steamId64);
|
||||
}
|
||||
$steamId64 = $parser->convertSteamIdToCommunityId('STEAM_0:0:12345');
|
||||
$this->assertEquals('76561197960290418', $steamId64);
|
||||
}
|
||||
|
||||
public function testConvertUIdToCommunityId() {
|
||||
$parser = new Parser($this->rawParser);
|
||||
public function testConvertUIdToCommunityId() {
|
||||
$parser = new Parser($this->rawParser);
|
||||
|
||||
$steamId64 = $parser->convertSteamIdToCommunityId('[U:1:12345]');
|
||||
$this->assertEquals('76561197960278073', $steamId64);
|
||||
$steamId64 = $parser->convertSteamIdToCommunityId('[U:1:39743963]');
|
||||
$this->assertEquals('76561198000009691', $steamId64);
|
||||
}
|
||||
$steamId64 = $parser->convertSteamIdToCommunityId('[U:1:12345]');
|
||||
$this->assertEquals('76561197960278073', $steamId64);
|
||||
$steamId64 = $parser->convertSteamIdToCommunityId('[U:1:39743963]');
|
||||
$this->assertEquals('76561198000009691', $steamId64);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,33 +7,33 @@ use Demostf\API\Providers\ChatProvider;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class ChatProviderTest extends TestCase {
|
||||
/** @var ChatProvider */
|
||||
private $provider;
|
||||
/** @var ChatProvider */
|
||||
private $provider;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->provider = new ChatProvider($this->getDatabaseConnection());
|
||||
}
|
||||
$this->provider = new ChatProvider($this->getDatabaseConnection());
|
||||
}
|
||||
|
||||
public function testGetEmptyChat() {
|
||||
$this->assertCount(0, $this->provider->getChat(1));
|
||||
}
|
||||
public function testGetEmptyChat() {
|
||||
$this->assertCount(0, $this->provider->getChat(1));
|
||||
}
|
||||
|
||||
public function testStoreRetrieve() {
|
||||
$message1 = new ChatMessage('foo', 2, 'bar');
|
||||
$message2 = new ChatMessage('foo2', 2, 'bar2');
|
||||
$message3 = new ChatMessage('foo2', 2, 'bar2');
|
||||
public function testStoreRetrieve() {
|
||||
$message1 = new ChatMessage('foo', 2, 'bar');
|
||||
$message2 = new ChatMessage('foo2', 2, 'bar2');
|
||||
$message3 = new ChatMessage('foo2', 2, 'bar2');
|
||||
|
||||
$this->provider->storeChatMessage(1, $message1);
|
||||
$this->provider->storeChatMessage(1, $message2);
|
||||
$this->provider->storeChatMessage(2, $message3);
|
||||
$this->provider->storeChatMessage(1, $message1);
|
||||
$this->provider->storeChatMessage(1, $message2);
|
||||
$this->provider->storeChatMessage(2, $message3);
|
||||
|
||||
$result = $this->provider->getChat(1);
|
||||
sort($result);
|
||||
$result = $this->provider->getChat(1);
|
||||
sort($result);
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertEquals($message1, $result[0]);
|
||||
$this->assertEquals($message2, $result[1]);
|
||||
}
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertEquals($message1, $result[0]);
|
||||
$this->assertEquals($message2, $result[1]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,153 +11,153 @@ use Demostf\API\Providers\UserProvider;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class DemoListProviderTest extends TestCase {
|
||||
/** @var DemoListProvider */
|
||||
private $demoListProvider;
|
||||
/** @var DemoProvider */
|
||||
private $demoProvider;
|
||||
/** @var PlayerProvider */
|
||||
private $playerProvider;
|
||||
/** @var UserProvider */
|
||||
private $userProvider;
|
||||
/** @var DemoListProvider */
|
||||
private $demoListProvider;
|
||||
/** @var DemoProvider */
|
||||
private $demoProvider;
|
||||
/** @var PlayerProvider */
|
||||
private $playerProvider;
|
||||
/** @var UserProvider */
|
||||
private $userProvider;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->demoListProvider = new DemoListProvider($this->getDatabaseConnection());
|
||||
$this->demoProvider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->playerProvider = new PlayerProvider($this->getDatabaseConnection());
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
}
|
||||
$this->demoListProvider = new DemoListProvider($this->getDatabaseConnection());
|
||||
$this->demoProvider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->playerProvider = new PlayerProvider($this->getDatabaseConnection());
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
}
|
||||
|
||||
private function getDemo(int $uploaderId, $map = 'map', $playerCount = 18) {
|
||||
return new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
$map,
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
$playerCount,
|
||||
$uploaderId,
|
||||
'hash',
|
||||
'backend',
|
||||
'path'
|
||||
);
|
||||
}
|
||||
private function getDemo(int $uploaderId, $map = 'map', $playerCount = 18) {
|
||||
return new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
$map,
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
$playerCount,
|
||||
$uploaderId,
|
||||
'hash',
|
||||
'backend',
|
||||
'path'
|
||||
);
|
||||
}
|
||||
|
||||
public function testListEmpty() {
|
||||
$this->assertEquals([], $this->demoListProvider->listDemos(1));
|
||||
}
|
||||
public function testListEmpty() {
|
||||
$this->assertEquals([], $this->demoListProvider->listDemos(1));
|
||||
}
|
||||
|
||||
public function testListSimple() {
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1), 'foo', 'bar');
|
||||
public function testListSimple() {
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1), 'foo', 'bar');
|
||||
|
||||
$list = $this->demoListProvider->listDemos(1);
|
||||
$this->assertCount(3, $list);
|
||||
$list = $this->demoListProvider->listDemos(1);
|
||||
$this->assertCount(3, $list);
|
||||
|
||||
$this->assertEquals($id3, $list[0]->getId());
|
||||
$this->assertEquals($id2, $list[1]->getId());
|
||||
$this->assertEquals($id1, $list[2]->getId());
|
||||
}
|
||||
$this->assertEquals($id3, $list[0]->getId());
|
||||
$this->assertEquals($id2, $list[1]->getId());
|
||||
$this->assertEquals($id1, $list[2]->getId());
|
||||
}
|
||||
|
||||
public function testFilterMap() {
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1'), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1, 'map2'), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1'), 'foo', 'bar');
|
||||
public function testFilterMap() {
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1'), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1, 'map2'), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1'), 'foo', 'bar');
|
||||
|
||||
$list = $this->demoListProvider->listDemos(1, ['map' => 'map1']);
|
||||
$this->assertCount(2, $list);
|
||||
$list = $this->demoListProvider->listDemos(1, ['map' => 'map1']);
|
||||
$this->assertCount(2, $list);
|
||||
|
||||
$this->assertEquals($id3, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
}
|
||||
$this->assertEquals($id3, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
}
|
||||
|
||||
public function testFilterPlayerCount() {
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 17), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 12), 'foo', 'bar');
|
||||
public function testFilterPlayerCount() {
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 17), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 12), 'foo', 'bar');
|
||||
|
||||
$list = $this->demoListProvider->listDemos(1, ['playerCount' => [17, 18, 19]]);
|
||||
$this->assertCount(2, $list);
|
||||
$list = $this->demoListProvider->listDemos(1, ['playerCount' => [17, 18, 19]]);
|
||||
$this->assertCount(2, $list);
|
||||
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
}
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
}
|
||||
|
||||
public function testByUploader() {
|
||||
$steamId = $this->getSteamId('12345', 'bar');
|
||||
$this->userProvider->store($steamId);
|
||||
$userId = $this->userProvider->get($steamId->getSteamId64())->getId();
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map1', 17), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo($userId + 1, 'map1', 12), 'foo', 'bar');
|
||||
public function testByUploader() {
|
||||
$steamId = $this->getSteamId('12345', 'bar');
|
||||
$this->userProvider->store($steamId);
|
||||
$userId = $this->userProvider->get($steamId->getSteamId64())->getId();
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map1', 17), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo($userId + 1, 'map1', 12), 'foo', 'bar');
|
||||
|
||||
$list = $this->demoListProvider->listUploads($steamId->getSteamId64(), 1);
|
||||
$list = $this->demoListProvider->listUploads($steamId->getSteamId64(), 1);
|
||||
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
}
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
}
|
||||
|
||||
public function testByUploaderFilter() {
|
||||
$steamId = $this->getSteamId('12345', 'bar');
|
||||
$this->userProvider->store($steamId);
|
||||
$userId = $this->userProvider->get($steamId->getSteamId64())->getId();
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map1', 12), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo($userId + 1, 'map1', 12), 'foo', 'bar');
|
||||
public function testByUploaderFilter() {
|
||||
$steamId = $this->getSteamId('12345', 'bar');
|
||||
$this->userProvider->store($steamId);
|
||||
$userId = $this->userProvider->get($steamId->getSteamId64())->getId();
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map1', 12), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo($userId + 1, 'map1', 12), 'foo', 'bar');
|
||||
|
||||
$list = $this->demoListProvider->listUploads($steamId->getSteamId64(), 1, ['playerCount' => [17, 18, 19]]);
|
||||
$list = $this->demoListProvider->listUploads($steamId->getSteamId64(), 1, ['playerCount' => [17, 18, 19]]);
|
||||
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
}
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
}
|
||||
|
||||
private function addPlayer($demoId, $userId) {
|
||||
$player = new Player(0, $demoId, 0, $userId, 'foo', 'red', 'scout');
|
||||
$this->playerProvider->store($player);
|
||||
}
|
||||
private function addPlayer($demoId, $userId) {
|
||||
$player = new Player(0, $demoId, 0, $userId, 'foo', 'red', 'scout');
|
||||
$this->playerProvider->store($player);
|
||||
}
|
||||
|
||||
public function testFilterPlayer() {
|
||||
$steamId1 = $this->getSteamId('12345', 'bar1');
|
||||
$steamId2 = $this->getSteamId('22345', 'bar2');
|
||||
$steamId3 = $this->getSteamId('32345', 'bar3');
|
||||
$this->userProvider->store($steamId1);
|
||||
$this->userProvider->store($steamId2);
|
||||
$this->userProvider->store($steamId3);
|
||||
$userId1 = $this->userProvider->get($steamId1->getSteamId64())->getId();
|
||||
$userId2 = $this->userProvider->get($steamId2->getSteamId64())->getId();
|
||||
$userId3 = $this->userProvider->get($steamId3->getSteamId64())->getId();
|
||||
public function testFilterPlayer() {
|
||||
$steamId1 = $this->getSteamId('12345', 'bar1');
|
||||
$steamId2 = $this->getSteamId('22345', 'bar2');
|
||||
$steamId3 = $this->getSteamId('32345', 'bar3');
|
||||
$this->userProvider->store($steamId1);
|
||||
$this->userProvider->store($steamId2);
|
||||
$this->userProvider->store($steamId3);
|
||||
$userId1 = $this->userProvider->get($steamId1->getSteamId64())->getId();
|
||||
$userId2 = $this->userProvider->get($steamId2->getSteamId64())->getId();
|
||||
$userId3 = $this->userProvider->get($steamId3->getSteamId64())->getId();
|
||||
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 17), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 12), 'foo', 'bar');
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 17), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 12), 'foo', 'bar');
|
||||
|
||||
$this->addPlayer($id1, $userId1);
|
||||
$this->addPlayer($id1, $userId2);
|
||||
$this->addPlayer($id2, $userId1);
|
||||
$this->addPlayer($id2, $userId3);
|
||||
$this->addPlayer($id3, $userId3);
|
||||
$this->addPlayer($id1, $userId1);
|
||||
$this->addPlayer($id1, $userId2);
|
||||
$this->addPlayer($id2, $userId1);
|
||||
$this->addPlayer($id2, $userId3);
|
||||
$this->addPlayer($id3, $userId3);
|
||||
|
||||
$list = $this->demoListProvider->listDemos(1, ['players' => [$steamId1->getSteamId64()]]);
|
||||
$list = $this->demoListProvider->listDemos(1, ['players' => [$steamId1->getSteamId64()]]);
|
||||
|
||||
$this->assertCount(2, $list);
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
$this->assertCount(2, $list);
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
|
||||
$list = $this->demoListProvider->listDemos(1, ['players' => [$steamId1->getSteamId64(), $steamId3->getSteamId64()]]);
|
||||
$list = $this->demoListProvider->listDemos(1, ['players' => [$steamId1->getSteamId64(), $steamId3->getSteamId64()]]);
|
||||
|
||||
$this->assertCount(1, $list);
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertCount(1, $list);
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
|
||||
$list = $this->demoListProvider->listDemos(1, ['players' => [$steamId2->getSteamId64(), $steamId3->getSteamId64()]]);
|
||||
$list = $this->demoListProvider->listDemos(1, ['players' => [$steamId2->getSteamId64(), $steamId3->getSteamId64()]]);
|
||||
|
||||
$this->assertCount(0, $list);
|
||||
}
|
||||
$this->assertCount(0, $list);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,187 +13,187 @@ use Demostf\API\Providers\UserProvider;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class DemoProviderTest extends TestCase {
|
||||
/** @var DemoProvider */
|
||||
private $provider;
|
||||
/** @var DemoProvider */
|
||||
private $provider;
|
||||
|
||||
/** @var UserProvider */
|
||||
private $userProvider;
|
||||
/** @var UserProvider */
|
||||
private $userProvider;
|
||||
|
||||
/** @var PlayerProvider */
|
||||
private $playerProvider;
|
||||
/** @var PlayerProvider */
|
||||
private $playerProvider;
|
||||
|
||||
/** @var KillProvider */
|
||||
private $killProvider;
|
||||
/** @var KillProvider */
|
||||
private $killProvider;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->provider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$this->playerProvider = new PlayerProvider($this->getDatabaseConnection());
|
||||
$this->killProvider = new KillProvider($this->getDatabaseConnection());
|
||||
}
|
||||
$this->provider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$this->playerProvider = new PlayerProvider($this->getDatabaseConnection());
|
||||
$this->killProvider = new KillProvider($this->getDatabaseConnection());
|
||||
}
|
||||
|
||||
public function testGetNonExisting() {
|
||||
$this->assertNull($this->provider->get(1));
|
||||
}
|
||||
public function testGetNonExisting() {
|
||||
$this->assertNull($this->provider->get(1));
|
||||
}
|
||||
|
||||
public function testStoreRetrieve() {
|
||||
$uploaderSteamId = $this->getSteamId('12345', 'test');
|
||||
$this->userProvider->store($uploaderSteamId);
|
||||
public function testStoreRetrieve() {
|
||||
$uploaderSteamId = $this->getSteamId('12345', 'test');
|
||||
$this->userProvider->store($uploaderSteamId);
|
||||
|
||||
$uploader = $this->userProvider->get($uploaderSteamId->getSteamId64());
|
||||
$uploader = $this->userProvider->get($uploaderSteamId->getSteamId64());
|
||||
|
||||
$demo = new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
'map',
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
18,
|
||||
$uploader->getId(),
|
||||
'hash',
|
||||
'dummy',
|
||||
'path'
|
||||
);
|
||||
$demo->setUploaderUser($uploader);
|
||||
$demo = new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
'map',
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
18,
|
||||
$uploader->getId(),
|
||||
'hash',
|
||||
'dummy',
|
||||
'path'
|
||||
);
|
||||
$demo->setUploaderUser($uploader);
|
||||
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
|
||||
$retrieved = $this->provider->get($id);
|
||||
$this->assertInstanceOf(Demo::class, $retrieved);
|
||||
$retrieved = $this->provider->get($id);
|
||||
$this->assertInstanceOf(Demo::class, $retrieved);
|
||||
|
||||
$storedData = $demo->jsonSerialize();
|
||||
$storedData['id'] = $id;
|
||||
$storedData = $demo->jsonSerialize();
|
||||
$storedData['id'] = $id;
|
||||
|
||||
$this->assertEquals($storedData, $retrieved->jsonSerialize());
|
||||
$this->assertEquals($storedData, $retrieved->jsonSerialize());
|
||||
|
||||
$this->assertEquals($id, $this->provider->demoIdByHash('hash'));
|
||||
}
|
||||
$this->assertEquals($id, $this->provider->demoIdByHash('hash'));
|
||||
}
|
||||
|
||||
public function testRetrieveWithPlayers() {
|
||||
$uploaderSteamId = $this->getSteamId('12345', 'test');
|
||||
$this->userProvider->store($uploaderSteamId);
|
||||
public function testRetrieveWithPlayers() {
|
||||
$uploaderSteamId = $this->getSteamId('12345', 'test');
|
||||
$this->userProvider->store($uploaderSteamId);
|
||||
|
||||
$steamId1 = $this->getSteamId('1', 'u1');
|
||||
$steamId2 = $this->getSteamId('2', 'u2');
|
||||
$steamId3 = $this->getSteamId('3', 'u3');
|
||||
$steamId4 = $this->getSteamId('4', 'u4');
|
||||
$steamId1 = $this->getSteamId('1', 'u1');
|
||||
$steamId2 = $this->getSteamId('2', 'u2');
|
||||
$steamId3 = $this->getSteamId('3', 'u3');
|
||||
$steamId4 = $this->getSteamId('4', 'u4');
|
||||
|
||||
$this->userProvider->store($steamId1);
|
||||
$this->userProvider->store($steamId2);
|
||||
$this->userProvider->store($steamId3);
|
||||
$this->userProvider->store($steamId4);
|
||||
$this->userProvider->store($steamId1);
|
||||
$this->userProvider->store($steamId2);
|
||||
$this->userProvider->store($steamId3);
|
||||
$this->userProvider->store($steamId4);
|
||||
|
||||
$user1 = $this->userProvider->get($steamId1->getSteamId64());
|
||||
$user2 = $this->userProvider->get($steamId2->getSteamId64());
|
||||
$user3 = $this->userProvider->get($steamId3->getSteamId64());
|
||||
$user4 = $this->userProvider->get($steamId4->getSteamId64());
|
||||
$user1 = $this->userProvider->get($steamId1->getSteamId64());
|
||||
$user2 = $this->userProvider->get($steamId2->getSteamId64());
|
||||
$user3 = $this->userProvider->get($steamId3->getSteamId64());
|
||||
$user4 = $this->userProvider->get($steamId4->getSteamId64());
|
||||
|
||||
$uploader = $this->userProvider->get($uploaderSteamId->getSteamId64());
|
||||
$uploader = $this->userProvider->get($uploaderSteamId->getSteamId64());
|
||||
|
||||
$demo = new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
'map',
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
18,
|
||||
$uploader->getId(),
|
||||
'hash',
|
||||
'backend',
|
||||
'path',
|
||||
'dummy',
|
||||
'path'
|
||||
);
|
||||
$demo = new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
'map',
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
18,
|
||||
$uploader->getId(),
|
||||
'hash',
|
||||
'backend',
|
||||
'path',
|
||||
'dummy',
|
||||
'path'
|
||||
);
|
||||
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
$player1 = $this->addPlayer($id, 101, $user1->getId(), 'red', 'scout');
|
||||
$player2 = $this->addPlayer($id, 102, $user2->getId(), 'red', 'soldier');
|
||||
$player3 = $this->addPlayer($id, 103, $user3->getId(), 'blue', 'engineer');
|
||||
$player4 = $this->addPlayer($id, 104, $user4->getId(), 'blue', 'spy');
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
$player1 = $this->addPlayer($id, 101, $user1->getId(), 'red', 'scout');
|
||||
$player2 = $this->addPlayer($id, 102, $user2->getId(), 'red', 'soldier');
|
||||
$player3 = $this->addPlayer($id, 103, $user3->getId(), 'blue', 'engineer');
|
||||
$player4 = $this->addPlayer($id, 104, $user4->getId(), 'blue', 'spy');
|
||||
|
||||
$this->addKill($id, $user1->getId(), 0, $user3->getId(), 'pan');
|
||||
$this->addKill($id, $user1->getId(), $user2->getId(), $user3->getId(), 'pan');
|
||||
$this->addKill($id, $user4->getId(), 0, $user1->getId(), 'pan');
|
||||
$this->addKill($id, $user1->getId(), 0, $user3->getId(), 'pan');
|
||||
$this->addKill($id, $user1->getId(), $user2->getId(), $user3->getId(), 'pan');
|
||||
$this->addKill($id, $user4->getId(), 0, $user1->getId(), 'pan');
|
||||
|
||||
$retrieved = $this->provider->get($id, true);
|
||||
$this->assertInstanceOf(Demo::class, $retrieved);
|
||||
$retrieved = $this->provider->get($id, true);
|
||||
$this->assertInstanceOf(Demo::class, $retrieved);
|
||||
|
||||
$players = $retrieved->getPlayers();
|
||||
$this->assertCount(4, $players);
|
||||
usort($players, function (DemoPlayer $a, DemoPlayer $b) {
|
||||
return $a->getUserId() - $b->getUserId();
|
||||
});
|
||||
$this->assertEquals([
|
||||
new DemoPlayer($player1, $user1->getId(), 'user_' . $user1->getId(), 'red', 'scout', '1', 'foo_medium.jpg', 2, 0, 1),
|
||||
new DemoPlayer($player2, $user2->getId(), 'user_' . $user2->getId(), 'red', 'soldier', '2', 'foo_medium.jpg', 0, 1, 0),
|
||||
new DemoPlayer($player3, $user3->getId(), 'user_' . $user3->getId(), 'blue', 'engineer', '3', 'foo_medium.jpg', 0, 0, 2),
|
||||
new DemoPlayer($player4, $user4->getId(), 'user_' . $user4->getId(), 'blue', 'spy', '4', 'foo_medium.jpg', 1, 0, 0),
|
||||
], $players);
|
||||
}
|
||||
$players = $retrieved->getPlayers();
|
||||
$this->assertCount(4, $players);
|
||||
usort($players, function (DemoPlayer $a, DemoPlayer $b) {
|
||||
return $a->getUserId() - $b->getUserId();
|
||||
});
|
||||
$this->assertEquals([
|
||||
new DemoPlayer($player1, $user1->getId(), 'user_' . $user1->getId(), 'red', 'scout', '1', 'foo_medium.jpg', 2, 0, 1),
|
||||
new DemoPlayer($player2, $user2->getId(), 'user_' . $user2->getId(), 'red', 'soldier', '2', 'foo_medium.jpg', 0, 1, 0),
|
||||
new DemoPlayer($player3, $user3->getId(), 'user_' . $user3->getId(), 'blue', 'engineer', '3', 'foo_medium.jpg', 0, 0, 2),
|
||||
new DemoPlayer($player4, $user4->getId(), 'user_' . $user4->getId(), 'blue', 'spy', '4', 'foo_medium.jpg', 1, 0, 0),
|
||||
], $players);
|
||||
}
|
||||
|
||||
private function addPlayer(int $demoId, int $demoUserId, int $userId, string $team, string $class): int {
|
||||
$player = new Player(0, $demoId, $demoUserId, $userId, 'user_' . $userId, $team, $class);
|
||||
return $this->playerProvider->store($player);
|
||||
}
|
||||
private function addPlayer(int $demoId, int $demoUserId, int $userId, string $team, string $class): int {
|
||||
$player = new Player(0, $demoId, $demoUserId, $userId, 'user_' . $userId, $team, $class);
|
||||
return $this->playerProvider->store($player);
|
||||
}
|
||||
|
||||
private function addKill(int $demoId, int $attackerId, int $assisterId, int $victimId, string $weapon): int {
|
||||
$kill = new Kill(0, $demoId, $attackerId, $assisterId, $victimId, $weapon);
|
||||
return $this->killProvider->store($kill);
|
||||
}
|
||||
private function addKill(int $demoId, int $attackerId, int $assisterId, int $victimId, string $weapon): int {
|
||||
$kill = new Kill(0, $demoId, $attackerId, $assisterId, $victimId, $weapon);
|
||||
return $this->killProvider->store($kill);
|
||||
}
|
||||
|
||||
public function testSetDemoUrl() {
|
||||
$uploaderSteamId = $this->getSteamId('12345', 'test');
|
||||
$this->userProvider->store($uploaderSteamId);
|
||||
public function testSetDemoUrl() {
|
||||
$uploaderSteamId = $this->getSteamId('12345', 'test');
|
||||
$this->userProvider->store($uploaderSteamId);
|
||||
|
||||
$uploader = $this->userProvider->get($uploaderSteamId->getSteamId64());
|
||||
$uploader = $this->userProvider->get($uploaderSteamId->getSteamId64());
|
||||
|
||||
$demo = new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
'map',
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
18,
|
||||
$uploader->getId(),
|
||||
'hash',
|
||||
'dummy',
|
||||
'path'
|
||||
);
|
||||
$demo = new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
'map',
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
18,
|
||||
$uploader->getId(),
|
||||
'hash',
|
||||
'dummy',
|
||||
'path'
|
||||
);
|
||||
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
$id2 = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
$id2 = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
|
||||
$this->provider->setDemoUrl($id, 'foobackend', 'http://foo.example.com', 'bar');
|
||||
$this->provider->setDemoUrl($id, 'foobackend', 'http://foo.example.com', 'bar');
|
||||
|
||||
$storedDemo = $this->provider->get($id);
|
||||
$this->assertEquals('http://foo.example.com', $storedDemo->getUrl());
|
||||
$this->assertEquals('foobackend', $storedDemo->getBackend());
|
||||
$this->assertEquals('bar', $storedDemo->getPath());
|
||||
$storedDemo = $this->provider->get($id);
|
||||
$this->assertEquals('http://foo.example.com', $storedDemo->getUrl());
|
||||
$this->assertEquals('foobackend', $storedDemo->getBackend());
|
||||
$this->assertEquals('bar', $storedDemo->getPath());
|
||||
|
||||
$storedDemo2 = $this->provider->get($id2);
|
||||
$this->assertEquals('http://example.com', $storedDemo2->getUrl());
|
||||
}
|
||||
$storedDemo2 = $this->provider->get($id2);
|
||||
$this->assertEquals('http://example.com', $storedDemo2->getUrl());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,284 +19,289 @@ use Demostf\API\Providers\UserProvider;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class UploadProviderTest extends TestCase {
|
||||
/** @var RawParser */
|
||||
private $rawParser;
|
||||
/** @var HeaderParser */
|
||||
private $headerParser;
|
||||
/** @var Parser */
|
||||
private $parser;
|
||||
/** @var DemoStore */
|
||||
private $demoStore;
|
||||
/** @var UserProvider */
|
||||
private $userProvider;
|
||||
/** @var DemoProvider */
|
||||
private $demoProvider;
|
||||
/** @var DemoSaver */
|
||||
private $demoSaver;
|
||||
/** @var UploadProvider */
|
||||
private $uploadProvider;
|
||||
/** @var string */
|
||||
private $tmpDir;
|
||||
/** @var RawParser */
|
||||
private $rawParser;
|
||||
/** @var HeaderParser */
|
||||
private $headerParser;
|
||||
/** @var Parser */
|
||||
private $parser;
|
||||
/** @var DemoStore */
|
||||
private $demoStore;
|
||||
/** @var UserProvider */
|
||||
private $userProvider;
|
||||
/** @var DemoProvider */
|
||||
private $demoProvider;
|
||||
/** @var DemoSaver */
|
||||
private $demoSaver;
|
||||
/** @var UploadProvider */
|
||||
private $uploadProvider;
|
||||
/** @var string */
|
||||
private $tmpDir;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->rawParser = $this->getMockBuilder(RawParser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$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);
|
||||
}));
|
||||
$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);
|
||||
}));
|
||||
|
||||
$targetDir = tempnam(sys_get_temp_dir(), 'dummy_target_');
|
||||
unlink($targetDir);
|
||||
mkdir($targetDir);
|
||||
$this->tmpDir = $targetDir;
|
||||
$targetDir = tempnam(sys_get_temp_dir(), 'dummy_target_');
|
||||
unlink($targetDir);
|
||||
mkdir($targetDir);
|
||||
$this->tmpDir = $targetDir;
|
||||
|
||||
$this->headerParser = new HeaderParser();
|
||||
$this->parser = new Parser($this->rawParser);
|
||||
$this->demoStore = new DemoStore($targetDir, 'example.com');
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$this->demoProvider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->demoSaver = new DemoSaver(
|
||||
new KillProvider($this->getDatabaseConnection()),
|
||||
new PlayerProvider($this->getDatabaseConnection()),
|
||||
new ChatProvider($this->getDatabaseConnection()),
|
||||
$this->userProvider,
|
||||
$this->demoProvider
|
||||
);
|
||||
$this->headerParser = new HeaderParser();
|
||||
$this->parser = new Parser($this->rawParser);
|
||||
$this->demoStore = new DemoStore($targetDir, 'example.com');
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$this->demoProvider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->demoSaver = new DemoSaver(
|
||||
new KillProvider($this->getDatabaseConnection()),
|
||||
new PlayerProvider($this->getDatabaseConnection()),
|
||||
new ChatProvider($this->getDatabaseConnection()),
|
||||
$this->userProvider,
|
||||
$this->demoProvider
|
||||
);
|
||||
|
||||
$this->uploadProvider = new UploadProvider(
|
||||
$this->getDatabaseConnection(),
|
||||
'http://example.com',
|
||||
$this->headerParser,
|
||||
$this->parser,
|
||||
$this->demoStore,
|
||||
$this->userProvider,
|
||||
$this->demoProvider,
|
||||
$this->demoSaver
|
||||
);
|
||||
}
|
||||
$this->uploadProvider = new UploadProvider(
|
||||
$this->getDatabaseConnection(),
|
||||
'http://example.com',
|
||||
$this->headerParser,
|
||||
$this->parser,
|
||||
$this->demoStore,
|
||||
$this->userProvider,
|
||||
$this->demoProvider,
|
||||
$this->demoSaver
|
||||
);
|
||||
}
|
||||
|
||||
private function rmdirr($dir) {
|
||||
$it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$files = new \RecursiveIteratorIterator($it,
|
||||
\RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
rmdir($file->getRealPath());
|
||||
} else {
|
||||
unlink($file->getRealPath());
|
||||
}
|
||||
}
|
||||
rmdir($dir);
|
||||
}
|
||||
private function rmdirr($dir) {
|
||||
$it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$files = new \RecursiveIteratorIterator(
|
||||
$it,
|
||||
\RecursiveIteratorIterator::CHILD_FIRST
|
||||
);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
rmdir($file->getRealPath());
|
||||
} else {
|
||||
unlink($file->getRealPath());
|
||||
}
|
||||
}
|
||||
rmdir($dir);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
$this->rmdirr($this->tmpDir);
|
||||
public function tearDown() {
|
||||
$this->rmdirr($this->tmpDir);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testValidateHeaderToSmall() {
|
||||
$this->assertEquals('Demos needs to be at least 1KB is size', $this->uploadProvider->validateHeader(
|
||||
12,
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
12,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
)
|
||||
));
|
||||
}
|
||||
public function testValidateHeaderToSmall() {
|
||||
$this->assertEquals('Demos needs to be at least 1KB is size', $this->uploadProvider->validateHeader(
|
||||
12,
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
12,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidateHeaderToBig() {
|
||||
$this->assertEquals('Demos cant be more than 100MB in size', $this->uploadProvider->validateHeader(
|
||||
99999999999,
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
12,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
)
|
||||
));
|
||||
}
|
||||
public function testValidateHeaderToBig() {
|
||||
$this->assertEquals('Demos cant be more than 100MB in size', $this->uploadProvider->validateHeader(
|
||||
99999999999,
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
12,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidateHeaderToLong() {
|
||||
$this->assertEquals('Demos cant be longer than one hour', $this->uploadProvider->validateHeader(
|
||||
9999,
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
999999,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
)
|
||||
));
|
||||
}
|
||||
public function testValidateHeaderToLong() {
|
||||
$this->assertEquals('Demos cant be longer than one hour', $this->uploadProvider->validateHeader(
|
||||
9999,
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
999999,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidateParsedToShortNoRounds() {
|
||||
$this->assertEquals('Demos must be at least 5 minutes long', $this->uploadProvider->validateParsed(
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
60,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
),
|
||||
new ParsedDemo(0, 0, [], [], [])
|
||||
));
|
||||
}
|
||||
public function testValidateParsedToShortNoRounds() {
|
||||
$this->assertEquals('Demos must be at least 5 minutes long', $this->uploadProvider->validateParsed(
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
60,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
),
|
||||
new ParsedDemo(0, 0, [], [], [])
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidateParsedToShortRounds() {
|
||||
$this->assertNull($this->uploadProvider->validateParsed(
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
60,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
),
|
||||
new ParsedDemo(1, 0, [], [], [])
|
||||
));
|
||||
}
|
||||
public function testValidateParsedToShortRounds() {
|
||||
$this->assertNull($this->uploadProvider->validateParsed(
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
60,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
),
|
||||
new ParsedDemo(1, 0, [], [], [])
|
||||
));
|
||||
}
|
||||
|
||||
public function testUploadInvalidKey() {
|
||||
$this->assertEquals('Invalid key',
|
||||
$this->uploadProvider->upload('asdasd', 'RED', 'BLU', 'asdasd', 'asdas')
|
||||
);
|
||||
}
|
||||
public function testUploadInvalidKey() {
|
||||
$this->assertEquals(
|
||||
'Invalid key',
|
||||
$this->uploadProvider->upload('asdasd', 'RED', 'BLU', 'asdasd', 'asdas')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Not an HL2 demo
|
||||
*/
|
||||
public function testUploadNonDemo() {
|
||||
file_put_contents($this->tmpDir . '/foo.dem', 'asd');
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Not an HL2 demo
|
||||
*/
|
||||
public function testUploadNonDemo() {
|
||||
file_put_contents($this->tmpDir . '/foo.dem', 'asd');
|
||||
|
||||
$steamId = $this->getSteamId('123', 'a');
|
||||
$token = $this->userProvider->store($steamId);
|
||||
$steamId = $this->getSteamId('123', 'a');
|
||||
$token = $this->userProvider->store($steamId);
|
||||
|
||||
$this->uploadProvider->upload($token, 'RED', 'BLU', 'asdasd', $this->tmpDir . '/foo.dem');
|
||||
}
|
||||
$this->uploadProvider->upload($token, 'RED', 'BLU', 'asdasd', $this->tmpDir . '/foo.dem');
|
||||
}
|
||||
|
||||
public function testUploadExisting() {
|
||||
$source = fopen(__DIR__ . '/../data/product.dem', 'r');
|
||||
file_put_contents($this->tmpDir . '/foo.dem', fread($source, 2048));
|
||||
fclose($source);
|
||||
$hash = md5_file($this->tmpDir . '/foo.dem');
|
||||
public function testUploadExisting() {
|
||||
$source = fopen(__DIR__ . '/../data/product.dem', 'r');
|
||||
file_put_contents($this->tmpDir . '/foo.dem', fread($source, 2048));
|
||||
fclose($source);
|
||||
$hash = md5_file($this->tmpDir . '/foo.dem');
|
||||
|
||||
$id = $this->demoProvider->storeDemo(
|
||||
new Demo(
|
||||
0,
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
12,
|
||||
'n',
|
||||
'm',
|
||||
new \DateTime(),
|
||||
'r',
|
||||
'b',
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
$hash,
|
||||
'b',
|
||||
'p'
|
||||
),
|
||||
'test', 'test'
|
||||
);
|
||||
$id = $this->demoProvider->storeDemo(
|
||||
new Demo(
|
||||
0,
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
12,
|
||||
'n',
|
||||
'm',
|
||||
new \DateTime(),
|
||||
'r',
|
||||
'b',
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
$hash,
|
||||
'b',
|
||||
'p'
|
||||
),
|
||||
'test',
|
||||
'test'
|
||||
);
|
||||
|
||||
$steamId = $this->getSteamId('123', 'a');
|
||||
$token = $this->userProvider->store($steamId);
|
||||
$steamId = $this->getSteamId('123', 'a');
|
||||
$token = $this->userProvider->store($steamId);
|
||||
|
||||
$this->assertEquals('STV available at: http://example.com/' . $id,
|
||||
$this->uploadProvider->upload($token, 'RED', 'BLU', 'asdasd', $this->tmpDir . '/foo.dem')
|
||||
);
|
||||
}
|
||||
$this->assertEquals(
|
||||
'STV available at: http://example.com/' . $id,
|
||||
$this->uploadProvider->upload($token, 'RED', 'BLU', 'asdasd', $this->tmpDir . '/foo.dem')
|
||||
);
|
||||
}
|
||||
|
||||
private function saveSteamId($steamId, $name) {
|
||||
$steamId = $this->getSteamId($this->parser->convertSteamIdToCommunityId($steamId), $name);
|
||||
$this->userProvider->store($steamId);
|
||||
}
|
||||
private function saveSteamId($steamId, $name) {
|
||||
$steamId = $this->getSteamId($this->parser->convertSteamIdToCommunityId($steamId), $name);
|
||||
$this->userProvider->store($steamId);
|
||||
}
|
||||
|
||||
public function testUpload() {
|
||||
copy(__DIR__ . '/../data/product.dem', $this->tmpDir . '/foo.dem');
|
||||
copy(__DIR__ . '/../data/product-raw.json', $this->tmpDir . '/foo-raw.json');
|
||||
public function testUpload() {
|
||||
copy(__DIR__ . '/../data/product.dem', $this->tmpDir . '/foo.dem');
|
||||
copy(__DIR__ . '/../data/product-raw.json', $this->tmpDir . '/foo-raw.json');
|
||||
|
||||
$steamId = $this->getSteamId('123', 'a');
|
||||
$token = $this->userProvider->store($steamId);
|
||||
$steamId = $this->getSteamId('123', 'a');
|
||||
$token = $this->userProvider->store($steamId);
|
||||
|
||||
// pre-save the names so we dont have to get them from steam
|
||||
$this->saveSteamId('[U:1:64229260]', 'Icewind');
|
||||
$this->saveSteamId('[U:1:115748435]', 'Foz');
|
||||
$this->saveSteamId('[U:1:115754284]', 'Deity');
|
||||
$this->saveSteamId('[U:1:92428736]', 'Kireek');
|
||||
$this->saveSteamId('[U:1:22958903]', 'Vinegar');
|
||||
$this->saveSteamId('[U:1:32061783]', 'Kimo');
|
||||
$this->saveSteamId('[U:1:67502510]', 'magikarp');
|
||||
$this->saveSteamId('[U:1:55128465]', 'Solar');
|
||||
$this->saveSteamId('[U:1:301587080]', 'ztreak');
|
||||
$this->saveSteamId('[U:1:22162172]', 'TheMasterOfDisaster');
|
||||
$this->saveSteamId('[U:1:13559571]', 'Sage');
|
||||
$this->saveSteamId('[U:1:71706948]', 'Sketis');
|
||||
$this->saveSteamId('[U:1:157204170]', 'Pyla');
|
||||
$this->saveSteamId('[U:1:30838206]', 'Heavy');
|
||||
$this->saveSteamId('[U:1:174774002]', 'Soldier');
|
||||
$this->saveSteamId('[U:1:92096346]', 'Fish');
|
||||
$this->saveSteamId('[U:1:143626373]', 'Pendulum');
|
||||
$this->saveSteamId('[U:1:30220936]', 'Jedi');
|
||||
// pre-save the names so we dont have to get them from steam
|
||||
$this->saveSteamId('[U:1:64229260]', 'Icewind');
|
||||
$this->saveSteamId('[U:1:115748435]', 'Foz');
|
||||
$this->saveSteamId('[U:1:115754284]', 'Deity');
|
||||
$this->saveSteamId('[U:1:92428736]', 'Kireek');
|
||||
$this->saveSteamId('[U:1:22958903]', 'Vinegar');
|
||||
$this->saveSteamId('[U:1:32061783]', 'Kimo');
|
||||
$this->saveSteamId('[U:1:67502510]', 'magikarp');
|
||||
$this->saveSteamId('[U:1:55128465]', 'Solar');
|
||||
$this->saveSteamId('[U:1:301587080]', 'ztreak');
|
||||
$this->saveSteamId('[U:1:22162172]', 'TheMasterOfDisaster');
|
||||
$this->saveSteamId('[U:1:13559571]', 'Sage');
|
||||
$this->saveSteamId('[U:1:71706948]', 'Sketis');
|
||||
$this->saveSteamId('[U:1:157204170]', 'Pyla');
|
||||
$this->saveSteamId('[U:1:30838206]', 'Heavy');
|
||||
$this->saveSteamId('[U:1:174774002]', 'Soldier');
|
||||
$this->saveSteamId('[U:1:92096346]', 'Fish');
|
||||
$this->saveSteamId('[U:1:143626373]', 'Pendulum');
|
||||
$this->saveSteamId('[U:1:30220936]', 'Jedi');
|
||||
|
||||
|
||||
$result = $this->uploadProvider->upload($token, 'RED', 'BLU', 'foodemo', $this->tmpDir . '/foo.dem');
|
||||
$this->assertStringStartsWith('STV available at: http://example.com/', $result);
|
||||
$result = $this->uploadProvider->upload($token, 'RED', 'BLU', 'foodemo', $this->tmpDir . '/foo.dem');
|
||||
$this->assertStringStartsWith('STV available at: http://example.com/', $result);
|
||||
|
||||
$demoId = (int)substr($result, strlen('STV available at: http://example.com/'));
|
||||
$demoId = (int)substr($result, strlen('STV available at: http://example.com/'));
|
||||
|
||||
$demo = $this->demoProvider->get($demoId, true);
|
||||
$demo = $this->demoProvider->get($demoId, true);
|
||||
|
||||
$this->assertNotNull($demo);
|
||||
$this->assertNotNull($demo);
|
||||
|
||||
$this->assertEquals('koth_product_rc8', $demo->getMap());
|
||||
$this->assertEquals(0, $demo->getBlueScore());
|
||||
$this->assertEquals(3, $demo->getRedScore());
|
||||
}
|
||||
$this->assertEquals('koth_product_rc8', $demo->getMap());
|
||||
$this->assertEquals(0, $demo->getBlueScore());
|
||||
$this->assertEquals(3, $demo->getRedScore());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,73 +6,73 @@ use Demostf\API\Providers\UserProvider;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class UserProviderTest extends TestCase {
|
||||
/** @var UserProvider */
|
||||
private $provider;
|
||||
/** @var UserProvider */
|
||||
private $provider;
|
||||
|
||||
/** @var \SteamId */
|
||||
private $steamId;
|
||||
/** @var \SteamId */
|
||||
private $steamId;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->steamId = $this->getSteamId('76561198024494988', 'Icewind');
|
||||
$this->provider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
}
|
||||
$this->steamId = $this->getSteamId('76561198024494988', 'Icewind');
|
||||
$this->provider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
}
|
||||
|
||||
public function testGetNonExisting() {
|
||||
$this->assertNull($this->provider->get('76561198024494988'));
|
||||
}
|
||||
public function testGetNonExisting() {
|
||||
$this->assertNull($this->provider->get('76561198024494988'));
|
||||
}
|
||||
|
||||
public function testStoreRetrieve() {
|
||||
$this->provider->store($this->steamId);
|
||||
public function testStoreRetrieve() {
|
||||
$this->provider->store($this->steamId);
|
||||
|
||||
$user = $this->provider->get('76561198024494988');
|
||||
$user = $this->provider->get('76561198024494988');
|
||||
|
||||
$this->assertEquals($this->steamId->getNickname(), $user->getName());
|
||||
$this->assertEquals($this->steamId->getSteamId64(), $user->getSteamId());
|
||||
}
|
||||
$this->assertEquals($this->steamId->getNickname(), $user->getName());
|
||||
$this->assertEquals($this->steamId->getSteamId64(), $user->getSteamId());
|
||||
}
|
||||
|
||||
public function returnTokenExisting() {
|
||||
$token1 = $this->provider->store($this->steamId);
|
||||
$token2 = $this->provider->store($this->steamId);
|
||||
public function returnTokenExisting() {
|
||||
$token1 = $this->provider->store($this->steamId);
|
||||
$token2 = $this->provider->store($this->steamId);
|
||||
|
||||
$this->assertEquals($token1, $token2);
|
||||
}
|
||||
$this->assertEquals($token1, $token2);
|
||||
}
|
||||
|
||||
public function testDoubleInsert() {
|
||||
$this->provider->store($this->steamId);
|
||||
$this->provider->store($this->steamId);
|
||||
public function testDoubleInsert() {
|
||||
$this->provider->store($this->steamId);
|
||||
$this->provider->store($this->steamId);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testByKey() {
|
||||
$token = $this->provider->store($this->steamId);
|
||||
public function testByKey() {
|
||||
$token = $this->provider->store($this->steamId);
|
||||
|
||||
$byKey = $this->provider->byKey($token);
|
||||
$this->assertEquals('76561198024494988', $byKey->getSteamId());
|
||||
}
|
||||
$byKey = $this->provider->byKey($token);
|
||||
$this->assertEquals('76561198024494988', $byKey->getSteamId());
|
||||
}
|
||||
|
||||
public function testSearch() {
|
||||
$result = $this->provider->search('__NOT__FOUND__');
|
||||
public function testSearch() {
|
||||
$result = $this->provider->search('__NOT__FOUND__');
|
||||
|
||||
$this->assertCount(0, $result);
|
||||
}
|
||||
$this->assertCount(0, $result);
|
||||
}
|
||||
|
||||
public function testGetIdExisting() {
|
||||
$this->provider->store($this->steamId);
|
||||
public function testGetIdExisting() {
|
||||
$this->provider->store($this->steamId);
|
||||
|
||||
$user = $this->provider->get($this->steamId->getSteamId64());
|
||||
$user = $this->provider->get($this->steamId->getSteamId64());
|
||||
|
||||
$this->assertEquals($user->getId(), $this->provider->getUserId($this->steamId->getSteamId64()));
|
||||
}
|
||||
$this->assertEquals($user->getId(), $this->provider->getUserId($this->steamId->getSteamId64()));
|
||||
}
|
||||
|
||||
public function testGetIdNew() {
|
||||
$id = $this->provider->getUserId($this->steamId->getSteamId64());
|
||||
public function testGetIdNew() {
|
||||
$id = $this->provider->getUserId($this->steamId->getSteamId64());
|
||||
|
||||
$user = $this->provider->get($this->steamId->getSteamId64());
|
||||
$user = $this->provider->get($this->steamId->getSteamId64());
|
||||
|
||||
|
||||
$this->assertEquals($user->getId(), $id);
|
||||
}
|
||||
$this->assertEquals($user->getId(), $id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,63 +4,62 @@ use Doctrine\DBAL\Connection;
|
|||
use Doctrine\DBAL\DriverManager;
|
||||
|
||||
abstract class TestCase extends \PHPUnit\Framework\TestCase {
|
||||
/** @var Connection */
|
||||
private $database;
|
||||
/** @var Connection */
|
||||
private $database;
|
||||
|
||||
protected function getDatabaseConnection() {
|
||||
if (!$this->database instanceof Connection) {
|
||||
$connectionParams = array(
|
||||
'dbname' => getenv('DB_DATABASE'),
|
||||
'user' => getenv('DB_USERNAME'),
|
||||
'password' => getenv('DB_PASSWORD'),
|
||||
'host' => getenv('DB_HOST'),
|
||||
'port' => getenv('DB_PORT'),
|
||||
'driver' => getenv('DB_TYPE'),
|
||||
);
|
||||
if ($connectionParams['driver'] === 'pgsql') {
|
||||
$connectionParams['driver'] = 'pdo_pgsql';
|
||||
}
|
||||
$this->database = DriverManager::getConnection($connectionParams);
|
||||
}
|
||||
return $this->database;
|
||||
}
|
||||
protected function getDatabaseConnection() {
|
||||
if (!$this->database instanceof Connection) {
|
||||
$connectionParams = [
|
||||
'dbname' => getenv('DB_DATABASE'),
|
||||
'user' => getenv('DB_USERNAME'),
|
||||
'password' => getenv('DB_PASSWORD'),
|
||||
'host' => getenv('DB_HOST'),
|
||||
'port' => getenv('DB_PORT'),
|
||||
'driver' => getenv('DB_TYPE'),
|
||||
];
|
||||
if ($connectionParams['driver'] === 'pgsql') {
|
||||
$connectionParams['driver'] = 'pdo_pgsql';
|
||||
}
|
||||
$this->database = DriverManager::getConnection($connectionParams);
|
||||
}
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
}
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
$this->clearDatabase();
|
||||
parent::tearDown();
|
||||
}
|
||||
public function tearDown() {
|
||||
$this->clearDatabase();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
private function clearDatabase() {
|
||||
if ($this->database instanceof Connection) {
|
||||
$tables = $this->database->getSchemaManager()->listTables();
|
||||
foreach ($tables as $table) {
|
||||
$this->truncateTable($table->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
private function clearDatabase() {
|
||||
if ($this->database instanceof Connection) {
|
||||
$tables = $this->database->getSchemaManager()->listTables();
|
||||
foreach ($tables as $table) {
|
||||
$this->truncateTable($table->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function truncateTable(string $tableName) {
|
||||
$sql = sprintf('TRUNCATE TABLE %s;', $tableName);
|
||||
$this->getDatabaseConnection()->query($sql);
|
||||
}
|
||||
private function truncateTable(string $tableName) {
|
||||
$sql = sprintf('TRUNCATE TABLE %s;', $tableName);
|
||||
$this->getDatabaseConnection()->query($sql);
|
||||
}
|
||||
|
||||
protected function getRandomGenerator() {
|
||||
$factory = new \RandomLib\Factory;
|
||||
return $factory->getMediumStrengthGenerator();
|
||||
}
|
||||
|
||||
protected function getSteamId($steamId, $name) {
|
||||
$steamId = new \SteamId($steamId, false);
|
||||
$closure = \Closure::bind(function ($steamId) use ($name) {
|
||||
$steamId->nickname = $name;
|
||||
$steamId->imageUrl = 'foo';
|
||||
}, null, $steamId);
|
||||
$closure($steamId);
|
||||
return $steamId;
|
||||
}
|
||||
protected function getRandomGenerator() {
|
||||
$factory = new \RandomLib\Factory;
|
||||
return $factory->getMediumStrengthGenerator();
|
||||
}
|
||||
|
||||
protected function getSteamId($steamId, $name) {
|
||||
$steamId = new \SteamId($steamId, false);
|
||||
$closure = \Closure::bind(function ($steamId) use ($name) {
|
||||
$steamId->nickname = $name;
|
||||
$steamId->imageUrl = 'foo';
|
||||
}, null, $steamId);
|
||||
$closure($steamId);
|
||||
return $steamId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,41 +3,41 @@
|
|||
$_SERVER['SCRIPT_NAME'] = '';
|
||||
|
||||
if ($_SERVER["REQUEST_URI"] === '/upload') {
|
||||
require __DIR__ . '/../src/public/upload.php';
|
||||
} else if ($_SERVER["REQUEST_URI"] === '/reset') {
|
||||
// allow the api tests to reset the database
|
||||
/** @var \Demostf\API\Container $container */
|
||||
$container = require __DIR__ . '/../src/init.php';
|
||||
$connection = $container->getConnection();
|
||||
require __DIR__ . '/../src/public/upload.php';
|
||||
} elseif ($_SERVER["REQUEST_URI"] === '/reset') {
|
||||
// allow the api tests to reset the database
|
||||
/** @var \Demostf\API\Container $container */
|
||||
$container = require __DIR__ . '/../src/init.php';
|
||||
$connection = $container->getConnection();
|
||||
|
||||
clearDatabase($connection);
|
||||
} else if ($_SERVER["REQUEST_URI"] === '/testuser') {
|
||||
// allow the api tests to create a test user
|
||||
/** @var \Demostf\API\Container $container */
|
||||
$container = require __DIR__ . '/../src/init.php';
|
||||
$connection = $container->getConnection();
|
||||
clearDatabase($connection);
|
||||
} elseif ($_SERVER["REQUEST_URI"] === '/testuser') {
|
||||
// allow the api tests to create a test user
|
||||
/** @var \Demostf\API\Container $container */
|
||||
$container = require __DIR__ . '/../src/init.php';
|
||||
$connection = $container->getConnection();
|
||||
|
||||
$query = $connection->createQueryBuilder();
|
||||
$query->insert('users')
|
||||
->values([
|
||||
'steamid' => $query->createNamedParameter('steamid1'),
|
||||
'name' => $query->createNamedParameter('nickname1'),
|
||||
'avatar' => $query->createNamedParameter('avatar1'),
|
||||
'token' => $query->createNamedParameter('key1')
|
||||
])->add('orderBy', 'ON CONFLICT DO NOTHING')// hack to append arbitrary string to sql
|
||||
->execute();
|
||||
$query = $connection->createQueryBuilder();
|
||||
$query->insert('users')
|
||||
->values([
|
||||
'steamid' => $query->createNamedParameter('steamid1'),
|
||||
'name' => $query->createNamedParameter('nickname1'),
|
||||
'avatar' => $query->createNamedParameter('avatar1'),
|
||||
'token' => $query->createNamedParameter('key1')
|
||||
])->add('orderBy', 'ON CONFLICT DO NOTHING')// hack to append arbitrary string to sql
|
||||
->execute();
|
||||
} else {
|
||||
require __DIR__ . '/../src/public/index.php';
|
||||
require __DIR__ . '/../src/public/index.php';
|
||||
}
|
||||
|
||||
function clearDatabase(\Doctrine\DBAL\Connection $connection) {
|
||||
$tables = $connection->getSchemaManager()->listTables();
|
||||
foreach ($tables as $table) {
|
||||
truncateTable($connection, $table->getName());
|
||||
}
|
||||
$tables = $connection->getSchemaManager()->listTables();
|
||||
foreach ($tables as $table) {
|
||||
truncateTable($connection, $table->getName());
|
||||
}
|
||||
}
|
||||
|
||||
function truncateTable(\Doctrine\DBAL\Connection $connection, string $tableName) {
|
||||
$sql = sprintf('TRUNCATE TABLE %s;', $tableName);
|
||||
$connection->query($sql);
|
||||
$sql = sprintf('TRUNCATE TABLE %s;', $tableName);
|
||||
$connection->query($sql);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue