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
|
|
|
|