-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameServerTest.php
93 lines (72 loc) · 3.02 KB
/
GameServerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/*
* This file is a part of the Civ14 project.
*
* Copyright (c) 2025-present Valithor Obsidion <[email protected]>
*/
require_once __DIR__ . '/../vendor/autoload.php';
use PHPUnit\Framework\TestCase;
use Civ13\Civ13;
use Civ14\GameServer;
use React\Http\Browser;
use Psr\Http\Message\ResponseInterface;
use function React\Async\await;
use function React\Promise\resolve;
class GameServerTest extends TestCase
{
private GameServer $api;
private $browserMock;
protected function setUp(): void
{
// Mock the Civ13 instance
$civ13Mock = $this->createMock(Civ13::class);
// Create a real Browser instance or mock it
$this->browserMock = $this->createMock(Browser::class);
// Create the GameServer instance
$this->api = new GameServer($civ13Mock);
$this->api->setProtocol('http');
$this->api->setIP(gethostbyname('www.civ13.com')); //$this->api->setIP('127.0.0.1');
$this->api->setPort(1212);
$this->api->setWatchdogToken(getenv('SS14_WATCHDOG_TOKEN') ?? 'you should choose a better token');
}
public function testGetStatus(): void
{
// Mock the response
$responseMock = $this->createMock(ResponseInterface::class);
// Mock the Browser's get method
$this->browserMock->method('get')->with('/status')->willReturn(resolve($responseMock));
// Test the getStatus method
await($this->api->getStatus()->then(fn($result) => $this->assertArrayHasKey('name', $result, "The 'name' key is missing in the response.")));
}
public function testGetInfo(): void
{
// Mock the response
$responseMock = $this->createMock(ResponseInterface::class);
// Mock the Browser's get method
$this->browserMock->method('get')->with('/info')->willReturn(resolve($responseMock));
// Test the getInfo method
await($this->api->getInfo()->then(fn($result) => $this->assertArrayHasKey('build', $result, "The 'build' key is missing in the response.")));
}
/*
public function testUpdate(): void
{
// Mock the response
$responseMock = $this->createMock(ResponseInterface::class);
$responseMock->method('getStatusCode')->willReturn(200);
// Mock the Browser's post method
$this->browserMock->method('post')->with('/update', $this->anything())->willReturn(resolve($responseMock));
// Test the update method
await($this->api->update()->then(fn($result) => $this->assertTrue($result)));
}
public function testShutdown(): void
{
// Mock the response
$responseMock = $this->createMock(ResponseInterface::class);
$responseMock->method('getStatusCode')->willReturn(200);
// Mock the Browser's post method
$this->browserMock->method('post')->with('/shutdown', $this->anything())->willReturn(resolve($responseMock));
// Test the shutdown method
await($this->api->shutdown()->then( fn($result) => $this->assertTrue($result)));
}
*/
}