From 1233f5c071102794b4c9e895ae8bcfa63ba06f20 Mon Sep 17 00:00:00 2001 From: Andrey Maltsev Date: Fri, 2 Aug 2019 15:34:45 +0300 Subject: [PATCH] add docker --- .gitattributes | 10 ++++++++++ .gitignore | 1 + docker-compose.yml | 22 ++++++++++++++++++++++ phpunit.xml | 4 ++-- tests/ClientTest.php | 11 +++++++---- tests/HttpTransportTest.php | 23 ++++++++++------------- tests/Support/ServerTrait.php | 13 +++++++++++++ 7 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 .gitattributes create mode 100644 docker-compose.yml create mode 100644 tests/Support/ServerTrait.php diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a03beba --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/.gitignore b/.gitignore index f2a272f..ef2da60 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /.idea /coverage /utils/ccat/ccat +composer.lock diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..45f8b25 --- /dev/null +++ b/docker-compose.yml @@ -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" \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index 2cfb02b..c77b9f6 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -23,8 +23,8 @@ - - + + diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 0eb8e28..c4325c7 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -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 @@ -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); @@ -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); @@ -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); @@ -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); } diff --git a/tests/HttpTransportTest.php b/tests/HttpTransportTest.php index e10d3c5..a4bbab6 100644 --- a/tests/HttpTransportTest.php +++ b/tests/HttpTransportTest.php @@ -12,6 +12,7 @@ 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; /** @@ -19,6 +20,8 @@ */ class HttpTransportTest extends TestCase { + use ServerTrait; + protected function getMockedTransport(array $responses) : HttpTransport { $mock = new MockHandler($responses); @@ -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(); @@ -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() @@ -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')]) ]); } diff --git a/tests/Support/ServerTrait.php b/tests/Support/ServerTrait.php new file mode 100644 index 0000000..f7f99e2 --- /dev/null +++ b/tests/Support/ServerTrait.php @@ -0,0 +1,13 @@ +