|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace SmrTest\lib\DefaultGame; |
|
4
|
|
|
|
|
5
|
|
|
use ReflectionClassConstant; |
|
6
|
|
|
use Smr\Container\DiContainer; |
|
7
|
|
|
use Smr\Epoch; |
|
8
|
|
|
use SmrEnhancedWeaponEvent; |
|
9
|
|
|
use SmrLocation; |
|
10
|
|
|
use SmrTest\BaseIntegrationSpec; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @covers SmrEnhancedWeaponEvent |
|
14
|
|
|
*/ |
|
15
|
|
|
class SmrEnhancedWeaponEventTest extends BaseIntegrationSpec { |
|
16
|
|
|
|
|
17
|
|
|
protected function tablesToTruncate(): array { |
|
18
|
|
|
return ['location_sells_special', 'location']; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function test_integration(): void { |
|
22
|
|
|
// Get protected constant from class for more robust validation |
|
23
|
|
|
$prop = new ReflectionClassConstant(SmrEnhancedWeaponEvent::class, 'DURATION'); |
|
24
|
|
|
$buffer = $prop->getValue(); |
|
25
|
|
|
|
|
26
|
|
|
$gameID = 1; |
|
27
|
|
|
$sectorID = 2; |
|
28
|
|
|
$locTypePPL = 325; // Pulse of the Universe |
|
29
|
|
|
|
|
30
|
|
|
// We need to insert at least one location into the database, since |
|
31
|
|
|
// the class doesn't have a very modular design. |
|
32
|
|
|
$location = $this->createPartialMock(SmrLocation::class, ['getTypeID']); |
|
33
|
|
|
$location->method('getTypeID')->willReturn($locTypePPL); |
|
34
|
|
|
SmrLocation::addSectorLocation($gameID, $sectorID, $location); |
|
35
|
|
|
|
|
36
|
|
|
// Set an initial t=0 |
|
37
|
|
|
$epoch = $this->createPartialMock(Epoch::class, ['getTime']); |
|
38
|
|
|
$epoch->method('getTime')->willReturn(0); |
|
39
|
|
|
DiContainer::getContainer()->set(Epoch::class, $epoch); |
|
40
|
|
|
|
|
41
|
|
|
// Create a random event (seed for reproducibility) |
|
42
|
|
|
srand(1); |
|
43
|
|
|
$event = SmrEnhancedWeaponEvent::getLatestEvent($gameID); |
|
44
|
|
|
self::assertSame($sectorID, $event->getSectorID()); |
|
45
|
|
|
self::assertSame($buffer, $event->getExpireTime()); |
|
46
|
|
|
self::assertSame(100.0, $event->getDurationRemainingPercent()); |
|
47
|
|
|
|
|
48
|
|
|
// There is only one weapon it could have selected (PPL) |
|
49
|
|
|
$weapon = $event->getWeapon(); |
|
50
|
|
|
self::assertSame(WEAPON_TYPE_PLANETARY_PULSE_LASER, $weapon->getWeaponTypeID()); |
|
51
|
|
|
self::assertTrue($weapon->hasBonusDamage()); |
|
52
|
|
|
self::assertFalse($weapon->hasBonusAccuracy()); |
|
53
|
|
|
|
|
54
|
|
|
// If we try to create this event again, we get the same one back |
|
55
|
|
|
self::assertEquals($event, SmrEnhancedWeaponEvent::getLatestEvent($gameID)); |
|
56
|
|
|
|
|
57
|
|
|
// Make sure we can get this event from the weapon shop |
|
58
|
|
|
$events = SmrEnhancedWeaponEvent::getShopEvents($gameID, $sectorID, $locTypePPL); |
|
59
|
|
|
self::assertEquals([$event], $events); |
|
60
|
|
|
|
|
61
|
|
|
// Advance to the very latest time that this event is valid |
|
62
|
|
|
$epoch = $this->createPartialMock(Epoch::class, ['getTime']); |
|
63
|
|
|
$epoch->method('getTime')->willReturn($buffer); |
|
64
|
|
|
DiContainer::getContainer()->set(Epoch::class, $epoch); |
|
65
|
|
|
self::assertSame(0.0, $event->getDurationRemainingPercent()); |
|
66
|
|
|
|
|
67
|
|
|
// We should be able to create a 2nd event now, but since there is only |
|
68
|
|
|
// one valid configuration in this test, it just replaces it (simulating |
|
69
|
|
|
// the unlikely chance of selecting the same configuration). |
|
70
|
|
|
$event2 = SmrEnhancedWeaponEvent::getLatestEvent($gameID); |
|
71
|
|
|
self::assertNotEquals($event2, $event); |
|
72
|
|
|
self::assertSame(2 * $buffer, $event2->getExpireTime()); |
|
73
|
|
|
$events2 = SmrEnhancedWeaponEvent::getShopEvents($gameID, $sectorID, $locTypePPL); |
|
74
|
|
|
self::assertEquals([$event2], $events2); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|