Skip to content

Commit

Permalink
add docker
Browse files Browse the repository at this point in the history
  • Loading branch information
amltv committed Aug 2, 2019
1 parent a71a451 commit 1233f5c
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 19 deletions.
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* text=auto

/tests export-ignore
/utils export-ignore
/.coveralls.yml export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/docker-compose.yml export-ignore
/phpunit.xml export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.idea
/coverage
/utils/ccat/ccat
composer.lock
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: "3.6"

services:
clickhouse:
image: "yandex/clickhouse-server:19.11.3.11"
composer:
image: "composer"
volumes:
- "./:/app"
- ${COMPOSER_HOME:-$HOME/.composer}:/tmp
phpunit:
image: "php"
depends_on:
- clickhouse
volumes:
- "./:/app"
working_dir: "/app"
entrypoint:
- "./vendor/bin/phpunit"
environment:
"CH_HOST": "clickhouse"
"CH_PORT": "8123"
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
<log type="coverage-html" target="coverage" charset="UTF-8"/>
</logging>
<php>
<const name="CLICKHOUSE_SERVER_HOST" value="127.0.0.1"/>
<const name="CLICKHOUSE_SERVER_PORT" value="8123"/>
<env name="CH_HOST" value="127.0.0.1"/>
<env name="CH_PORT" value="8123"/>
<const name="CCAT_PATH" value="bin/ccat"/>
</php>
</phpunit>
11 changes: 7 additions & 4 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Tinderbox\Clickhouse\Query\Mapper\NamedMapper;
use Tinderbox\Clickhouse\Query\QueryStatistic;
use Tinderbox\Clickhouse\Query\Result;
use Tinderbox\Clickhouse\Support\ServerTrait;

/**
* @covers \Tinderbox\Clickhouse\Client
Expand All @@ -20,9 +21,11 @@
*/
class ClientTest extends TestCase
{
use ServerTrait;

public function testGetters()
{
$server = new Server('127.0.0.1');
$server = $this->getServer();
$serverProvider = new ServerProvider();
$serverProvider->addServer($server);

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

public function testMappers()
{
$server = new Server('127.0.0.1');
$server = $this->getServer();
$serverProvider = new ServerProvider();
$serverProvider->addServer($server);

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

public function testTransports()
{
$server = new Server('127.0.0.1');
$server = $this->getServer();
$serverProvider = new ServerProvider();
$serverProvider->addServer($server);

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

return new Client($serverProvider);
}
Expand Down
23 changes: 10 additions & 13 deletions tests/HttpTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
use Tinderbox\Clickhouse\Common\MergedFiles;
use Tinderbox\Clickhouse\Common\TempTable;
use Tinderbox\Clickhouse\Exceptions\TransportException;
use Tinderbox\Clickhouse\Support\ServerTrait;
use Tinderbox\Clickhouse\Transport\HttpTransport;

/**
* @covers \Tinderbox\Clickhouse\Transport\HttpTransport
*/
class HttpTransportTest extends TestCase
{
use ServerTrait;

protected function getMockedTransport(array $responses) : HttpTransport
{
$mock = new MockHandler($responses);
Expand All @@ -35,11 +38,6 @@ protected function getQuery() : Query
return new Query($this->getServer(), 'select * from table');
}

protected function getServer() : Server
{
return new Server(CLICKHOUSE_SERVER_HOST, CLICKHOUSE_SERVER_PORT, 'default', 'default');
}

protected function getTransport() : HttpTransport
{
return new HttpTransport();
Expand Down Expand Up @@ -379,11 +377,10 @@ public function testConnectionWithPassword()
$this->expectException(TransportException::class);
$this->expectExceptionMessageRegExp('/Wrong password for user default/');

$transport->read([
new Query(new Server('127.0.0.1', 8123, 'default','default', 'pass'), 'select 1', [
new TempTable('name', new FileFromString('aaa'), ['string' => 'String'], Format::TSV)
])
]);
$server = $this->getServer('default', 'default', 'pass');
$file = new TempTable('name', new FileFromString('aaa'), ['string' => 'String'], Format::TSV);

$transport->read([new Query($server, 'select 1', [$file])]);
}

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

$server = $this->getServer('default', 'default', 'pass');

$transport->write([
new Query(new Server('127.0.0.1', 8123, 'default','default', 'pass'), 'insert into table 1', [
new FileFromString('aaa')
])
new Query($server, 'insert into table ', [new FileFromString('aaa')])
]);
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Support/ServerTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Tinderbox\Clickhouse\Support;

use Tinderbox\Clickhouse\Server;

trait ServerTrait
{
protected function getServer($database = 'default', $username = 'default', $password = null) : Server
{
return new Server(getenv('CH_HOST'), getenv('CH_PORT'), $database, $username, $password);
}
}

0 comments on commit 1233f5c

Please sign in to comment.