Skip to content

Commit

Permalink
Add Version snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed May 19, 2020
1 parent 9e19dac commit edf2eba
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,4 @@ $currentDatabaseName = CurrentDatabase::run($client);
- ShowCreateTable
- ShowDatabases
- TableSizes
- Version
29 changes: 29 additions & 0 deletions src/Snippet/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace SimPod\ClickHouseClient\Snippet;

use SimPod\ClickHouseClient\Client\ClickHouseClient;
use SimPod\ClickHouseClient\Format\JsonEachRow;
use function assert;
use function is_string;

final class Version
{
public static function run(ClickHouseClient $clickHouseClient) : string
{
$version = $clickHouseClient->select(
<<<CLICKHOUSE
SELECT version() AS version
CLICKHOUSE,
new JsonEachRow()
);

/** @psalm-suppress MixedAssignment */
$version = $version->data[0]['version'];
assert(is_string($version));

return $version;
}
}
20 changes: 20 additions & 0 deletions tests/Snippet/VersionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace SimPod\ClickHouseClient\Tests\Snippet;

use SimPod\ClickHouseClient\Snippet\Version;
use SimPod\ClickHouseClient\Tests\TestCaseBase;
use SimPod\ClickHouseClient\Tests\WithClient;

/** @covers \SimPod\ClickHouseClient\Snippet\Version */
final class VersionTest extends TestCaseBase
{
use WithClient;

public function testRun() : void
{
self::assertRegExp('~(\d+\.)+\d+~', Version::run($this->client));
}
}

0 comments on commit edf2eba

Please sign in to comment.