1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace SmrTest\lib\DefaultGame; |
4
|
|
|
|
5
|
|
|
use Globals; |
6
|
|
|
use Smr\Race; |
7
|
|
|
use SmrGame; |
8
|
|
|
use SmrTest\BaseIntegrationSpec; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @covers SmrGame |
12
|
|
|
*/ |
13
|
|
|
class SmrGameIntegrationTest extends BaseIntegrationSpec { |
14
|
|
|
|
15
|
|
|
protected function tablesToTruncate(): array { |
16
|
|
|
return ['game', 'race_has_relation']; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
protected function tearDown(): void { |
20
|
|
|
SmrGame::clearCache(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function test_gameExists(): void { |
24
|
|
|
// Test that the game does not exist beforehand |
25
|
|
|
$gameID = 42; |
26
|
|
|
self::assertFalse(SmrGame::gameExists($gameID)); |
27
|
|
|
|
28
|
|
|
// Now create the game and confirm that the game now exists |
29
|
|
|
SmrGame::createGame($gameID); |
30
|
|
|
self::assertTrue(SmrGame::gameExists($gameID)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function test_save_and_reload_required_properties(): void { |
34
|
|
|
// First create a new game |
35
|
|
|
$gameID = 3; |
36
|
|
|
$game1 = SmrGame::createGame($gameID); |
37
|
|
|
|
38
|
|
|
// Then set all of its properties |
39
|
|
|
$game1->setName('Test Game'); |
40
|
|
|
$game1->setDescription('A test game.'); |
41
|
|
|
$game1->setStartTime(123); |
42
|
|
|
$game1->setJoinTime(234); |
43
|
|
|
$game1->setEndTime(345); |
44
|
|
|
$game1->setMaxPlayers(5); |
45
|
|
|
$game1->setMaxTurns(1000); |
46
|
|
|
$game1->setStartTurnHours(24); |
47
|
|
|
$game1->setGameTypeID(SmrGame::GAME_TYPE_DRAFT); |
48
|
|
|
$game1->setCreditsNeeded(10); |
49
|
|
|
$game1->setGameSpeed(1.5); |
50
|
|
|
$game1->setEnabled(true); |
51
|
|
|
$game1->setIgnoreStats(true); |
52
|
|
|
$game1->setAllianceMaxPlayers(15); |
53
|
|
|
$game1->setAllianceMaxVets(10); |
54
|
|
|
$game1->setStartingCredits(3000); |
55
|
|
|
|
56
|
|
|
// Now save the game and reload it |
57
|
|
|
$game1->save(); |
58
|
|
|
$game2 = SmrGame::getGame($gameID, true); |
59
|
|
|
|
60
|
|
|
// Test that the properties have all propagated correctly |
61
|
|
|
self::assertSame('Test Game', $game2->getName()); |
62
|
|
|
self::assertSame('A test game.', $game2->getDescription()); |
63
|
|
|
self::assertSame(123, $game2->getStartTime()); |
64
|
|
|
self::assertSame(234, $game2->getJoinTime()); |
65
|
|
|
self::assertSame(345, $game2->getEndTime()); |
66
|
|
|
self::assertSame(5, $game2->getMaxPlayers()); |
67
|
|
|
self::assertSame(1000, $game2->getMaxTurns()); |
68
|
|
|
self::assertSame(24, $game2->getStartTurnHours()); |
69
|
|
|
self::assertSame('Draft', $game2->getGameType()); |
70
|
|
|
self::assertSame(10, $game2->getCreditsNeeded()); |
71
|
|
|
self::assertSame(1.5, $game2->getGameSpeed()); |
72
|
|
|
self::assertTrue($game2->isEnabled()); |
73
|
|
|
self::assertTrue($game2->isIgnoreStats()); |
74
|
|
|
self::assertSame(15, $game2->getAllianceMaxPlayers()); |
75
|
|
|
self::assertSame(10, $game2->getAllianceMaxVets()); |
76
|
|
|
self::assertSame(3000, $game2->getStartingCredits()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function test_setStartingRelations(): void { |
80
|
|
|
// Set the starting relations |
81
|
|
|
$game = SmrGame::createGame(1); |
82
|
|
|
$game->setStartingRelations(-123); |
83
|
|
|
|
84
|
|
|
// Verify that relations have been set properly |
85
|
|
|
foreach (Race::getAllIDs() as $raceID1) { |
86
|
|
|
$relations = Globals::getRaceRelations(1, $raceID1); |
87
|
|
|
foreach (Race::getAllIDs() as $raceID2) { |
88
|
|
|
$expected = -123; |
89
|
|
|
if ($raceID1 == $raceID2) { |
90
|
|
|
$expected = MAX_GLOBAL_RELATIONS; |
91
|
|
|
} elseif ($raceID1 == RACE_NEUTRAL || $raceID2 == RACE_NEUTRAL) { |
92
|
|
|
$expected = 0; |
93
|
|
|
} |
94
|
|
|
self::assertSame($expected, $relations[$raceID2]); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function test_isGameType(): void { |
100
|
|
|
$game = SmrGame::createGame(1); |
101
|
|
|
$game->setGameTypeID(SmrGame::GAME_TYPE_NEWBIE); |
102
|
|
|
self::assertTrue($game->isGameType(SmrGame::GAME_TYPE_NEWBIE)); |
103
|
|
|
self::assertFalse($game->isGameType(SmrGame::GAME_TYPE_DEFAULT)); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
} |
107
|
|
|
|