Passed
Push — master ( c73d10...c1344b )
by Stefan
06:00
created

PNDataProviderMySQLTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 16
dl 0
loc 33
rs 10
c 1
b 0
f 1
wmc 5
1
<?php
2
declare(strict_types=1);
3
4
namespace SKien\Test\PNServer;
5
6
use SKien\PNServer\PNDataProviderMySQL;
7
8
/**
9
 * Fixture for the whole test.
10
 * - connect to MYSQL phpUnit test database and drop subscription table if exist
11
 * 
12
 * Clean-Up 
13
 * - drop created table 
14
 * 
15
 * @author Stefanius <[email protected]>
16
 * @copyright MIT License - see the LICENSE file for details
17
 */
18
class PNDataProviderMySQLTest extends PNDataProviderTest
19
{
20
    public static function setUpBeforeClass() : void
21
    {
22
        $db = mysqli_connect($GLOBALS['MYSQL_HOST'], $GLOBALS['MYSQL_USER'], $GLOBALS['MYSQL_PASSWD'], $GLOBALS['MYSQL_DBNAME']);
23
        if (!$db) {
24
            fwrite(STDOUT, 'MySQL: Connect Error ' . mysqli_connect_errno() . PHP_EOL);
25
        }
26
        $db->query("DROP TABLE IF EXISTS " . PNDataProviderMySQL::TABLE_NAME);
27
    }
28
    
29
    public static function tearDownAfterClass() : void
30
    {
31
        $db = mysqli_connect($GLOBALS['MYSQL_HOST'], $GLOBALS['MYSQL_USER'], $GLOBALS['MYSQL_PASSWD'], $GLOBALS['MYSQL_DBNAME']);
32
        $db->query("DROP TABLE IF EXISTS " . PNDataProviderMySQL::TABLE_NAME);
33
    }
34
35
    public function setUp() : void
36
    {
37
        // connection params set in the phpunit.xml configuration file
38
        $strDBHost = $GLOBALS['MYSQL_HOST'];
39
        $strDBUser = $GLOBALS['MYSQL_USER'];
40
        $strDBPwd = $GLOBALS['MYSQL_PASSWD'];
41
        $strDBName = $GLOBALS['MYSQL_DBNAME'];
42
        $this->dp = new PNDataProviderMySQL($strDBHost, $strDBUser, $strDBPwd, $strDBName);
43
    }
44
    
45
    public function test_constructError()
46
    {
47
        $dp = new PNDataProviderMySQL('not', 'a', 'valid', 'connection');
48
        $this->assertIsObject($dp);
49
        $this->assertFalse($dp->isConnected());
50
        $this->assertNotEmpty($dp->getError());
51
    }
52
}
53