-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SelectAsyncTest.php
61 lines (48 loc) · 1.77 KB
/
SelectAsyncTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
namespace SimPod\ClickHouseClient\Tests\Client;
use GuzzleHttp\Promise\Utils;
use PHPUnit\Framework\Attributes\CoversClass;
use SimPod\ClickHouseClient\Client\Http\RequestFactory;
use SimPod\ClickHouseClient\Client\PsrClickHouseAsyncClient;
use SimPod\ClickHouseClient\Exception\ServerError;
use SimPod\ClickHouseClient\Format\JsonEachRow;
use SimPod\ClickHouseClient\Format\TabSeparated;
use SimPod\ClickHouseClient\Tests\TestCaseBase;
use SimPod\ClickHouseClient\Tests\WithClient;
#[CoversClass(RequestFactory::class)]
#[CoversClass(PsrClickHouseAsyncClient::class)]
#[CoversClass(ServerError::class)]
#[CoversClass(JsonEachRow::class)]
#[CoversClass(TabSeparated::class)]
final class SelectAsyncTest extends TestCaseBase
{
use WithClient;
public function testAsyncSelect(): void
{
$client = self::$asyncClient;
$sql = <<<'CLICKHOUSE'
SELECT number FROM system.numbers LIMIT 2
CLICKHOUSE;
/** @var JsonEachRow<array{number: string}> $format */
$format = new JsonEachRow();
$promises = [
$client->select($sql, $format),
$client->select($sql, $format),
];
$jsonEachRowOutputs = Utils::all($promises)->wait();
$expectedData = [
['number' => '0'],
['number' => '1'],
];
self::assertIsArray($jsonEachRowOutputs);
self::assertCount(2, $jsonEachRowOutputs);
self::assertSame($expectedData, $jsonEachRowOutputs[0]->data);
self::assertSame($expectedData, $jsonEachRowOutputs[1]->data);
}
public function testSelectFromNonExistentTableExpectServerError(): void
{
$this->expectException(ServerError::class);
self::$asyncClient->select('table', new TabSeparated())->wait();
}
}