mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
run lint
This commit is contained in:
parent
3e22e36a79
commit
7320711a36
23 changed files with 36 additions and 81 deletions
|
|
@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Demostf\API\Controllers;
|
namespace Demostf\API\Controllers;
|
||||||
|
|
||||||
use Ehesp\SteamLogin\SteamLogin;
|
|
||||||
use Demostf\API\Providers\AuthProvider;
|
use Demostf\API\Providers\AuthProvider;
|
||||||
use Demostf\API\Providers\UserProvider;
|
use Demostf\API\Providers\UserProvider;
|
||||||
|
use Ehesp\SteamLogin\SteamLogin;
|
||||||
use Flight;
|
use Flight;
|
||||||
use flight\net\Request;
|
use flight\net\Request;
|
||||||
use flight\net\Response;
|
use flight\net\Response;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ class BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function query($name, $default) {
|
protected function query($name, $default) {
|
||||||
return isset($this->request->query[$name]) ? $this->request->query[$name] : $default;
|
return $this->request->query[$name] ?? $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function file($name) {
|
protected function file($name) {
|
||||||
|
|
@ -25,7 +25,7 @@ class BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function post($name, $default = null) {
|
protected function post($name, $default = null) {
|
||||||
return isset($this->request->data[$name]) ? $this->request->data[$name] : $default;
|
return $this->request->data[$name] ?? $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function json($data, $code = 200, $encode = true, $charset = 'utf-8', $option = 0) {
|
protected function json($data, $code = 200, $encode = true, $charset = 'utf-8', $option = 0) {
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,6 @@ use Demostf\API\Providers\DemoListProvider;
|
||||||
use Demostf\API\Providers\DemoProvider;
|
use Demostf\API\Providers\DemoProvider;
|
||||||
use flight\net\Request;
|
use flight\net\Request;
|
||||||
use flight\net\Response;
|
use flight\net\Response;
|
||||||
use function intval;
|
|
||||||
use function is_array;
|
|
||||||
|
|
||||||
class DemoController extends BaseController {
|
class DemoController extends BaseController {
|
||||||
/** @var DemoProvider */
|
/** @var DemoProvider */
|
||||||
|
|
@ -49,7 +47,7 @@ class DemoController extends BaseController {
|
||||||
* @param string $id
|
* @param string $id
|
||||||
*/
|
*/
|
||||||
public function get($id) {
|
public function get($id) {
|
||||||
$this->json($this->demoProvider->get(intval($id, 10)));
|
$this->json($this->demoProvider->get(\intval($id, 10)));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getFilter() {
|
protected function getFilter() {
|
||||||
|
|
@ -67,7 +65,7 @@ class DemoController extends BaseController {
|
||||||
$filter['backend'] = $backend;
|
$filter['backend'] = $backend;
|
||||||
}
|
}
|
||||||
if ($players) {
|
if ($players) {
|
||||||
if (!is_array($players)) {
|
if (!\is_array($players)) {
|
||||||
$players = explode(',', $players);
|
$players = explode(',', $players);
|
||||||
}
|
}
|
||||||
$players = array_filter($players);
|
$players = array_filter($players);
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ class UserController extends BaseController {
|
||||||
}
|
}
|
||||||
} elseif ($user = $this->userProvider->getById((int) $steamId)) {
|
} elseif ($user = $this->userProvider->getById((int) $steamId)) {
|
||||||
Flight::json($user);
|
Flight::json($user);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Flight::json($this->userProvider->get($steamId));
|
Flight::json($this->userProvider->get($steamId));
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,6 @@ class ParsedDemo {
|
||||||
/**
|
/**
|
||||||
* ParsedDemo constructor.
|
* ParsedDemo constructor.
|
||||||
*
|
*
|
||||||
* @param int $redScore
|
|
||||||
* @param int $blueScore
|
|
||||||
* @param ChatMessage[] $chat
|
* @param ChatMessage[] $chat
|
||||||
* @param ParsedPlayer[] $players
|
* @param ParsedPlayer[] $players
|
||||||
* @param ParsedKill[] $kills
|
* @param ParsedKill[] $kills
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,6 @@ class ChatMessage implements JsonSerializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ChatMessage constructor.
|
* ChatMessage constructor.
|
||||||
*
|
|
||||||
* @param string $user
|
|
||||||
* @param int $time
|
|
||||||
* @param string $message
|
|
||||||
*/
|
*/
|
||||||
public function __construct(string $user, int $time, string $message) {
|
public function __construct(string $user, int $time, string $message) {
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
|
@ -29,23 +25,14 @@ class ChatMessage implements JsonSerializable {
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getUser(): string {
|
public function getUser(): string {
|
||||||
return $this->user;
|
return $this->user;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function getTime(): int {
|
public function getTime(): int {
|
||||||
return $this->time;
|
return $this->time;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getMessage(): string {
|
public function getMessage(): string {
|
||||||
return $this->message;
|
return $this->message;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Demostf\API\Demo;
|
namespace Demostf\API\Demo;
|
||||||
|
|
||||||
use function count;
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Demostf\API\Data\Kill;
|
use Demostf\API\Data\Kill;
|
||||||
use Demostf\API\Data\ParsedDemo;
|
use Demostf\API\Data\ParsedDemo;
|
||||||
|
|
@ -66,7 +65,7 @@ class DemoSaver {
|
||||||
$upload->getBlue(),
|
$upload->getBlue(),
|
||||||
$demo->getRedScore(),
|
$demo->getRedScore(),
|
||||||
$demo->getBlueScore(),
|
$demo->getBlueScore(),
|
||||||
count($demo->getPlayers()),
|
\count($demo->getPlayers()),
|
||||||
$upload->getUploaderId(),
|
$upload->getUploaderId(),
|
||||||
$upload->getHash(),
|
$upload->getHash(),
|
||||||
$storedDemo->getBackend(),
|
$storedDemo->getBackend(),
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||||
namespace Demostf\API\Demo;
|
namespace Demostf\API\Demo;
|
||||||
|
|
||||||
use Demostf\API\Data\StoredDemo;
|
use Demostf\API\Data\StoredDemo;
|
||||||
use function dirname;
|
|
||||||
|
|
||||||
class DemoStore {
|
class DemoStore {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
|
|
@ -20,8 +19,8 @@ class DemoStore {
|
||||||
|
|
||||||
public function store(string $sourcePath, string $name): StoredDemo {
|
public function store(string $sourcePath, string $name): StoredDemo {
|
||||||
$target = $this->generatePath($name);
|
$target = $this->generatePath($name);
|
||||||
if (!is_dir(dirname($target))) {
|
if (!is_dir(\dirname($target))) {
|
||||||
mkdir(dirname($target), 0777, true);
|
mkdir(\dirname($target), 0777, true);
|
||||||
}
|
}
|
||||||
rename($sourcePath, $target);
|
rename($sourcePath, $target);
|
||||||
chmod($target, 0755);
|
chmod($target, 0755);
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,6 @@ class HeaderParser {
|
||||||
* @param string $head string containing the demo header binary data
|
* @param string $head string containing the demo header binary data
|
||||||
*
|
*
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*
|
|
||||||
* @return Header
|
|
||||||
*/
|
*/
|
||||||
public function parseString(string $head): Header {
|
public function parseString(string $head): Header {
|
||||||
$info = @unpack(
|
$info = @unpack(
|
||||||
|
|
@ -32,8 +30,6 @@ class HeaderParser {
|
||||||
* @param resource $stream
|
* @param resource $stream
|
||||||
*
|
*
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*
|
|
||||||
* @return Header
|
|
||||||
*/
|
*/
|
||||||
public function parseStream($stream): Header {
|
public function parseStream($stream): Header {
|
||||||
$head = fread($stream, 2048);
|
$head = fread($stream, 2048);
|
||||||
|
|
@ -44,11 +40,7 @@ class HeaderParser {
|
||||||
/**
|
/**
|
||||||
* Parse demo info from a local file.
|
* Parse demo info from a local file.
|
||||||
*
|
*
|
||||||
* @param string $path
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*
|
|
||||||
* @return Header
|
|
||||||
*/
|
*/
|
||||||
public function parseHeader(string $path): Header {
|
public function parseHeader(string $path): Header {
|
||||||
if (!is_readable($path)) {
|
if (!is_readable($path)) {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ use Demostf\API\Data\ParsedKill;
|
||||||
use Demostf\API\Data\ParsedPlayer;
|
use Demostf\API\Data\ParsedPlayer;
|
||||||
use Exception;
|
use Exception;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use function is_array;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Higher level parser.
|
* Higher level parser.
|
||||||
|
|
@ -38,7 +37,7 @@ class Parser {
|
||||||
|
|
||||||
public function analyse(string $path): ParsedDemo {
|
public function analyse(string $path): ParsedDemo {
|
||||||
$data = $this->rawParser->parse($path);
|
$data = $this->rawParser->parse($path);
|
||||||
if (is_array($data) && isset($data['intervalPerTick'])) {
|
if (\is_array($data) && isset($data['intervalPerTick'])) {
|
||||||
return $this->handleData($data);
|
return $this->handleData($data);
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidArgumentException('Error parsing demo');
|
throw new InvalidArgumentException('Error parsing demo');
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,6 @@ class RawParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
|
||||||
* @return array|null
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function parse(string $path): ?array {
|
public function parse(string $path): ?array {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
|
* @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
|
||||||
*
|
|
||||||
* @license GNU AGPL version 3 or any later version
|
* @license GNU AGPL version 3 or any later version
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
|
@ -18,11 +17,9 @@ declare(strict_types=1);
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Demostf\API\Error;
|
namespace Demostf\API\Error;
|
||||||
|
|
||||||
class InvalidHashException extends \Exception {
|
class InvalidHashException extends \Exception {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
|
* @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
|
||||||
*
|
|
||||||
* @license GNU AGPL version 3 or any later version
|
* @license GNU AGPL version 3 or any later version
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
|
@ -18,11 +17,9 @@ declare(strict_types=1);
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Demostf\API\Error;
|
namespace Demostf\API\Error;
|
||||||
|
|
||||||
class InvalidKeyException extends \Exception {
|
class InvalidKeyException extends \Exception {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,9 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Demostf\API\Providers;
|
namespace Demostf\API\Providers;
|
||||||
|
|
||||||
use Doctrine\DBAL\Query\QueryBuilder;
|
|
||||||
use function count;
|
|
||||||
use Demostf\API\Demo\Demo;
|
use Demostf\API\Demo\Demo;
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
use function is_array;
|
use Doctrine\DBAL\Query\QueryBuilder;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
class DemoListProvider extends BaseProvider {
|
class DemoListProvider extends BaseProvider {
|
||||||
|
|
@ -41,13 +39,13 @@ class DemoListProvider extends BaseProvider {
|
||||||
$query->select('p.demo_id')
|
$query->select('p.demo_id')
|
||||||
->from('players', 'p');
|
->from('players', 'p');
|
||||||
|
|
||||||
if (count($userIds) > 1) {
|
if (\count($userIds) > 1) {
|
||||||
$query->where($query->expr()->in('user_id',
|
$query->where($query->expr()->in('user_id',
|
||||||
$query->createNamedParameter($userIds, Connection::PARAM_INT_ARRAY)))
|
$query->createNamedParameter($userIds, Connection::PARAM_INT_ARRAY)))
|
||||||
->groupBy('demo_id')
|
->groupBy('demo_id')
|
||||||
->having($query->expr()->eq(
|
->having($query->expr()->eq(
|
||||||
'COUNT(user_id)',
|
'COUNT(user_id)',
|
||||||
$query->createNamedParameter(count($userIds), PDO::PARAM_INT)
|
$query->createNamedParameter(\count($userIds), PDO::PARAM_INT)
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$query->where($query->expr()->eq('user_id',
|
$query->where($query->expr()->eq('user_id',
|
||||||
|
|
@ -57,7 +55,7 @@ class DemoListProvider extends BaseProvider {
|
||||||
->setMaxResults(50)
|
->setMaxResults(50)
|
||||||
->setFirstResult(((int) $page - 1) * 50);
|
->setFirstResult(((int) $page - 1) * 50);
|
||||||
|
|
||||||
if (count($where)) {
|
if (\count($where)) {
|
||||||
$query->innerJoin('p', 'demos', 'd', $query->expr()->eq('demo_id', 'd.id'));
|
$query->innerJoin('p', 'demos', 'd', $query->expr()->eq('demo_id', 'd.id'));
|
||||||
$this->addWhere($query, $where);
|
$this->addWhere($query, $where);
|
||||||
}
|
}
|
||||||
|
|
@ -105,14 +103,10 @@ class DemoListProvider extends BaseProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $page
|
|
||||||
* @param array $where
|
|
||||||
* @param string $order
|
|
||||||
*
|
|
||||||
* @return Demo[]
|
* @return Demo[]
|
||||||
*/
|
*/
|
||||||
public function listDemos(int $page, array $where = [], string $order = 'DESC') {
|
public function listDemos(int $page, array $where = [], string $order = 'DESC') {
|
||||||
if (isset($where['players']) and is_array($where['players']) and count($where['players']) > 0) {
|
if (isset($where['players']) and \is_array($where['players']) and \count($where['players']) > 0) {
|
||||||
return $this->listProfile($page, $where);
|
return $this->listProfile($page, $where);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Demostf\API\Providers;
|
namespace Demostf\API\Providers;
|
||||||
|
|
||||||
use Doctrine\DBAL\Connection;
|
|
||||||
use const DATE_ATOM;
|
use const DATE_ATOM;
|
||||||
use Demostf\API\Data\DemoPlayer;
|
use Demostf\API\Data\DemoPlayer;
|
||||||
use Demostf\API\Demo\Demo;
|
use Demostf\API\Demo\Demo;
|
||||||
|
use Doctrine\DBAL\Connection;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
|
||||||
class DemoProvider extends BaseProvider {
|
class DemoProvider extends BaseProvider {
|
||||||
|
|
@ -43,7 +43,7 @@ class DemoProvider extends BaseProvider {
|
||||||
WHERE demo_id = ?';
|
WHERE demo_id = ?';
|
||||||
|
|
||||||
$demo = $this->fetchDemo($id);
|
$demo = $this->fetchDemo($id);
|
||||||
if ($demo === null) {
|
if (null === $demo) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ class InfoProvider extends BaseProvider {
|
||||||
$query = $this->getQueryBuilder();
|
$query = $this->getQueryBuilder();
|
||||||
$query->select('count(*)')
|
$query->select('count(*)')
|
||||||
->from($table);
|
->from($table);
|
||||||
|
|
||||||
return $query->execute()->fetch(PDO::FETCH_COLUMN);
|
return $query->execute()->fetch(PDO::FETCH_COLUMN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ namespace Demostf\API\Providers;
|
||||||
use Demostf\API\Data\SteamUser;
|
use Demostf\API\Data\SteamUser;
|
||||||
use Demostf\API\Data\User;
|
use Demostf\API\Data\User;
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
use function is_array;
|
|
||||||
use PDO;
|
use PDO;
|
||||||
use RandomLib\Generator;
|
use RandomLib\Generator;
|
||||||
use SteamId;
|
use SteamId;
|
||||||
|
|
@ -108,7 +107,7 @@ class UserProvider extends BaseProvider {
|
||||||
->setMaxResults(1);
|
->setMaxResults(1);
|
||||||
|
|
||||||
$result = $query->execute()->fetch();
|
$result = $query->execute()->fetch();
|
||||||
if (is_array($result)) {
|
if (\is_array($result)) {
|
||||||
return $result;
|
return $result;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -116,8 +115,6 @@ class UserProvider extends BaseProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $search
|
|
||||||
*
|
|
||||||
* @return SteamUser[]
|
* @return SteamUser[]
|
||||||
*/
|
*/
|
||||||
public function search(string $search): array {
|
public function search(string $search): array {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use flight\net\Response;
|
||||||
use flight\util\Collection;
|
use flight\util\Collection;
|
||||||
|
|
||||||
abstract class ControllerTest extends TestCase {
|
abstract class ControllerTest extends TestCase {
|
||||||
/** @var string $responseData */
|
/** @var string */
|
||||||
private $responseData;
|
private $responseData;
|
||||||
|
|
||||||
protected function getRequest(array $get = [], array $post = [], array $files = []): Request {
|
protected function getRequest(array $get = [], array $post = [], array $files = []): Request {
|
||||||
|
|
|
||||||
|
|
@ -13,17 +13,16 @@ use Demostf\API\Error\InvalidKeyException;
|
||||||
use Demostf\API\Providers\ChatProvider;
|
use Demostf\API\Providers\ChatProvider;
|
||||||
use Demostf\API\Providers\DemoListProvider;
|
use Demostf\API\Providers\DemoListProvider;
|
||||||
use Demostf\API\Providers\DemoProvider;
|
use Demostf\API\Providers\DemoProvider;
|
||||||
use InvalidArgumentException;
|
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
|
||||||
class DemoControllerTest extends ControllerTest {
|
class DemoControllerTest extends ControllerTest {
|
||||||
/** @var DemoStore|MockObject $demoStore */
|
/** @var DemoStore|MockObject */
|
||||||
private $demoStore;
|
private $demoStore;
|
||||||
/** @var DemoProvider|MockObject $demoProvider */
|
/** @var DemoProvider|MockObject */
|
||||||
private $demoProvider;
|
private $demoProvider;
|
||||||
/** @var ChatProvider|MockObject $chatProvider */
|
/** @var ChatProvider|MockObject */
|
||||||
private $chatProvider;
|
private $chatProvider;
|
||||||
/** @var DemoListProvider|MockObject $demoListProvider */
|
/** @var DemoListProvider|MockObject */
|
||||||
private $demoListProvider;
|
private $demoListProvider;
|
||||||
|
|
||||||
public function setUp(): void {
|
public function setUp(): void {
|
||||||
|
|
@ -208,7 +207,7 @@ class DemoControllerTest extends ControllerTest {
|
||||||
->method('listDemos')
|
->method('listDemos')
|
||||||
->with(1, [
|
->with(1, [
|
||||||
'before' => \DateTime::createFromFormat('U', '500'),
|
'before' => \DateTime::createFromFormat('U', '500'),
|
||||||
'after' => \DateTime::createFromFormat('U', '100')
|
'after' => \DateTime::createFromFormat('U', '100'),
|
||||||
], 'DESC')
|
], 'DESC')
|
||||||
->willReturn(['dummy']);
|
->willReturn(['dummy']);
|
||||||
|
|
||||||
|
|
@ -222,7 +221,7 @@ class DemoControllerTest extends ControllerTest {
|
||||||
$this->demoListProvider->expects($this->once())
|
$this->demoListProvider->expects($this->once())
|
||||||
->method('listDemos')
|
->method('listDemos')
|
||||||
->with(1, [
|
->with(1, [
|
||||||
'before' => \DateTime::createFromFormat('U', '500')
|
'before' => \DateTime::createFromFormat('U', '500'),
|
||||||
], 'DESC')
|
], 'DESC')
|
||||||
->willReturn(['dummy']);
|
->willReturn(['dummy']);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,11 @@ class ParserTest extends TestCase {
|
||||||
|
|
||||||
$this->rawParser->expects($this->any())
|
$this->rawParser->expects($this->any())
|
||||||
->method('parse')
|
->method('parse')
|
||||||
->will($this->returnCallback(function ($path) {
|
->willReturnCallback(function ($path) {
|
||||||
$jsonPath = str_replace('.dem', '-raw.json', $path);
|
$jsonPath = str_replace('.dem', '-raw.json', $path);
|
||||||
|
|
||||||
return json_decode(file_get_contents($jsonPath), true);
|
return json_decode(file_get_contents($jsonPath), true);
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAnalyse() {
|
public function testAnalyse() {
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class DemoListProviderTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDemo(int $uploaderId, $map = 'map', $playerCount = 18, int $time = null) {
|
private function getDemo(int $uploaderId, $map = 'map', $playerCount = 18, int $time = null) {
|
||||||
$time = is_null($time) ? new \DateTime() : \DateTime::createFromFormat('U', (string) $time);
|
$time = null === $time ? new \DateTime() : \DateTime::createFromFormat('U', (string) $time);
|
||||||
|
|
||||||
return new Demo(
|
return new Demo(
|
||||||
0,
|
0,
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ use InvalidArgumentException;
|
||||||
use RecursiveDirectoryIterator;
|
use RecursiveDirectoryIterator;
|
||||||
use RecursiveIteratorIterator;
|
use RecursiveIteratorIterator;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use function strlen;
|
|
||||||
|
|
||||||
class UploadProviderTest extends TestCase {
|
class UploadProviderTest extends TestCase {
|
||||||
/** @var RawParser */
|
/** @var RawParser */
|
||||||
|
|
@ -59,11 +58,11 @@ class UploadProviderTest extends TestCase {
|
||||||
|
|
||||||
$this->rawParser->expects($this->any())
|
$this->rawParser->expects($this->any())
|
||||||
->method('parse')
|
->method('parse')
|
||||||
->will($this->returnCallback(function ($path) {
|
->willReturnCallback(function ($path) {
|
||||||
$jsonPath = str_replace('.dem', '-raw.json', $path);
|
$jsonPath = str_replace('.dem', '-raw.json', $path);
|
||||||
|
|
||||||
return json_decode(file_get_contents($jsonPath), true);
|
return json_decode(file_get_contents($jsonPath), true);
|
||||||
}));
|
});
|
||||||
|
|
||||||
$targetDir = tempnam(sys_get_temp_dir(), 'dummy_target_');
|
$targetDir = tempnam(sys_get_temp_dir(), 'dummy_target_');
|
||||||
unlink($targetDir);
|
unlink($targetDir);
|
||||||
|
|
@ -307,7 +306,7 @@ class UploadProviderTest extends TestCase {
|
||||||
$result = $this->uploadProvider->upload($token, 'RED', 'BLU', 'foodemo', $this->tmpDir . '/foo.dem');
|
$result = $this->uploadProvider->upload($token, 'RED', 'BLU', 'foodemo', $this->tmpDir . '/foo.dem');
|
||||||
$this->assertStringStartsWith('STV available at: http://example.com/', $result);
|
$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);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue