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
Push — live ( 5fc72e...903a76 )
by Dan
07:31 queued 02:29
created

SmrShipIntegrationTest::tablesToTruncate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace SmrTest\lib\DefaultGame;
4
5
use AbstractSmrPlayer;
6
use SmrShip;
7
use SmrTest\BaseIntegrationSpec;
8
use SmrWeapon;
9
10
/**
11
 * @covers SmrShip
12
 */
13
class SmrShipIntegrationTest extends BaseIntegrationSpec {
14
15
	private AbstractSmrPlayer $player; // will be mocked
16
17
	protected function tablesToTruncate(): array {
18
		return ['ship_has_hardware'];
19
	}
20
21
	protected function setUp(): void {
22
		// Start each test with an empty ship cache
23
		SmrShip::clearCache();
24
25
		// Create mock player that will be needed to create any ship
26
		$this->player = $this->createMock(AbstractSmrPlayer::class);
27
		$this->player
28
			->method('getAccountID')
0 ignored issues
show
Bug introduced by
The method method() does not exist on AbstractSmrPlayer. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
			->/** @scrutinizer ignore-call */ 
29
     method('getAccountID')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
			->willReturn(7);
30
		$this->player
31
			->method('getGameID')
32
			->willReturn(3);
33
		// Use Demonica because it's the only ship with all special hardware
34
		$this->player
35
			->method('getShipTypeID')
36
			->willReturn(SHIP_TYPE_DEMONICA);
37
	}
38
39
40
	public function test_getShip(): void {
41
		// Get the ship associated with this player
42
		$original = SmrShip::getShip($this->player);
43
		self::assertSame($this->player->getAccountID(), $original->getAccountID());
44
		self::assertSame($this->player->getGameID(), $original->getGameID());
45
		self::assertSame($this->player->getShipTypeID(), $original->getTypeID());
46
47
		// Check that we get the exact same object if we get it again
48
		$forceUpdate = false;
49
		$ship = SmrShip::getShip($this->player, $forceUpdate);
50
		self::assertSame($original, $ship);
51
52
		// Check that we get a different object if we force update
53
		$forceUpdate = true;
54
		$ship = SmrShip::getShip($this->player, $forceUpdate);
55
		self::assertNotSame($original, $ship);
56
		// but it is still the same ship
57
		self::assertEquals($original, $ship);
58
	}
59
60
61
	public function test_updateHardware(): void {
62
		$original = SmrShip::getShip($this->player);
63
64
		// Add hardware
65
		$original->setHardwareToMax();
66
		$original->update();
67
68
		// Check that the reloaded ship is equal to the original
69
		$ship = SmrShip::getShip($this->player, true);
70
		self::assertNotSame($original, $ship);
71
		self::assertEquals($original, $ship);
72
73
		// Change some hardware
74
		$original->decreaseShields(10);
75
		$original->decreaseCDs(10);
76
		$original->update();
77
78
		// Check that the reloaded ship is equal to the original
79
		$ship = SmrShip::getShip($this->player, true);
80
		self::assertNotSame($original, $ship);
81
		self::assertEquals($original, $ship);
82
83
		// Remove hardware
84
		$original->removeAllHardware();
85
		$original->update();
86
87
		// Check that the reloaded ship is equal to the original
88
		$ship = SmrShip::getShip($this->player, true);
89
		self::assertNotSame($original, $ship);
90
		self::assertEquals($original, $ship);
91
	}
92
93
94
	public function test_updateWeapons(): void {
95
		$original = SmrShip::getShip($this->player);
96
97
		// Add a couple weapons
98
		$original->addWeapon(SmrWeapon::getWeapon(WEAPON_TYPE_LASER));
99
		$original->addWeapon(SmrWeapon::getWeapon(WEAPON_PORT_TURRET));
100
		$original->addWeapon(SmrWeapon::getWeapon(WEAPON_TYPE_LASER));
101
		$original->update();
102
103
		// Check that the reloaded ship is equal to the original
104
		$ship = SmrShip::getShip($this->player, true);
105
		self::assertNotSame($original, $ship);
106
		self::assertEquals($original, $ship);
107
108
		// Remove a weapon
109
		$original->removeWeapon(1);
110
		$original->update();
111
112
		// Check that the reloaded ship is equal to the original
113
		$ship = SmrShip::getShip($this->player, true);
114
		self::assertNotSame($original, $ship);
115
		self::assertEquals($original, $ship);
116
117
		// Remove all weapons
118
		$original->removeAllWeapons();
119
		$original->update();
120
121
		// Check that the reloaded ship is equal to the original
122
		$ship = SmrShip::getShip($this->player, true);
123
		self::assertNotSame($original, $ship);
124
		self::assertEquals($original, $ship);
125
	}
126
127
128
	public function test_updateCargo(): void {
129
		$original = SmrShip::getShip($this->player);
130
		$original->setHardwareToMax();
131
132
		// Add some cargo
133
		$original->increaseCargo(GOODS_ORE, 15);
134
		$original->increaseCargo(GOODS_WOOD, 5);
135
		$original->increaseCargo(GOODS_FOOD, 10);
136
		$original->update();
137
138
		// Check that the reloaded ship is equal to the original
139
		$ship = SmrShip::getShip($this->player, true);
140
		self::assertNotSame($original, $ship);
141
		self::assertEquals($original, $ship);
142
143
		// Modify existing cargo
144
		$original->decreaseCargo(GOODS_ORE, 5); // decrease
145
		$original->decreaseCargo(GOODS_WOOD, 5); // remove all
146
		$original->update();
147
148
		// Check that the reloaded ship is equal to the original
149
		$ship = SmrShip::getShip($this->player, true);
150
		self::assertNotSame($original, $ship);
151
		self::assertEquals($original, $ship);
152
153
		// Remove all cargo
154
		$original->removeAllCargo();
155
		$original->update();
156
157
		// Check that the reloaded ship is equal to the original
158
		$ship = SmrShip::getShip($this->player, true);
159
		self::assertNotSame($original, $ship);
160
		self::assertEquals($original, $ship);
161
	}
162
163
164
	public function test_updateCloak(): void {
165
		$original = SmrShip::getShip($this->player);
166
		$original->setHardwareToMax();
167
168
		// Enable cloak
169
		$original->enableCloak();
170
		$original->update();
171
172
		// Check that the reloaded ship is equal to the original
173
		$ship = SmrShip::getShip($this->player, true);
174
		self::assertNotSame($original, $ship);
175
		self::assertEquals($original, $ship);
176
177
		// Disable cloak
178
		$original->decloak();
179
		$original->update();
180
181
		// Check that the reloaded ship is equal to the original
182
		$ship = SmrShip::getShip($this->player, true);
183
		self::assertNotSame($original, $ship);
184
		self::assertEquals($original, $ship);
185
	}
186
187
188
	public function test_updateIllusion(): void {
189
		$original = SmrShip::getShip($this->player);
190
		$original->setHardwareToMax();
191
192
		// Enable illusion
193
		$original->setIllusion(SHIP_TYPE_DRUDGE, 2, 3);
194
		$original->update();
195
196
		// Check that the reloaded ship is equal to the original
197
		$ship = SmrShip::getShip($this->player, true);
198
		self::assertNotSame($original, $ship);
199
		self::assertEquals($original, $ship);
200
201
		// Change illusion
202
		$original->setIllusion(SHIP_TYPE_ROGUE, 5, 1);
203
		$original->update();
204
205
		// Check that the reloaded ship is equal to the original
206
		$ship = SmrShip::getShip($this->player, true);
207
		self::assertNotSame($original, $ship);
208
		self::assertEquals($original, $ship);
209
210
		// Disable illusion
211
		$original->disableIllusion();
212
		$original->update();
213
214
		// Check that the reloaded ship is equal to the original
215
		$ship = SmrShip::getShip($this->player, true);
216
		self::assertNotSame($original, $ship);
217
		self::assertEquals($original, $ship);
218
	}
219
220
}
221