We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 1 |
Paths | 1 |
Total Lines | 54 |
Code Lines | 32 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types=1); |
||
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 | } |
||
78 |