@@ -74,6 +74,117 @@ public function testSetServerUrlException()
7474 $ ch ->setServerUrl ("ftp://8.8.8.8 " );
7575 }
7676
77+ /**
78+ * @covers ierusalim\ClickHouse\ClickHouseAPI::doApiCall
79+ * @todo Implement testDoApiCall().
80+ */
81+ public function testDoApiCall ()
82+ {
83+ $ ch = $ this ->object ;
84+
85+ // $ch->toSlot()->doApiCall - clear async-mode, than do..
86+
87+ $ ans = $ ch ->toSlot ()->doApiCall (0 , ['query ' => 'SELECT version() ' ]);
88+
89+ $ curl_error = $ ans ['curl_error ' ];
90+ if ($ curl_error ) {
91+ echo "\nCURL_ERROR: $ curl_error " ;
92+ $ this ->assertTrue (empty ($ curl_error ));
93+ } else {
94+ echo "Version response: {$ ans ['response ' ]}Starting tests... \n" ;
95+ }
96+
97+ $ slot = "tmp1 " ;
98+ $ ans = $ ch ->toSlot ($ slot )->doApiCall (false , ['query ' =>'SELECT 123 ' ]);
99+ $ this ->assertEquals (102 , $ ans ['code ' ]);
100+
101+ $ ch ->debug = true ;
102+ $ ch ->hook_before_api_call = function ($ url , $ obj ) {
103+ return "https://ierusalim.github.io " ;
104+ };
105+
106+ $ file = dirname (dirname (__DIR__ )) . DIRECTORY_SEPARATOR . '.gitignore ' ;
107+
108+ $ ans = $ ch ->doApiCall ("empty " , [], true , [], $ file );
109+ $ this ->assertEquals ($ ans ['code ' ], 405 );
110+
111+ $ this ->assertEquals ("123 \n" , $ ch ->fromSlot ($ slot )->results );
112+ }
113+
114+ /**
115+ * @covers ierusalim\ClickHouse\ClickHouseAPI::yiDoApiCall
116+ * @todo Implement testYiDoApiCall().
117+ */
118+ public function testYiDoApiCall ()
119+ {
120+ $ ch = $ this ->object ;
121+
122+ if ($ ch ->isSupported ('query ' )) {
123+ $ table = "anytabletmp " ;
124+
125+ $ file = 'anyfile.txt ' ;
126+
127+ $ file_data = '' ;
128+ for ($ t =1 ; $ t <100 ; $ t ++) {
129+ $ file_data .= $ t . "\t2017-12-12 \tAny string data \n" ;
130+ }
131+
132+ $ file_size = file_put_contents ($ file , $ file_data );
133+
134+ $ this ->assertTrue ($ file_size > 0 );
135+
136+ $ fields = '(id, dt, s) ' ;
137+ $ structure_excactly = 'id UInt32, dt Date, s String ' ;
138+
139+ $ ch ->query ("DROP TABLE IF EXISTS $ table " )
140+
141+ ->query ("CREATE TABLE $ table " .
142+ "( $ structure_excactly ) " .
143+ "ENGINE = MergeTree(dt, (id, dt), 8192) " );
144+
145+ $ ch ->is_windows = true ;
146+
147+ $ ans = $ ch ->doApiCall (false ,
148+ ['query ' => "INSERT INTO $ table $ fields FORMAT TabSeparated " ],
149+ true , [], $ file , true );
150+
151+ $ ch ->query ("SELECT * FROM $ table " );
152+ $ this ->assertEquals ($ file_data , $ ch ->results );
153+
154+ $ ch ->is_windows = false ;
155+
156+ try {
157+ $ ans = $ ch ->doApiCall (false ,
158+ ['query ' => "INSERT INTO $ table $ fields FORMAT TabSeparated " ],
159+ true , [], $ file , true );
160+ } catch (\Exception $ e ) {
161+ echo $ e ->getMessage ();
162+ \fclose ($ ch ->fh );
163+ }
164+
165+
166+ $ ch ->query ("DROP TABLE IF EXISTS $ table " );
167+ unlink ($ file );
168+ unlink ($ file . '.gz ' );
169+ $ slot = "tmp1 " ;
170+ $ ans = $ ch ->toSlot ($ slot )->doApiCall (false , ['query ' =>'SELECT 123 ' ]);
171+ $ this ->assertEquals (102 , $ ans ['code ' ]);
172+
173+ $ ch ->debug = true ;
174+
175+ $ ch ->hook_before_api_call = function ($ url , $ obj ) {
176+ return "https://ierusalim.github.io " ;
177+ };
178+
179+ $ file = dirname (dirname (__DIR__ )) . \DIRECTORY_SEPARATOR . '.gitignore ' ;
180+
181+ $ ans = $ ch ->doApiCall ("empty " , [], true , [], $ file );
182+ $ this ->assertEquals ($ ans ['code ' ], 405 );
183+
184+ $ this ->assertEquals ("123 \n" , $ ch ->fromSlot ($ slot )->results );
185+ }
186+ }
187+
77188 /**
78189 * @covers ierusalim\ClickHouse\ClickHouseAPI::getVersion
79190 */
@@ -356,105 +467,6 @@ public function testDoQuery()
356467 }
357468 }
358469
359- /**
360- * @covers ierusalim\ClickHouse\ClickHouseAPI::doApiCall
361- * @todo Implement testDoApiCall().
362- */
363- public function testDoApiCall ()
364- {
365- $ ch = $ this ->object ;
366-
367- $ slot = "tmp1 " ;
368- $ ans = $ ch ->toSlot ($ slot )->doApiCall (false , ['query ' =>'SELECT 123 ' ]);
369- $ this ->assertEquals (102 , $ ans ['code ' ]);
370-
371- $ ch ->debug = true ;
372- $ ch ->hook_before_api_call = function ($ url , $ obj ) {
373- return "https://ierusalim.github.io " ;
374- };
375-
376- $ file = dirname (dirname (__DIR__ )) . DIRECTORY_SEPARATOR . '.gitignore ' ;
377-
378- $ ans = $ ch ->doApiCall ("empty " , [], true , [], $ file );
379- $ this ->assertEquals ($ ans ['code ' ], 405 );
380-
381- $ this ->assertEquals ("123 \n" , $ ch ->fromSlot ($ slot )->results );
382- }
383-
384- /**
385- * @covers ierusalim\ClickHouse\ClickHouseAPI::yiDoApiCall
386- * @todo Implement testYiDoApiCall().
387- */
388- public function testYiDoApiCall ()
389- {
390- $ ch = $ this ->object ;
391-
392- if ($ ch ->isSupported ('query ' )) {
393- $ table = "anytabletmp " ;
394-
395- $ file = 'anyfile.txt ' ;
396-
397- $ file_data = '' ;
398- for ($ t =1 ; $ t <100 ; $ t ++) {
399- $ file_data .= $ t . "\t2017-12-12 \tAny string data \n" ;
400- }
401-
402- $ file_size = file_put_contents ($ file , $ file_data );
403-
404- $ this ->assertTrue ($ file_size > 0 );
405-
406- $ fields = '(id, dt, s) ' ;
407- $ structure_excactly = 'id UInt32, dt Date, s String ' ;
408-
409- $ ch ->query ("DROP TABLE IF EXISTS $ table " )
410-
411- ->query ("CREATE TABLE $ table " .
412- "( $ structure_excactly ) " .
413- "ENGINE = MergeTree(dt, (id, dt), 8192) " );
414-
415- $ ch ->is_windows = true ;
416-
417- $ ans = $ ch ->doApiCall (false ,
418- ['query ' => "INSERT INTO $ table $ fields FORMAT TabSeparated " ],
419- true , [], $ file , true );
420-
421- $ ch ->query ("SELECT * FROM $ table " );
422- $ this ->assertEquals ($ file_data , $ ch ->results );
423-
424- $ ch ->is_windows = false ;
425-
426- try {
427- $ ans = $ ch ->doApiCall (false ,
428- ['query ' => "INSERT INTO $ table $ fields FORMAT TabSeparated " ],
429- true , [], $ file , true );
430- } catch (\Exception $ e ) {
431- echo $ e ->getMessage ();
432- \fclose ($ ch ->fh );
433- }
434-
435-
436- $ ch ->query ("DROP TABLE IF EXISTS $ table " );
437- unlink ($ file );
438- unlink ($ file . '.gz ' );
439- $ slot = "tmp1 " ;
440- $ ans = $ ch ->toSlot ($ slot )->doApiCall (false , ['query ' =>'SELECT 123 ' ]);
441- $ this ->assertEquals (102 , $ ans ['code ' ]);
442-
443- $ ch ->debug = true ;
444-
445- $ ch ->hook_before_api_call = function ($ url , $ obj ) {
446- return "https://ierusalim.github.io " ;
447- };
448-
449- $ file = dirname (dirname (__DIR__ )) . \DIRECTORY_SEPARATOR . '.gitignore ' ;
450-
451- $ ans = $ ch ->doApiCall ("empty " , [], true , [], $ file );
452- $ this ->assertEquals ($ ans ['code ' ], 405 );
453-
454- $ this ->assertEquals ("123 \n" , $ ch ->fromSlot ($ slot )->results );
455- }
456- }
457-
458470 /**
459471 * @covers ierusalim\ClickHouse\ClickHouseAPI::setOption
460472 * @todo Implement testSetOption().
0 commit comments