1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace SmrTest\lib\DefaultGame; |
4
|
|
|
|
5
|
|
|
use SmrShip; |
6
|
|
|
use AbstractSmrPlayer; |
7
|
|
|
use SmrTest\BaseIntegrationSpec; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers SmrShip |
11
|
|
|
*/ |
12
|
|
|
class SmrShipIntegrationTest extends BaseIntegrationSpec { |
13
|
|
|
|
14
|
|
|
private $player; |
15
|
|
|
|
16
|
|
|
protected function setUp() : void { |
17
|
|
|
// Start each test with an empty ship cache |
18
|
|
|
SmrShip::clearCache(); |
19
|
|
|
|
20
|
|
|
// Create mock player that will be needed to create any ship |
21
|
|
|
$this->player = $this->createMock(AbstractSmrPlayer::class); |
22
|
|
|
$this->player |
23
|
|
|
->method('getAccountID') |
24
|
|
|
->willReturn(7); |
25
|
|
|
$this->player |
26
|
|
|
->method('getGameID') |
27
|
|
|
->willReturn(3); |
28
|
|
|
// Use Demonica because it's the only ship with all special hardware |
29
|
|
|
$this->player |
30
|
|
|
->method('getShipTypeID') |
31
|
|
|
->willReturn(SHIP_TYPE_DEMONICA); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function test_getShip() { |
35
|
|
|
// Get the ship associated with this player |
36
|
|
|
$original = SmrShip::getShip($this->player); |
37
|
|
|
self::assertSame($this->player->getAccountID(), $original->getAccountID()); |
38
|
|
|
self::assertSame($this->player->getGameID(), $original->getGameID()); |
39
|
|
|
self::assertSame($this->player->getShipTypeID(), $original->getShipTypeID()); |
40
|
|
|
|
41
|
|
|
// Check that we get the exact same object if we get it again |
42
|
|
|
$forceUpdate = false; |
43
|
|
|
$ship = SmrShip::getShip($this->player, $forceUpdate); |
44
|
|
|
self::assertSame($original, $ship); |
45
|
|
|
|
46
|
|
|
// Check that we get a different object if we force update |
47
|
|
|
$forceUpdate = true; |
48
|
|
|
$ship = SmrShip::getShip($this->player, $forceUpdate); |
49
|
|
|
self::assertNotSame($original, $ship); |
50
|
|
|
// but it is still the same ship |
51
|
|
|
self::assertSame($original->getGameID(), $ship->getGameID()); |
52
|
|
|
self::assertSame($original->getAccountID(), $ship->getAccountID()); |
53
|
|
|
self::assertSame($original->getShipTypeID(), $ship->getShipTypeID()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function test_cloak() { |
57
|
|
|
$ship = SmrShip::getShip($this->player); |
58
|
|
|
|
59
|
|
|
// ships are initially uncloaked |
60
|
|
|
self::assertFalse($ship->isCloaked()); |
61
|
|
|
|
62
|
|
|
// remain uncloaked when enabled without hardware |
63
|
|
|
// (note that this doesn't check hardware...) |
64
|
|
|
$ship->enableCloak(); |
65
|
|
|
self::assertFalse($ship->isCloaked()); |
66
|
|
|
// remain uncloaked when disabled without hardware |
67
|
|
|
$ship->decloak(); |
68
|
|
|
self::assertFalse($ship->isCloaked()); |
69
|
|
|
|
70
|
|
|
// add cloak hardware |
71
|
|
|
$ship->increaseHardware(HARDWARE_CLOAK, 1); |
72
|
|
|
self::assertFalse($ship->isCloaked()); |
73
|
|
|
// enable |
74
|
|
|
$ship->enableCloak(); |
75
|
|
|
self::assertTrue($ship->isCloaked()); |
76
|
|
|
// disable |
77
|
|
|
$ship->decloak(); |
78
|
|
|
self::assertFalse($ship->isCloaked()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function test_illusion_generator() { |
82
|
|
|
$ship = SmrShip::getShip($this->player); |
83
|
|
|
|
84
|
|
|
// ship has no IG initially |
85
|
|
|
self::assertFalse($ship->getIllusionShip()); |
86
|
|
|
|
87
|
|
|
// still no illusion when set without hardware |
88
|
|
|
// (note that this doesn't check hardware...) |
89
|
|
|
$ship->setIllusion(SHIP_TYPE_THIEF, 12, 13); |
90
|
|
|
self::assertFalse($ship->getIllusionShip()); |
91
|
|
|
// remain unset when disabled without hardware |
92
|
|
|
$ship->disableIllusion(); |
93
|
|
|
self::assertFalse($ship->getIllusionShip()); |
94
|
|
|
|
95
|
|
|
// add IG hardware |
96
|
|
|
$ship->increaseHardware(HARDWARE_ILLUSION, 1); |
97
|
|
|
self::assertFalse($ship->getIllusionShip()); |
98
|
|
|
// enable |
99
|
|
|
$ship->setIllusion(SHIP_TYPE_THIEF, 12, 13); |
100
|
|
|
$expected = [ |
101
|
|
|
'ID' => SHIP_TYPE_THIEF, |
102
|
|
|
'Attack' => 12, |
103
|
|
|
'Defense' => 13, |
104
|
|
|
'Name' => 'Thief', |
105
|
|
|
]; |
106
|
|
|
self::assertSame($expected, $ship->getIllusionShip()); |
107
|
|
|
// disable |
108
|
|
|
$ship->disableIllusion(); |
109
|
|
|
self::assertFalse($ship->getIllusionShip()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|