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
Pull Request — master (#1034)
by Dan
04:50
created

icroTime_equality()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace SmrTest\lib\DefaultGame;
4
5
use SmrSession;
6
use SmrTest\BaseIntegrationSpec;
7
8
/**
9
 * @covers SmrSession
10
 */
11
class SmrSessionIntegrationTest extends BaseIntegrationSpec {
12
13
	private SmrSession $session;
14
15
	protected function setUp() : void {
16
		// Start each test with a fresh container (and SmrSession).
17
		// This ensures the independence of each test.
18
		\Smr\Container\DiContainer::initializeContainer();
19
		$this->session = SmrSession::getInstance();
20
	}
21
22
	/**
23
	 * Test that the updateTime function works properly when NPC_SCRIPT is set.
24
	 * We run in a separate process so that the constant doesn't propagate into
25
	 * other tests.
26
	 * @runInSeparateProcess
27
	 */
28
	public function test_updateTime_cli() {
29
		// Set the NPC_SCRIPT variable as if this were a CLI program
30
		define('NPC_SCRIPT', true);
31
32
		$time = $this->session->time();
33
		$microtime = $this->session->microtime();
34
35
		// Sleep 1 second to ensure that the integer time has incremented
36
		sleep(1);
37
		$this->session->updateTime();
38
39
		// Make sure the times have changed
40
		self::assertNotEquals($time, $this->session->time());
41
		self::assertNotEquals($microtime, $this->session->microtime());
42
	}
43
44
	/**
45
	 * updateTime should throw if called without NPC_SCRIPT defined.
46
	 */
47
	public function test_updateTime() {
48
		self::expectException(\Exception::class);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

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

48
		self::/** @scrutinizer ignore-call */ 
49
        expectException(\Exception::class);
Loading history...
49
		self::expectExceptionMessage('Only call this function from CLI programs');
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCa...xpectExceptionMessage() is not static, but was called statically. ( Ignorable by Annotation )

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

49
		self::/** @scrutinizer ignore-call */ 
50
        expectExceptionMessage('Only call this function from CLI programs');
Loading history...
50
		$this->session->updateTime();
51
	}
52
53
	/**
54
	 * We can't check the time/microtime values, but we can ensure that
55
	 * the rounded values are identical.
56
	 */
57
	public function test_time_microtime_equality() {
58
		self::assertEquals($this->session->time(), floor($this->session->microtime()));
59
	}
60
61
	public function test_game() {
62
		// Sessions are initialized with no game
63
		self::assertFalse($this->session->hasGame());
64
		self::assertSame(0, $this->session->getGameID());
65
66
		// Now update the game
67
		$gameID = 3;
68
		$this->session->updateGame($gameID);
69
		self::assertTrue($this->session->hasGame());
70
		self::assertSame($gameID, $this->session->getGameID());
71
	}
72
73
	public function test_account() {
74
		// Sessions are initialized with no account
75
		self::assertFalse($this->session->hasAccount());
76
		self::assertSame(0, $this->session->getAccountID());
77
78
		// Now update the account
79
		$account = $this->createMock(\AbstractSmrAccount::class);
80
		$account
81
			->method('getAccountID')
82
			->willReturn(7);
83
		$this->session->setAccount($account);
84
		self::assertTrue($this->session->hasAccount());
85
		self::assertSame(7, $this->session->getAccountID());
86
	}
87
88
89
}
90