Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Pull Request — master (#1014)
by Dan
04:44
created

SmrPlanetIntegrationTest::test_stockpile()   B

Complexity

Conditions 6
Paths 18

Size

Total Lines 45
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 30
c 1
b 0
f 0
nc 18
nop 0
dl 0
loc 45
rs 8.8177
1
<?php declare(strict_types=1);
2
3
namespace SmrTest\lib\DefaultGame;
4
5
use SmrPlanet;
6
use SmrTest\BaseIntegrationSpec;
7
8
/**
9
 * Class SmrPlanetIntegrationTest
10
 * @covers SmrPlanet
11
 */
12
class SmrPlanetIntegrationTest extends BaseIntegrationSpec {
13
14
	protected function tearDown() : void {
15
		SmrPlanet::clearCache();
16
		parent::tearDown();
17
	}
18
19
	public function test_createPlanet() : void {
20
		// Test arbitrary input
21
		$sectorID = 2;
22
		$gameID = 42;
23
		$typeID = 3;
24
		$inhabitableTime = 5;
25
26
		$planet = SmrPlanet::createPlanet($gameID, $sectorID, $typeID, $inhabitableTime);
27
		$this->assertTrue($planet->exists());
28
29
		// Check properties set explicitly
30
		$this->assertSame($planet->getGameID(), $gameID);
31
		$this->assertSame($planet->getSectorID(), $sectorID);
32
		$this->assertSame($planet->getTypeID(), $typeID);
33
		$this->assertSame($planet->getInhabitableTime(), $inhabitableTime);
34
	}
35
36
	public function test_createPlanet_already_exists() : void {
37
		$this->expectException(\Exception::class);
38
		$this->expectExceptionMessage('Planet already exists');
39
		SmrPlanet::createPlanet(1, 1, 1, 1);
40
		SmrPlanet::createPlanet(1, 1, 1, 1);
41
	}
42
43
	public function test_removePlanet() : void {
44
		// Check that planet exists
45
		$planet = SmrPlanet::createPlanet(1, 1, 1, 1);
46
		$this->assertTrue($planet->exists());
47
48
		SmrPlanet::removePlanet(1, 1);
49
		$planet = SmrPlanet::getPlanet(1, 1, true);
50
		$this->assertFalse($planet->exists());
51
	}
52
53
	public function test_name() : void {
54
		$planet = SmrPlanet::createPlanet(1, 1, 1, 1);
55
		// Check default name
56
		$this->assertSame($planet->getDisplayName(), 'Unknown');
57
58
		// Set a new name (include non-HTML-safe character)
59
		$planet->setName('Test&');
60
		$this->assertSame($planet->getDisplayName(), 'Test&amp;');
61
	}
62
63
	public function test_owner() : void {
64
		// Check default owner
65
		$planet = SmrPlanet::createPlanet(1, 1, 1, 1);
66
		$this->assertFalse($planet->hasOwner());
67
		$this->assertSame($planet->getOwnerID(), 0);
68
69
		// Set a new owner
70
		$ownerID = 3;
71
		$planet->setOwnerID($ownerID);
72
		$this->assertTrue($planet->hasOwner());
73
		$this->assertSame($planet->getOwnerID(), $ownerID);
74
75
		// Remove the owner again
76
		$planet->removeOwner();
77
		$this->assertFalse($planet->hasOwner());
78
		$this->assertSame($planet->getOwnerID(), 0);
79
	}
80
81
	public function test_password() : void {
82
		// Check default password
83
		$planet = SmrPlanet::createPlanet(1, 1, 1, 1);
84
		$this->assertSame($planet->getPassword(), '');
85
86
		// Set a new password
87
		$password = 'test';
88
		$planet->setPassword($password);
89
		$this->assertSame($planet->getPassword(), $password);
90
91
		// Remove the password again
92
		$planet->removePassword();
93
		$this->assertSame($planet->getPassword(), '');
94
	}
95
96
	public function test_credits() : void {
97
		// Check default credits
98
		$planet = SmrPlanet::createPlanet(1, 1, 1, 1);
99
		$this->assertSame($planet->getCredits(), 0);
100
101
		// Check increase/decrease credits
102
		$planet->increaseCredits(100);
103
		$this->assertSame($planet->getCredits(), 100);
104
		$planet->increaseCredits(50);
105
		$this->assertSame($planet->getCredits(), 150);
106
		$planet->decreaseCredits(50);
107
		$this->assertSame($planet->getCredits(), 100);
108
	}
109
110
	public function test_bonds() : void {
111
		// Check default bond
112
		$planet = SmrPlanet::createPlanet(1, 1, 1, 1);
113
		$this->assertSame($planet->getBonds(), 0);
114
115
		// Check increase/decrease bonds
116
		$planet->increaseBonds(100);
117
		$this->assertSame($planet->getBonds(), 100);
118
		$planet->increaseBonds(50);
119
		$this->assertSame($planet->getBonds(), 150);
120
		$planet->decreaseBonds(50);
121
		$this->assertSame($planet->getBonds(), 100);
122
	}
123
124
	public function test_bond_maturity() : void {
125
		// Check default maturity
126
		$planet = SmrPlanet::createPlanet(1, 1, 1, 1);
127
		$this->assertSame($planet->getMaturity(), 0);
128
129
		// Set a new bond maturity
130
		$maturity = time();
131
		$planet->setMaturity($maturity);
132
		$this->assertSame($planet->getMaturity(), $maturity);
133
	}
134
135
	public function test_stockpile() : void {
136
		// Check default stockpile
137
		$planet = SmrPlanet::createPlanet(1, 1, 1, 1);
138
		$this->assertFalse($planet->hasStockpile());
139
		$this->assertSame($planet->getStockpile(), []);
140
		foreach (array_keys(\Globals::getGoods()) as $goodID) {
141
			$this->assertFalse($planet->hasStockpile($goodID));
142
			$this->assertSame($planet->getStockpile($goodID), 0);
143
		}
144
145
		// Setting 0 still counts as empty
146
		$planet->setStockpile(GOODS_ORE, 0);
147
		$this->assertFalse($planet->hasStockpile());
148
		$this->assertFalse($planet->hasStockpile(GOODS_ORE));
149
150
		// Check increase stockpile
151
		$planet->increaseStockpile(GOODS_ORE, 50);
152
		$this->assertTrue($planet->hasStockpile());
153
		$this->assertSame($planet->getStockpile(), [GOODS_ORE => 50]);
154
		foreach (array_keys(\Globals::getGoods()) as $goodID) {
155
			if ($goodID === GOODS_ORE) {
156
				$this->assertTrue($planet->hasStockpile($goodID));
157
				$this->assertSame($planet->getStockpile($goodID), 50);
158
			} else {
159
				$this->assertFalse($planet->hasStockpile($goodID));
160
				$this->assertSame($planet->getStockpile($goodID), 0);
161
			}
162
		}
163
164
		// Check decrease stockpile
165
		$planet->decreaseStockpile(GOODS_ORE, 10);
166
		$this->assertTrue($planet->hasStockpile());
167
		$this->assertSame($planet->getStockpile(), [GOODS_ORE => 40]);
168
		foreach (array_keys(\Globals::getGoods()) as $goodID) {
169
			if ($goodID === GOODS_ORE) {
170
				$this->assertTrue($planet->hasStockpile($goodID));
171
				$this->assertSame($planet->getStockpile($goodID), 40);
172
			} else {
173
				$this->assertFalse($planet->hasStockpile($goodID));
174
				$this->assertSame($planet->getStockpile($goodID), 0);
175
			}
176
		}
177
178
		// Check remaining stockpile (ore: 600 - 40)
179
		$this->assertSame($planet->getRemainingStockpile(GOODS_ORE), 560);
180
	}
181
182
}
183