1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace SmrTest\lib\DefaultGame; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use Smr\PlayerLevel; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @covers Smr\PlayerLevel |
11
|
|
|
*/ |
12
|
|
|
class PlayerLevelTest extends TestCase { |
13
|
|
|
|
14
|
|
|
public static function setUpBeforeClass(): void { |
15
|
|
|
// Make sure cache is clear so we can cover the cache population code |
16
|
|
|
PlayerLevel::clearCache(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function test_get(): void { |
20
|
|
|
// Test that we calculate level from exp properly |
21
|
|
|
$exp = 49240; |
22
|
|
|
$level = PlayerLevel::get($exp); |
23
|
|
|
$expected = new PlayerLevel(22, 'Lieutenant 2nd Class', 44765); |
24
|
|
|
self::assertEquals($expected, $level); |
25
|
|
|
self::assertGreaterThanOrEqual($level->expRequired, $exp); // B >= A |
26
|
|
|
|
27
|
|
|
// Make sure the next level has more exp |
28
|
|
|
self::assertLessThan($level->next()->expRequired, $exp); // B < A |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function test_get_invalid_exp(): void { |
32
|
|
|
// If we pass an invalid amount of exp, we throw |
33
|
|
|
$this->expectException(Exception::class); |
34
|
|
|
$this->expectExceptionMessage('Failed to properly determine level from exp: -1'); |
35
|
|
|
PlayerLevel::get(-1); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function test_getMax(): void { |
39
|
|
|
self::assertSame(50, PlayerLevel::getMax()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @testWith [1, 2] |
44
|
|
|
* [49, 50] |
45
|
|
|
* [50, 50] |
46
|
|
|
*/ |
47
|
|
|
public function test_next(int $levelID, int $nextLevelID): void { |
48
|
|
|
$level = new PlayerLevel($levelID, '', 0); |
49
|
|
|
self::assertSame($nextLevelID, $level->next()->id); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
} |
53
|
|
|
|