push(Middleware::history($history)); $http = new Client(['handler' => $handler]); $client = new ClickHouseClient($http, $this->configuration()); $this->assertTrue($client->ping()); $this->assertSame([['value' => 1], ['value' => 2]], $client->rows( 'SELECT value FROM numbers(2) WHERE value >= {minimum:UInt8}', ['minimum' => 0], )); $client->insertJsonEachRow('fact_rows', ['id', 'name'], [ ['id' => 1, 'name' => '测试'], ]); parse_str($history[1]['request']->getUri()->getQuery(), $query); $this->assertSame('0', (string) $query['param_minimum']); $this->assertStringContainsString('{minimum:UInt8}', $query['query']); $this->assertStringNotContainsString('fixture-password', $query['query']); parse_str($history[2]['request']->getUri()->getQuery(), $insertQuery); $this->assertStringContainsString('FORMAT JSONEachRow', $insertQuery['query']); $this->assertSame("{\"id\":1,\"name\":\"测试\"}\n", (string) $history[2]['request']->getBody()); $this->assertSame('PAR1', (string) $client->stream('SELECT 1', 'Parquet')); $this->assertSame(1800.0, $history[3]['options']['timeout']); } public function test_invalid_identifier_is_rejected_before_a_query_is_sent(): void { $client = new ClickHouseClient(new Client(['handler' => HandlerStack::create(new MockHandler())]), $this->configuration()); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('clickhouse_invalid_identifier'); $client->qualifiedTable('fact_rows; DROP TABLE fact_rows'); } /** @return array */ private function configuration(): array { return [ 'enabled' => true, 'url' => 'http://clickhouse:8123', 'database' => 'analytics', 'username' => 'fixture-user', 'password' => 'fixture-password', 'connect_timeout_seconds' => 1, 'query_timeout_seconds' => 1, ]; } }