Skip to content

Commit 6642d6f

Browse files
authored
feat: add Null output and format (#168)
1 parent 9c4439f commit 6642d6f

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

phpstan-baseline.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Constructor of class SimPod\\\\ClickHouseClient\\\\Output\\\\Null_ has an unused parameter \\$_\\.$#"
5+
count: 1
6+
path: src/Output/Null_.php

phpstan.neon.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@ parameters:
55
- %currentWorkingDirectory%/tests
66

77
ignoreErrors:
8+
# There's no other way to test-pass without assertions while counting it towards coverage https://github.com/sebastianbergmann/phpunit/issues/3016
9+
- '~Call to static method PHPUnit\\Framework\\Assert::assertTrue\(\) with true will always evaluate to true~'
10+
811
# Adds unnecessary maintanence overhead. We rather rely on PHPStan telling us the method returns unhandled FALSE
912
- "~Class DateTime(Immutable)? is unsafe to use. Its methods can return FALSE instead of throwing an exception. Please add 'use Safe\\\\DateTime(Immutable)?;' at the beginning of the file to use the variant provided by the 'thecodingmachine/safe' library~"
13+
14+
includes:
15+
- phpstan-baseline.neon

src/Format/Null_.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimPod\ClickHouseClient\Format;
6+
7+
use SimPod\ClickHouseClient\Output\Output;
8+
9+
// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
10+
11+
/**
12+
* @template T
13+
* @implements Format<\SimPod\ClickHouseClient\Output\Null_<T>>
14+
*/
15+
final class Null_ implements Format
16+
{
17+
public static function output(string $contents): Output
18+
{
19+
return new \SimPod\ClickHouseClient\Output\Null_($contents);
20+
}
21+
22+
public static function toSql(): string
23+
{
24+
return 'FORMAT Null';
25+
}
26+
}

src/Output/Null_.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimPod\ClickHouseClient\Output;
6+
7+
// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
8+
9+
/**
10+
* @psalm-immutable
11+
* @template T
12+
* @implements Output<T>
13+
*/
14+
final class Null_ implements Output
15+
{
16+
public function __construct(string $_)
17+
{
18+
}
19+
}

tests/Client/SelectTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use SimPod\ClickHouseClient\Format\Json;
99
use SimPod\ClickHouseClient\Format\JsonCompact;
1010
use SimPod\ClickHouseClient\Format\JsonEachRow;
11+
use SimPod\ClickHouseClient\Format\Null_;
1112
use SimPod\ClickHouseClient\Tests\TestCaseBase;
1213
use SimPod\ClickHouseClient\Tests\WithClient;
1314

@@ -16,8 +17,13 @@
1617
* @covers \SimPod\ClickHouseClient\Client\PsrClickHouseClient
1718
* @covers \SimPod\ClickHouseClient\Exception\ServerError
1819
* @covers \SimPod\ClickHouseClient\Format\Json
20+
* @covers \SimPod\ClickHouseClient\Output\Json
1921
* @covers \SimPod\ClickHouseClient\Format\JsonEachRow
22+
* @covers \SimPod\ClickHouseClient\Output\JsonEachRow
2023
* @covers \SimPod\ClickHouseClient\Format\JsonCompact
24+
* @covers \SimPod\ClickHouseClient\Output\JsonCompact
25+
* @covers \SimPod\ClickHouseClient\Format\Null_
26+
* @covers \SimPod\ClickHouseClient\Output\Null_
2127
*/
2228
final class SelectTest extends TestCaseBase
2329
{
@@ -140,6 +146,14 @@ public function providerJsonEachRow(): iterable
140146
];
141147
}
142148

149+
public function testNull(): void
150+
{
151+
$client = $this->client;
152+
$client->select('SELECT 1', new Null_());
153+
154+
self::assertTrue(true);
155+
}
156+
143157
public function testSettingsArePassed(): void
144158
{
145159
self::expectException(ServerError::class);

0 commit comments

Comments
 (0)