1
|
|
|
<?php declare( strict_types=1 ); |
2
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Tests\Core\Extractors; |
4
|
|
|
|
5
|
|
|
use Coco\SourceWatcher\Core\Database\Connections\MySqlConnector; |
6
|
|
|
use Coco\SourceWatcher\Core\Extractors\DatabaseExtractor; |
7
|
|
|
use Coco\SourceWatcher\Core\SourceWatcherException; |
8
|
|
|
use Coco\SourceWatcher\Tests\Common\ParentTest; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class DatabaseExtractorTest |
12
|
|
|
* |
13
|
|
|
* @package Coco\SourceWatcher\Tests\Core\Extractors |
14
|
|
|
*/ |
15
|
|
|
class DatabaseExtractorTest extends ParentTest |
16
|
|
|
{ |
17
|
|
|
private string $tableName; |
18
|
|
|
private MySqlConnector $mysqlConnector; |
19
|
|
|
|
20
|
|
|
public function setUp () : void |
21
|
|
|
{ |
22
|
|
|
$this->tableName = "people"; |
23
|
|
|
|
24
|
|
|
$this->mysqlConnector = new MySqlConnector(); |
25
|
|
|
$this->mysqlConnector->setUser( $this->getEnvironmentVariable( "UNIT_TEST_MYSQL_USERNAME", null ) ); |
26
|
|
|
$this->mysqlConnector->setPassword( $this->getEnvironmentVariable( "UNIT_TEST_MYSQL_PASSWORD", null ) ); |
27
|
|
|
$this->mysqlConnector->setHost( $this->getEnvironmentVariable( "UNIT_TEST_MYSQL_HOST", null ) ); |
28
|
|
|
$this->mysqlConnector->setPort( $this->getEnvironmentVariable( "UNIT_TEST_MYSQL_PORT", 5432, "intval" ) ); |
29
|
|
|
$this->mysqlConnector->setDbName( $this->getEnvironmentVariable( "UNIT_TEST_MYSQL_DATABASE", null ) ); |
30
|
|
|
|
31
|
|
|
$this->mysqlConnector->setTableName( $this->tableName ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @throws SourceWatcherException |
36
|
|
|
*/ |
37
|
|
|
public function testExtractFromMySqlTable () : void |
38
|
|
|
{ |
39
|
|
|
$query = "SELECT * FROM " . $this->tableName; |
40
|
|
|
|
41
|
|
|
$databaseExtractor = new DatabaseExtractor( $this->mysqlConnector, $query ); |
42
|
|
|
|
43
|
|
|
$result = $databaseExtractor->extract(); |
44
|
|
|
|
45
|
|
|
$this->assertNotEmpty( $result ); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|