-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.php
More file actions
48 lines (39 loc) · 984 Bytes
/
index.php
File metadata and controls
48 lines (39 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
/**
* DB connection constants
*
* Note: Don't hard code these values IRL. Use environmental variables
*/
const DB_HOST = 'database';
const DB_USER = 'root';
const DB_PASS = '';
/**
* Function to be tested
*
* Should connect to a database, retrieve the database version number.
*/
function getMysqlVersion(): string
{
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASS);
if (mysqli_connect_errno()) {
throw new Exception("Connection failed: %s\n" . mysqli_connect_error());
}
$version = mysqli_get_server_version($link);
mysqli_close($link);
return $version;
}
/**
* PHPUnit test code
*
* This ensures that the database connection is made and the expected
* version integer is returned.
*/
use PHPUnit\Framework\TestCase;
class GetMysqlVersionTest extends TestCase
{
function testItConnectsAndReturnsCorrectVersion()
{
$result = getMysqlVersion();
$this->assertStringStartsWith('507', $result);
}
}