|
| 1 | +<?php |
| 2 | + |
| 3 | +use PHPUnit\Framework\TestCase; |
| 4 | + |
| 5 | +/** |
| 6 | + * Class ClientTest |
| 7 | + */ |
| 8 | +class FormatQueryTest extends TestCase |
| 9 | +{ |
| 10 | + /** |
| 11 | + * @var \ClickHouseDB\Client |
| 12 | + */ |
| 13 | + private $db; |
| 14 | + |
| 15 | + /** |
| 16 | + * @var |
| 17 | + */ |
| 18 | + private $tmp_path; |
| 19 | + |
| 20 | + /** |
| 21 | + * @throws Exception |
| 22 | + */ |
| 23 | + public function setUp() |
| 24 | + { |
| 25 | + date_default_timezone_set('Europe/Moscow'); |
| 26 | + |
| 27 | + if (!defined('phpunit_clickhouse_host')) { |
| 28 | + throw new Exception("Not set phpunit_clickhouse_host in phpUnit.xml"); |
| 29 | + } |
| 30 | + |
| 31 | + $tmp_path = rtrim(phpunit_clickhouse_tmp_path, '/') . '/'; |
| 32 | + |
| 33 | + if (!is_dir($tmp_path)) { |
| 34 | + throw new Exception("Not dir in phpunit_clickhouse_tmp_path"); |
| 35 | + } |
| 36 | + |
| 37 | + $this->tmp_path = $tmp_path; |
| 38 | + |
| 39 | + $config = [ |
| 40 | + 'host' => phpunit_clickhouse_host, |
| 41 | + 'port' => phpunit_clickhouse_port, |
| 42 | + 'username' => phpunit_clickhouse_user, |
| 43 | + 'password' => phpunit_clickhouse_pass, |
| 44 | + |
| 45 | + ]; |
| 46 | + |
| 47 | + $this->db = new ClickHouseDB\Client($config); |
| 48 | + |
| 49 | + |
| 50 | + $this->db->ping(); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * |
| 55 | + */ |
| 56 | + public function tearDown() |
| 57 | + { |
| 58 | + // |
| 59 | + } |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + public function testCreateTableTEMPORARYNoSession() |
| 64 | + { |
| 65 | + $this->setUp(); |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + $query="SELECT 2*number as FORMAT FROM system.numbers LIMIT 1,1 format TSV"; |
| 70 | + $st = $this->db->select($query); |
| 71 | + $this->assertEquals($query, $st->sql()); |
| 72 | + $this->assertEquals('TSV', $st->getFormat()); |
| 73 | + $this->assertEquals("2\n", $st->rawData()); |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + $query="SELECT number as format_id FROM system.numbers LIMIT 3 FORMAT CSVWithNames"; |
| 78 | + $st = $this->db->select($query); |
| 79 | + $this->assertEquals($query, $st->sql()); |
| 80 | + $this->assertEquals('CSVWithNames', $st->getFormat()); |
| 81 | + $this->assertEquals("\"format_id\"\n0\n1\n2\n", $st->rawData()); |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + $query="SELECT number as format_id FROM system.numbers LIMIT 1,1 FORMAT CSV"; |
| 86 | + $st = $this->db->select($query); |
| 87 | + $this->assertEquals($query, $st->sql()); |
| 88 | + $this->assertEquals('CSV', $st->getFormat()); |
| 89 | + |
| 90 | + // |
| 91 | + |
| 92 | + |
| 93 | + } |
| 94 | + |
| 95 | + |
| 96 | +} |
0 commit comments