Skip to content

Commit 1233f5c

Browse files
committed
add docker
1 parent a71a451 commit 1233f5c

File tree

7 files changed

+65
-19
lines changed

7 files changed

+65
-19
lines changed

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
* text=auto
2+
3+
/tests export-ignore
4+
/utils export-ignore
5+
/.coveralls.yml export-ignore
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/.travis.yml export-ignore
9+
/docker-compose.yml export-ignore
10+
/phpunit.xml export-ignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/.idea
33
/coverage
44
/utils/ccat/ccat
5+
composer.lock

docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: "3.6"
2+
3+
services:
4+
clickhouse:
5+
image: "yandex/clickhouse-server:19.11.3.11"
6+
composer:
7+
image: "composer"
8+
volumes:
9+
- "./:/app"
10+
- ${COMPOSER_HOME:-$HOME/.composer}:/tmp
11+
phpunit:
12+
image: "php"
13+
depends_on:
14+
- clickhouse
15+
volumes:
16+
- "./:/app"
17+
working_dir: "/app"
18+
entrypoint:
19+
- "./vendor/bin/phpunit"
20+
environment:
21+
"CH_HOST": "clickhouse"
22+
"CH_PORT": "8123"

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
<log type="coverage-html" target="coverage" charset="UTF-8"/>
2424
</logging>
2525
<php>
26-
<const name="CLICKHOUSE_SERVER_HOST" value="127.0.0.1"/>
27-
<const name="CLICKHOUSE_SERVER_PORT" value="8123"/>
26+
<env name="CH_HOST" value="127.0.0.1"/>
27+
<env name="CH_PORT" value="8123"/>
2828
<const name="CCAT_PATH" value="bin/ccat"/>
2929
</php>
3030
</phpunit>

tests/ClientTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Tinderbox\Clickhouse\Query\Mapper\NamedMapper;
1313
use Tinderbox\Clickhouse\Query\QueryStatistic;
1414
use Tinderbox\Clickhouse\Query\Result;
15+
use Tinderbox\Clickhouse\Support\ServerTrait;
1516

1617
/**
1718
* @covers \Tinderbox\Clickhouse\Client
@@ -20,9 +21,11 @@
2021
*/
2122
class ClientTest extends TestCase
2223
{
24+
use ServerTrait;
25+
2326
public function testGetters()
2427
{
25-
$server = new Server('127.0.0.1');
28+
$server = $this->getServer();
2629
$serverProvider = new ServerProvider();
2730
$serverProvider->addServer($server);
2831

@@ -37,7 +40,7 @@ public function testGetters()
3740

3841
public function testMappers()
3942
{
40-
$server = new Server('127.0.0.1');
43+
$server = $this->getServer();
4144
$serverProvider = new ServerProvider();
4245
$serverProvider->addServer($server);
4346

@@ -50,7 +53,7 @@ public function testMappers()
5053

5154
public function testTransports()
5255
{
53-
$server = new Server('127.0.0.1');
56+
$server = $this->getServer();
5457
$serverProvider = new ServerProvider();
5558
$serverProvider->addServer($server);
5659

@@ -214,7 +217,7 @@ public function testClusterAndServersTogether()
214217
protected function getClient(): Client
215218
{
216219
$serverProvider = new ServerProvider();
217-
$serverProvider->addServer(new Server('127.0.0.1', '8123', 'default', 'default', ''));
220+
$serverProvider->addServer($this->getServer());
218221

219222
return new Client($serverProvider);
220223
}

tests/HttpTransportTest.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
use Tinderbox\Clickhouse\Common\MergedFiles;
1313
use Tinderbox\Clickhouse\Common\TempTable;
1414
use Tinderbox\Clickhouse\Exceptions\TransportException;
15+
use Tinderbox\Clickhouse\Support\ServerTrait;
1516
use Tinderbox\Clickhouse\Transport\HttpTransport;
1617

1718
/**
1819
* @covers \Tinderbox\Clickhouse\Transport\HttpTransport
1920
*/
2021
class HttpTransportTest extends TestCase
2122
{
23+
use ServerTrait;
24+
2225
protected function getMockedTransport(array $responses) : HttpTransport
2326
{
2427
$mock = new MockHandler($responses);
@@ -35,11 +38,6 @@ protected function getQuery() : Query
3538
return new Query($this->getServer(), 'select * from table');
3639
}
3740

38-
protected function getServer() : Server
39-
{
40-
return new Server(CLICKHOUSE_SERVER_HOST, CLICKHOUSE_SERVER_PORT, 'default', 'default');
41-
}
42-
4341
protected function getTransport() : HttpTransport
4442
{
4543
return new HttpTransport();
@@ -379,11 +377,10 @@ public function testConnectionWithPassword()
379377
$this->expectException(TransportException::class);
380378
$this->expectExceptionMessageRegExp('/Wrong password for user default/');
381379

382-
$transport->read([
383-
new Query(new Server('127.0.0.1', 8123, 'default','default', 'pass'), 'select 1', [
384-
new TempTable('name', new FileFromString('aaa'), ['string' => 'String'], Format::TSV)
385-
])
386-
]);
380+
$server = $this->getServer('default', 'default', 'pass');
381+
$file = new TempTable('name', new FileFromString('aaa'), ['string' => 'String'], Format::TSV);
382+
383+
$transport->read([new Query($server, 'select 1', [$file])]);
387384
}
388385

389386
public function testConnectionWithPasswordOnWrite()
@@ -393,10 +390,10 @@ public function testConnectionWithPasswordOnWrite()
393390
$this->expectException(TransportException::class);
394391
$this->expectExceptionMessageRegExp('/Wrong password for user default/');
395392

393+
$server = $this->getServer('default', 'default', 'pass');
394+
396395
$transport->write([
397-
new Query(new Server('127.0.0.1', 8123, 'default','default', 'pass'), 'insert into table 1', [
398-
new FileFromString('aaa')
399-
])
396+
new Query($server, 'insert into table ', [new FileFromString('aaa')])
400397
]);
401398
}
402399

tests/Support/ServerTrait.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Tinderbox\Clickhouse\Support;
4+
5+
use Tinderbox\Clickhouse\Server;
6+
7+
trait ServerTrait
8+
{
9+
protected function getServer($database = 'default', $username = 'default', $password = null) : Server
10+
{
11+
return new Server(getenv('CH_HOST'), getenv('CH_PORT'), $database, $username, $password);
12+
}
13+
}

0 commit comments

Comments
 (0)