mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 09:54:17 +02:00
stricter cs
This commit is contained in:
parent
309ae17036
commit
d9a843ecd6
54 changed files with 346 additions and 168 deletions
|
|
@ -1,4 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test\Data;
|
||||
|
||||
|
|
@ -17,7 +19,7 @@ class DemoPlayerTest extends TestCase {
|
|||
'avatar' => 'asd.png',
|
||||
'kills' => 5,
|
||||
'assists' => 3,
|
||||
'deaths' => 7
|
||||
'deaths' => 7,
|
||||
];
|
||||
|
||||
$demoPlayer = DemoPlayer::fromRow($data);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test\Demo;
|
||||
|
||||
|
|
@ -56,7 +58,7 @@ class DemoSaverTest extends TestCase {
|
|||
3,
|
||||
[
|
||||
new ChatMessage('user1', 12, 'msg1'),
|
||||
new ChatMessage('user2', 13, 'msg2')
|
||||
new ChatMessage('user2', 13, 'msg2'),
|
||||
],
|
||||
[
|
||||
new ParsedPlayer('user1', 1, '1234567', 'red', 'scout'),
|
||||
|
|
@ -107,7 +109,7 @@ class DemoSaverTest extends TestCase {
|
|||
|
||||
$this->assertEquals([
|
||||
new ChatMessage('user1', 12, 'msg1'),
|
||||
new ChatMessage('user2', 13, 'msg2')
|
||||
new ChatMessage('user2', 13, 'msg2'),
|
||||
], $chatProvider->getChat($demoId));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test\Demo;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test\Demo;
|
||||
|
||||
|
|
@ -44,7 +46,7 @@ class HeaderParserTest extends TestCase {
|
|||
*/
|
||||
public function testNonDemoShort() {
|
||||
$parser = new HeaderParser();
|
||||
$parser->parseString("short");
|
||||
$parser->parseString('short');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test\Demo;
|
||||
|
||||
|
|
@ -21,6 +23,7 @@ class ParserTest extends TestCase {
|
|||
->method('parse')
|
||||
->will($this->returnCallback(function ($path) {
|
||||
$jsonPath = str_replace('.dem', '-raw.json', $path);
|
||||
|
||||
return json_decode(file_get_contents($jsonPath), true);
|
||||
}));
|
||||
}
|
||||
|
|
@ -51,9 +54,9 @@ class ParserTest extends TestCase {
|
|||
|
||||
$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((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());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php declare(strict_types = 1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test\Providers;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test\Providers;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test\Providers;
|
||||
|
||||
|
|
@ -149,11 +151,13 @@ class DemoProviderTest extends TestCase {
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test\Providers;
|
||||
|
||||
|
|
@ -25,7 +27,7 @@ class UploadProviderTest extends TestCase {
|
|||
private $headerParser;
|
||||
/** @var Parser */
|
||||
private $parser;
|
||||
/** @var DemoStore */
|
||||
/** @var DemoStore */
|
||||
private $demoStore;
|
||||
/** @var UserProvider */
|
||||
private $userProvider;
|
||||
|
|
@ -49,6 +51,7 @@ class UploadProviderTest extends TestCase {
|
|||
->method('parse')
|
||||
->will($this->returnCallback(function ($path) {
|
||||
$jsonPath = str_replace('.dem', '-raw.json', $path);
|
||||
|
||||
return json_decode(file_get_contents($jsonPath), true);
|
||||
}));
|
||||
|
||||
|
|
@ -290,11 +293,10 @@ class UploadProviderTest extends TestCase {
|
|||
$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);
|
||||
|
||||
$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);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test\Providers;
|
||||
|
||||
|
|
@ -72,7 +74,6 @@ class UserProviderTest extends TestCase {
|
|||
|
||||
$user = $this->provider->get($this->steamId->getSteamId64());
|
||||
|
||||
|
||||
$this->assertEquals($user->getId(), $id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
<?php namespace Demostf\API\Test;
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Demostf\API\Test;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\DriverManager;
|
||||
|
|
@ -22,6 +26,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
|
|||
}
|
||||
$this->database = DriverManager::getConnection($connectionParams);
|
||||
}
|
||||
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
|
|
@ -49,7 +54,8 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
|
|||
}
|
||||
|
||||
protected function getRandomGenerator() {
|
||||
$factory = new \RandomLib\Factory;
|
||||
$factory = new \RandomLib\Factory();
|
||||
|
||||
return $factory->getMediumStrengthGenerator();
|
||||
}
|
||||
|
||||
|
|
@ -60,6 +66,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
|
|||
$steamId->imageUrl = 'foo';
|
||||
}, null, $steamId);
|
||||
$closure($steamId);
|
||||
|
||||
return $steamId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,4 @@
|
|||
<?php require_once __DIR__ . '/../src/init.php';
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/../src/init.php';
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
<?php declare(strict_types=1);
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
$_SERVER['SCRIPT_NAME'] = '';
|
||||
|
||||
if ($_SERVER["REQUEST_URI"] === '/upload') {
|
||||
if ($_SERVER['REQUEST_URI'] === '/upload') {
|
||||
require __DIR__ . '/../src/public/upload.php';
|
||||
} elseif ($_SERVER["REQUEST_URI"] === '/reset') {
|
||||
} 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);
|
||||
} elseif ($_SERVER["REQUEST_URI"] === '/testuser') {
|
||||
} 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';
|
||||
|
|
@ -23,7 +25,7 @@ if ($_SERVER["REQUEST_URI"] === '/upload') {
|
|||
'steamid' => $query->createNamedParameter('steamid1'),
|
||||
'name' => $query->createNamedParameter('nickname1'),
|
||||
'avatar' => $query->createNamedParameter('avatar1'),
|
||||
'token' => $query->createNamedParameter('key1')
|
||||
'token' => $query->createNamedParameter('key1'),
|
||||
])->add('orderBy', 'ON CONFLICT DO NOTHING')// hack to append arbitrary string to sql
|
||||
->execute();
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue