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
Push — master ( c670fd...b18f1a )
by Dan
20s queued 16s
created

SessionIntegrationTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 32
dl 0
loc 66
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A test_account() 0 13 1
A test_current_var() 0 28 1
A setUp() 0 5 1
A test_game() 0 10 1
1
<?php declare(strict_types=1);
2
3
namespace SmrTest\lib\DefaultGame;
4
5
use Page;
6
use Smr\Session;
7
use SmrTest\BaseIntegrationSpec;
8
9
/**
10
 * @covers Smr\Session
11
 */
12
class SessionIntegrationTest extends BaseIntegrationSpec {
13
14
	private Session $session;
15
16
	protected function setUp() : void {
17
		// Start each test with a fresh container (and Smr\Session).
18
		// This ensures the independence of each test.
19
		\Smr\Container\DiContainer::initializeContainer();
20
		$this->session = Session::getInstance();
21
	}
22
23
	public function test_game() {
24
		// Sessions are initialized with no game
25
		self::assertFalse($this->session->hasGame());
26
		self::assertSame(0, $this->session->getGameID());
27
28
		// Now update the game
29
		$gameID = 3;
30
		$this->session->updateGame($gameID);
31
		self::assertTrue($this->session->hasGame());
32
		self::assertSame($gameID, $this->session->getGameID());
33
	}
34
35
	public function test_account() {
36
		// Sessions are initialized with no account
37
		self::assertFalse($this->session->hasAccount());
38
		self::assertSame(0, $this->session->getAccountID());
39
40
		// Now update the account
41
		$account = $this->createMock(\AbstractSmrAccount::class);
42
		$account
43
			->method('getAccountID')
44
			->willReturn(7);
45
		$this->session->setAccount($account);
46
		self::assertTrue($this->session->hasAccount());
47
		self::assertSame(7, $this->session->getAccountID());
48
	}
49
50
	public function test_current_var() {
51
		// With an empty session, there should be no current var
52
		self::assertFalse($this->session->findCurrentVar());
53
54
		// Add a page to the session so that we can find it later.
55
		// (This mimics Page::href but with better access to the SN.)
56
		$page = Page::create('some_page');
57
		$page['CommonID'] = 'abc';
58
		$page['RemainingPageLoads'] = 1;
59
		$sn = $this->session->addLink($page);
60
61
		// Now we should be able to find this sn in the var
62
		self::assertTrue($this->session->findCurrentVar($sn));
63
64
		// The current var should now be accessible
65
		$var = $this->session->getCurrentVar();
66
		self::assertSame('some_page', $var['url']);
67
68
		// The CommonID metadata should be stripped
69
		self::assertFalse(isset($var['CommonID']));
70
		// The RemainingPageLoads metadata should be incremented
71
		self::assertSame(2, $var['RemainingPageLoads']);
72
73
		// We can now change the current var
74
		$page2 = Page::create('another_page');
75
		$this->session->setCurrentVar($page2);
76
		// And $var should be updated automatically
77
		self::assertSame('another_page', $var['url']);
78
	}
79
80
}
81