Skip to content

Commit b7c841d

Browse files
committed
Fix phpUnit
1 parent 5de32b0 commit b7c841d

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ Edit in phpunit.xml constants:
873873
<env name="CLICKHOUSE_HOST" value="127.0.0.1" />
874874
<env name="CLICKHOUSE_PORT" value="8123" />
875875
<env name="CLICKHOUSE_USER" value="default" />
876+
<env name="CLICKHOUSE_DATABASE" value="phpChTestDefault" />
876877
<env name="CLICKHOUSE_PASSWORD" value="" />
877878
<env name="CLICKHOUSE_TMPPATH" value="/tmp" />
878879
</php>

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"php": "^7.1",
2121
"doctrine/coding-standard": "^4.0",
2222
"phpstan/phpstan": "^0.9.2",
23-
"phpunit/phpunit": "^7.0"
23+
"phpunit/phpunit": "^7",
24+
"sebastian/comparator": "~3.0"
2425
},
2526
"autoload": {
2627
"psr-4": {

tests/WithClient.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@ public function restartClickHouseClient()
3333
'password' => getenv('CLICKHOUSE_PASSWORD'),
3434

3535
];
36+
3637
$this->client = new Client($config);
3738
$databaseName = getenv('CLICKHOUSE_DATABASE');
38-
$this->client->write(sprintf('DROP DATABASE IF EXISTS "%s"', $databaseName));
39-
$this->client->write(sprintf('CREATE DATABASE "%s"', $databaseName));
39+
if (!$databaseName || $databaseName==='default') {
40+
throw new \Exception('Change CLICKHOUSE_DATABASE, not use default');
41+
}
42+
if (empty($GLOBALS['phpCH_needFirstCreateDB'])) { // hack use Global VAR, for once create DB
43+
$GLOBALS['phpCH_needFirstCreateDB']=true;
44+
$this->client->write(sprintf('DROP DATABASE IF EXISTS "%s"', $databaseName));
45+
$this->client->write(sprintf('CREATE DATABASE "%s"', $databaseName));
46+
}
47+
// Change Database
4048
$this->client->database($databaseName);
4149
}
4250
}

0 commit comments

Comments
 (0)