|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ClickHouseDB\Tests; |
| 4 | + |
| 5 | +use ClickHouseDB\Quote\StrictQuoteLine; |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | + |
| 8 | +class StrictQuoteLineTest extends TestCase |
| 9 | +{ |
| 10 | + use WithClient; |
| 11 | + |
| 12 | + public function setUp() |
| 13 | + { |
| 14 | + $this->client->write('DROP TABLE IF EXISTS cities'); |
| 15 | + $this->client->write(' |
| 16 | + CREATE TABLE IF NOT EXISTS cities ( |
| 17 | + date Date, |
| 18 | + city String, |
| 19 | + keywords Array(String), |
| 20 | + nums Array(UInt8) |
| 21 | + ) ENGINE = MergeTree(date, (date), 8192) |
| 22 | + '); |
| 23 | + parent::setUp(); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @group test |
| 28 | + */ |
| 29 | + public function testQuoteValueCSV() |
| 30 | + { |
| 31 | + $strict = new StrictQuoteLine('CSV'); |
| 32 | + |
| 33 | + $rows = [ |
| 34 | + ['2018-04-01', '"That works"', ['\"That does not\"', 'That works'], [8, 7]], |
| 35 | + ['2018-04-02', 'That works', ['\""That does not\""', '"\'\""That works"""\"'], [1, 0]], |
| 36 | + ['2018-04-03', 'That works', ['\"\"That does not"\'""', '""""That works""""'], [9, 121]], |
| 37 | + ]; |
| 38 | + $fileName = $this->tmpPath . '__test_quote_value.csv'; |
| 39 | + |
| 40 | + @unlink($fileName); |
| 41 | + foreach ($rows as $row) { |
| 42 | + file_put_contents($fileName, $strict->quoteRow($row) . "\n", FILE_APPEND); |
| 43 | + } |
| 44 | + |
| 45 | + $this->client->insertBatchFiles('cities', [$fileName], ['date', 'city', 'keywords', 'nums']); |
| 46 | + $statement = $this->client->select('SELECT * FROM cities'); |
| 47 | + |
| 48 | + $result = array_map('array_values', $statement->rows()); |
| 49 | + foreach ($result as $key => $value) { |
| 50 | + // check correct quote string |
| 51 | + $this->assertEmpty(array_diff($rows[$key][2], $value[2])); |
| 52 | + $this->assertEmpty(array_diff($rows[$key][3], $value[3])); |
| 53 | + } |
| 54 | + |
| 55 | + $rows[0][2][1] = 'Not the same string'; |
| 56 | + $this->assertCount(1, array_diff($rows[0][2], $result[0][2])); |
| 57 | + } |
| 58 | +} |
0 commit comments