@@ -24,49 +24,6 @@ protected function setUp()
2424 $ ch ->session_autocreate = false ;
2525 }
2626
27- /**
28- * @covers Ierusalim\ClickHouse\ClickHouseAPI::query
29- */
30- public function testQuery ()
31- {
32- $ ch = $ this ->object ;
33- $ ans = $ ch ->query ("SELECT 123 " )->results ;
34- $ this ->assertEquals ("123 \n" , $ ans );
35- $ table = "querytesttable " ;
36- $ this ->assertEquals ("111 \n" , $ ch
37- ->query ("CREATE TABLE IF NOT EXISTS $ table (id UInt8, dt Date) ENGINE = MergeTree(dt, (id), 8192) " )
38- ->query ("INSERT INTO $ table SELECT 111 as id, toDate(now()) as dt " )
39- ->query ("SELECT id FROM $ table WHERE dt = toDate(now()) " )
40- ->query ("DROP TABLE IF EXISTS $ table " )
41- ->results
42- );
43- try {
44- $ ans = $ ch ->query ("BAD QUERY " );
45- } catch (\Exception $ e ) {
46- $ ans = $ e ->getMessage ();
47- }
48- $ this ->assertTrue (\strpos ($ ans , 'Syntax error ' ) !== false );
49-
50- // curl error emulation
51- $ ch ->hook_before_api_call = function ($ s , $ obj ) {
52- return 'http://github.com:22/ ' ;
53- };
54- try {
55- $ ans = $ ch ->query ("ANY QUERY " );
56- } catch (\Exception $ e ) {
57- $ ans = $ e ->getMessage ();
58- }
59- print_r ($ ans );
60- //$this->assertTrue(\strpos($ans, 'Syntax error') !== false);
61- $ ch ->hook_before_api_call = false ;
62-
63- try {
64- $ ans =(new ClickHouseAPI ("https://github.com:443/ " ))->query ("" );
65- } catch (\Exception $ e ) {
66- $ ans = $ e ->getMessage ();
67- }
68- }
69-
7027 public function testConstructEmpty ()
7128 {
7229 $ r = new ClickHouseAPI ();
@@ -146,6 +103,30 @@ public function testGetVersion()
146103 $ this ->assertEquals ($ version , $ ver_good );
147104 }
148105
106+ /**
107+ * @covers Ierusalim\ClickHouse\ClickHouseAPI::setCompression
108+ */
109+ public function testSetCompression ()
110+ {
111+ $ ch = $ this ->object ;
112+ $ ch ->setCompression (false );
113+
114+ $ ans = $ ch ->query ("SELECT number FROM system.numbers LIMIT 100 " )->results ;
115+
116+ $ size_d = $ ch ->curl_getinfo [\CURLINFO_SIZE_DOWNLOAD ];
117+ $ this ->assertEquals (strlen ($ ans ), $ size_d );
118+
119+ $ ch ->setCompression (true );
120+
121+ $ ans = $ ch ->query ("SELECT number FROM system.numbers LIMIT 100 " )->results ;
122+
123+ $ size_d = $ ch ->curl_getinfo [\CURLINFO_SIZE_DOWNLOAD ];
124+ if ($ size_d < strlen ($ ans )) {
125+ echo "http-compression supported \n" ;
126+ }
127+ $ this ->assertGreaterThan ($ size_d , strlen ($ ans ));
128+ }
129+
149130 /**
150131 * @covers ierusalim\ClickHouse\ClickHouseAPI::isSupported
151132 */
@@ -167,9 +148,62 @@ public function testIsSupported()
167148 $ this ->assertTrue ($ ch ->isSupported ('session_id ' ));
168149 }
169150
151+ $ this ->assertEquals ($ ch ->isSupported ('version ' , true ), $ ch ->getVersion ());
152+
170153 $ this ->assertFalse ($ ch ->isSupported ('unknown ' ));
171154 }
172155
156+
157+ /**
158+ * @covers Ierusalim\ClickHouse\ClickHouseAPI::query
159+ */
160+ public function testQuery ()
161+ {
162+ $ ch = $ this ->object ;
163+
164+ if ($ ch ->isSupported ('query ' )) {
165+ $ ans = $ ch ->query ("SELECT 123 " )->results ;
166+ $ this ->assertEquals ("123 \n" , $ ans );
167+ $ table = "querytesttable " ;
168+ $ this ->assertEquals ("111 \n" , $ ch
169+ ->query ("CREATE TABLE IF NOT EXISTS $ table (id UInt8, dt Date) ENGINE = MergeTree(dt, (id), 8192) " )
170+ ->query ("INSERT INTO $ table SELECT 111 as id, toDate(now()) as dt " )
171+ ->query ("SELECT id FROM $ table WHERE dt = toDate(now()) " )
172+ ->query ("DROP TABLE IF EXISTS $ table " )
173+ ->results
174+ );
175+ }
176+
177+ try {
178+ $ ans = $ ch ->query ("BAD QUERY " );
179+ } catch (\Exception $ e ) {
180+ $ ans = $ e ->getMessage ();
181+ }
182+ $ this ->assertTrue (\strpos ($ ans , 'Syntax error ' ) !== false );
183+
184+ $ ch ->curl_options [\CURLOPT_CONNECTTIMEOUT ] = 2 ;
185+
186+ // curl error emulation
187+ $ ch ->hook_before_api_call = function ($ s , $ obj ) {
188+ return 'http://github.com:22/ ' ;
189+ };
190+ try {
191+ $ ans = $ ch ->query ("ANY QUERY " );
192+ } catch (\Exception $ e ) {
193+ $ ans = $ e ->getMessage ();
194+ }
195+ //$this->assertTrue(\strpos($ans, 'Syntax error') !== false);
196+ $ ch ->hook_before_api_call = false ;
197+
198+ try {
199+ $ ch = new ClickHouseAPI ("https://github.com:443/ " );
200+ $ ch ->curl_options [\CURLOPT_CONNECTTIMEOUT ] = 2 ;
201+ $ ans =$ ch ->query ("" );
202+ } catch (\Exception $ e ) {
203+ $ ans = $ e ->getMessage ();
204+ }
205+ }
206+
173207 /**
174208 * @covers Ierusalim\ClickHouse\ClickHouseAPI::anyQuery
175209 * @todo Implement testAnyQuery().
0 commit comments