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

Failed Conditions
Pull Request — master (#1018)
by Dan
04:32
created

SmrShipIntegrationTest::test_updateCloak()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 21
rs 9.8666
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace SmrTest\lib\DefaultGame;
4
5
use SmrShip;
6
use AbstractSmrPlayer;
7
use SmrWeapon;
8
use SmrTest\BaseIntegrationSpec;
9
10
/**
11
 * @covers SmrShip
12
 */
13
class SmrShipIntegrationTest extends BaseIntegrationSpec {
14
15
	private $player;
16
17
	protected function setUp() : void {
18
		// Start each test with an empty ship cache
19
		SmrShip::clearCache();
20
21
		// Create mock player that will be needed to create any ship
22
		$this->player = $this->createMock(AbstractSmrPlayer::class);
23
		$this->player
24
			->method('getAccountID')
25
			->willReturn(7);
26
		$this->player
27
			->method('getGameID')
28
			->willReturn(3);
29
		// Use Demonica because it's the only ship with all special hardware
30
		$this->player
31
			->method('getShipTypeID')
32
			->willReturn(SHIP_TYPE_DEMONICA);
33
	}
34
35
36
	public function test_getShip() {
37
		// Get the ship associated with this player
38
		$original = SmrShip::getShip($this->player);
39
		self::assertSame($this->player->getAccountID(), $original->getAccountID());
40
		self::assertSame($this->player->getGameID(), $original->getGameID());
41
		self::assertSame($this->player->getShipTypeID(), $original->getShipTypeID());
42
43
		// Check that we get the exact same object if we get it again
44
		$forceUpdate = false;
45
		$ship = SmrShip::getShip($this->player, $forceUpdate);
46
		self::assertSame($original, $ship);
47
48
		// Check that we get a different object if we force update
49
		$forceUpdate = true;
50
		$ship = SmrShip::getShip($this->player, $forceUpdate);
51
		self::assertNotSame($original, $ship);
52
		// but it is still the same ship
53
		self::assertEquals($original, $ship);
54
	}
55
56
57
	public function test_updateHardware() {
58
		$original = SmrShip::getShip($this->player);
59
60
		// Add hardware
61
		$original->setHardwareToMax();
62
		$original->update();
63
64
		// Check that the reloaded ship is equal to the original
65
		$ship = SmrShip::getShip($this->player, true);
66
		self::assertNotSame($original, $ship);
67
		self::assertEquals($original, $ship);
68
69
		// Change some hardware
70
		$original->decreaseShields(10);
71
		$original->decreaseCDs(10);
72
		$original->update();
73
74
		// Check that the reloaded ship is equal to the original
75
		$ship = SmrShip::getShip($this->player, true);
76
		self::assertNotSame($original, $ship);
77
		self::assertEquals($original, $ship);
78
79
		// Remove hardware
80
		$original->removeAllHardware();
81
		$original->update();
82
83
		// Check that the reloaded ship is equal to the original
84
		$ship = SmrShip::getShip($this->player, true);
85
		self::assertNotSame($original, $ship);
86
		self::assertEquals($original, $ship);
87
	}
88
89
90
	public function test_updateWeapons() {
91
		$original = SmrShip::getShip($this->player);
92
93
		// Add a couple weapons
94
		$original->addWeapon(SmrWeapon::getWeapon(WEAPON_TYPE_LASER));
95
		$original->addWeapon(SmrWeapon::getWeapon(WEAPON_PORT_TURRET));
96
		$original->addWeapon(SmrWeapon::getWeapon(WEAPON_TYPE_LASER));
97
		$original->update();
98
99
		// Check that the reloaded ship is equal to the original
100
		$ship = SmrShip::getShip($this->player, true);
101
		self::assertNotSame($original, $ship);
102
		self::assertEquals($original, $ship);
103
104
		// Remove a weapon
105
		$original->removeWeapon(1);
106
		$original->update();
107
108
		// Check that the reloaded ship is equal to the original
109
		$ship = SmrShip::getShip($this->player, true);
110
		self::assertNotSame($original, $ship);
111
		self::assertEquals($original, $ship);
112
113
		// Remove all weapons
114
		$original->removeAllWeapons();
115
		$original->update();
116
117
		// Check that the reloaded ship is equal to the original
118
		$ship = SmrShip::getShip($this->player, true);
119
		self::assertNotSame($original, $ship);
120
		self::assertEquals($original, $ship);
121
	}
122
123
124
	public function test_updateCargo() {
125
		$original = SmrShip::getShip($this->player);
126
		$original->setHardwareToMax();
127
128
		// Add some cargo
129
		$original->increaseCargo(GOODS_ORE, 15);
130
		$original->increaseCargo(GOODS_WOOD, 5);
131
		$original->increaseCargo(GOODS_FOOD, 10);
132
		$original->update();
133
134
		// Check that the reloaded ship is equal to the original
135
		$ship = SmrShip::getShip($this->player, true);
136
		self::assertNotSame($original, $ship);
137
		self::assertEquals($original, $ship);
138
139
		// Modify existing cargo
140
		$original->decreaseCargo(GOODS_ORE, 5); // decrease
141
		$original->decreaseCargo(GOODS_WOOD, 5); // remove all
142
		$original->update();
143
144
		// Check that the reloaded ship is equal to the original
145
		$ship = SmrShip::getShip($this->player, true);
146
		self::assertNotSame($original, $ship);
147
		self::assertEquals($original, $ship);
148
149
		// Remove all cargo
150
		$original->removeAllCargo();
151
		$original->update();
152
153
		// Check that the reloaded ship is equal to the original
154
		$ship = SmrShip::getShip($this->player, true);
155
		self::assertNotSame($original, $ship);
156
		self::assertEquals($original, $ship);
157
	}
158
159
160
	public function test_updateCloak() {
161
		$original = SmrShip::getShip($this->player);
162
		$original->setHardwareToMax();
163
164
		// Enable cloak
165
		$original->enableCloak();
166
		$original->update();
167
168
		// Check that the reloaded ship is equal to the original
169
		$ship = SmrShip::getShip($this->player, true);
170
		self::assertNotSame($original, $ship);
171
		self::assertEquals($original, $ship);
172
173
		// Disable cloak
174
		$original->decloak();
175
		$original->update();
176
177
		// Check that the reloaded ship is equal to the original
178
		$ship = SmrShip::getShip($this->player, true);
179
		self::assertNotSame($original, $ship);
180
		self::assertEquals($original, $ship);
181
	}
182
183
184
	public function test_updateIllusion() {
185
		$original = SmrShip::getShip($this->player);
186
		$original->setHardwareToMax();
187
188
		// Enable illusion
189
		$original->setIllusion(SHIP_TYPE_DRUDGE, 2, 3);
190
		$original->update();
191
192
		// Check that the reloaded ship is equal to the original
193
		$ship = SmrShip::getShip($this->player, true);
194
		self::assertNotSame($original, $ship);
195
		self::assertEquals($original, $ship);
196
197
		// Change illusion
198
		$original->setIllusion(SHIP_TYPE_ROGUE, 5, 1);
199
		$original->update();
200
201
		// Check that the reloaded ship is equal to the original
202
		$ship = SmrShip::getShip($this->player, true);
203
		self::assertNotSame($original, $ship);
204
		self::assertEquals($original, $ship);
205
206
		// Disable illusion
207
		$original->disableIllusion();
208
		$original->update();
209
210
		// Check that the reloaded ship is equal to the original
211
		$ship = SmrShip::getShip($this->player, true);
212
		self::assertNotSame($original, $ship);
213
		self::assertEquals($original, $ship);
214
	}
215
216
}
217