Skip to content

Commit

Permalink
feat: add Null output and format (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Aug 1, 2022
1 parent 9c4439f commit 6642d6f
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Constructor of class SimPod\\\\ClickHouseClient\\\\Output\\\\Null_ has an unused parameter \\$_\\.$#"
count: 1
path: src/Output/Null_.php
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Expand Up @@ -5,5 +5,11 @@ parameters:
- %currentWorkingDirectory%/tests

ignoreErrors:
# There's no other way to test-pass without assertions while counting it towards coverage https://github.com/sebastianbergmann/phpunit/issues/3016
- '~Call to static method PHPUnit\\Framework\\Assert::assertTrue\(\) with true will always evaluate to true~'

# Adds unnecessary maintanence overhead. We rather rely on PHPStan telling us the method returns unhandled FALSE
- "~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~"

includes:
- phpstan-baseline.neon
26 changes: 26 additions & 0 deletions src/Format/Null_.php
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace SimPod\ClickHouseClient\Format;

use SimPod\ClickHouseClient\Output\Output;

// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps

/**
* @template T
* @implements Format<\SimPod\ClickHouseClient\Output\Null_<T>>
*/
final class Null_ implements Format
{
public static function output(string $contents): Output
{
return new \SimPod\ClickHouseClient\Output\Null_($contents);
}

public static function toSql(): string
{
return 'FORMAT Null';
}
}
19 changes: 19 additions & 0 deletions src/Output/Null_.php
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace SimPod\ClickHouseClient\Output;

// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps

/**
* @psalm-immutable
* @template T
* @implements Output<T>
*/
final class Null_ implements Output
{
public function __construct(string $_)
{
}
}
14 changes: 14 additions & 0 deletions tests/Client/SelectTest.php
Expand Up @@ -8,6 +8,7 @@
use SimPod\ClickHouseClient\Format\Json;
use SimPod\ClickHouseClient\Format\JsonCompact;
use SimPod\ClickHouseClient\Format\JsonEachRow;
use SimPod\ClickHouseClient\Format\Null_;
use SimPod\ClickHouseClient\Tests\TestCaseBase;
use SimPod\ClickHouseClient\Tests\WithClient;

Expand All @@ -16,8 +17,13 @@
* @covers \SimPod\ClickHouseClient\Client\PsrClickHouseClient
* @covers \SimPod\ClickHouseClient\Exception\ServerError
* @covers \SimPod\ClickHouseClient\Format\Json
* @covers \SimPod\ClickHouseClient\Output\Json
* @covers \SimPod\ClickHouseClient\Format\JsonEachRow
* @covers \SimPod\ClickHouseClient\Output\JsonEachRow
* @covers \SimPod\ClickHouseClient\Format\JsonCompact
* @covers \SimPod\ClickHouseClient\Output\JsonCompact
* @covers \SimPod\ClickHouseClient\Format\Null_
* @covers \SimPod\ClickHouseClient\Output\Null_
*/
final class SelectTest extends TestCaseBase
{
Expand Down Expand Up @@ -140,6 +146,14 @@ public function providerJsonEachRow(): iterable
];
}

public function testNull(): void
{
$client = $this->client;
$client->select('SELECT 1', new Null_());

self::assertTrue(true);
}

public function testSettingsArePassed(): void
{
self::expectException(ServerError::class);
Expand Down

0 comments on commit 6642d6f

Please sign in to comment.