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

Passed
Pull Request — master (#951)
by Dan
08:27
created

MySqlDatabaseIntegrationTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace SmrTest\lib\DefaultGame;
4
5
use DI\Container;
6
use Error;
7
use Exception;
8
use MySqlDatabase;
9
use mysqli;
10
use PHPUnit\Framework\TestCase;
11
use Smr\Container\DiContainer;
12
13
/**
14
 * Class MySqlDatabaseIntegrationTest
15
 * This is an integration test, but does not need to extend BaseIntegrationTest since we are not writing any data.
16
 * @covers MySqlDatabase
17
 * @package SmrTest\lib\DefaultGame
18
 */
19
class MySqlDatabaseIntegrationTest extends TestCase {
20
	private Container $container;
21
22
	protected function setUp(): void {
23
		DiContainer::initializeContainer();
24
		$this->container = DiContainer::getContainer();
25
	}
26
27
	public function test_performing_operations_on_closed_database_throws_error() {
28
		// Expectations
29
		$this->expectException(Error::class);
30
		$this->expectExceptionMessage('Typed property MySqlDatabase::$dbConn must not be accessed before initialization');
31
		// Given a mysql database instance
32
		$mysqlDatabase = MySqlDatabase::getInstance();
33
		// And disconnect is called
34
		$mysqlDatabase->close();
35
		// When calling database methods
36
		$mysqlDatabase->query("foo query");
37
	}
38
39
	public function test_getInstance_will_perform_reconnect_after_connection_closed() {
40
		// Given an original mysql connection
41
		$originalMysql = $this->container->get(mysqli::class);
42
		// And a mysql database instance
43
		$mysqlDatabase = MySqlDatabase::getInstance();
44
		// And disconnect is called
45
		$mysqlDatabase->close();
46
		// And mysql database is retrieved from the container
47
		$mysqlDatabase = MySqlDatabase::getInstance();
48
		// When performing a query
49
		$mysqlDatabase->query("select 1");
50
		// Then new mysqli instance is not the same as the initial mock
51
		self::assertNotSame($originalMysql, $this->container->get(mysqli::class));
52
	}
53
54
	public function test_getInstance_will_not_perform_reconnect_if_connection_not_closed() {
55
		// Given an original mysql connection
56
		$originalMysql = $this->container->get(mysqli::class);
57
		// And a mysql database instance
58
		MySqlDatabase::getInstance();
59
		// And get instance is called again
60
		MySqlDatabase::getInstance();
61
		// Then the two mysqli instances are the same
62
		self::assertSame($originalMysql, $this->container->get(mysqli::class));
63
	}
64
}
65