-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathRandomTest.php
110 lines (97 loc) · 3.18 KB
/
RandomTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
declare(strict_types=1);
namespace Atk4\Data\Tests\Persistence\Sql;
use Atk4\Core\Phpunit\TestCase;
use Atk4\Data\Persistence\Sql\Mysql;
use Atk4\Data\Persistence\Sql\Oracle;
use Atk4\Data\Persistence\Sql\Postgresql;
use Atk4\Data\Persistence\Sql\Query;
use Atk4\Data\Persistence\Sql\Sqlite;
/**
* @coversDefaultClass \Atk4\Data\Persistence\Sql\Query
*/
class RandomTest extends TestCase
{
/**
* @param string|array ...$args
*/
public function q(...$args): Query
{
return new Query(...$args);
}
public function testMiscInsert(): void
{
$data = [
'id' => null,
'system_id' => '3576',
'system' => null,
'created_dts' => 123,
'contractor_from' => null,
'contractor_to' => null,
'vat_rate_id' => null,
'currency_id' => null,
'vat_period_id' => null,
'journal_spec_id' => '147735',
'job_id' => '9341',
'nominal_id' => null,
'root_nominal_code' => null,
'doc_type' => null,
'is_cn' => 'N',
'doc_date' => null,
'ref_no' => '940 testingqq11111',
'po_ref' => null,
'total_gross' => '100.00',
'total_net' => null,
'total_vat' => null,
'exchange_rate' => null,
'note' => null,
'archive' => 'N',
'fx_document_id' => null,
'exchanged_total_net' => null,
'exchanged_total_gross' => null,
'exchanged_total_vat' => null,
'exchanged_total_a' => null,
'exchanged_total_b' => null,
];
$q = $this->q();
$q->mode('insert');
foreach ($data as $key => $val) {
$q->set($key, $val);
}
$this->assertSame(
'insert into ("' . implode('", "', array_keys($data)) . '") values (:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, :l, :m, :n, :o, :p, :q, :r, :s, :t, :u, :v, :w, :x, :y, :z, :aa, :ab, :ac, :ad)',
$q->render()[0]
);
}
/**
* Confirms that group concat works for all the SQL vendors we support.
*/
public function _groupConcatTest(string $expected, Query $q): void
{
$q->table('people');
$q->group('age');
$q->field('age');
$q->field($q->groupConcat('name', ','));
$q->groupConcat('name', ',');
$this->assertSame($expected, $q->render()[0]);
}
public function testGroupConcat(): void
{
$this->_groupConcatTest(
'select `age`, group_concat(`name` separator \',\') from `people` group by `age`',
new Mysql\Query()
);
$this->_groupConcatTest(
'select "age", group_concat("name", :a) from "people" group by "age"',
new Sqlite\Query()
);
$this->_groupConcatTest(
'select "age", string_agg("name", :a) from "people" group by "age"',
new Postgresql\Query()
);
$this->_groupConcatTest(
'select "age", listagg("name", :xxaaaa) within group (order by "name") from "people" group by "age"',
new Oracle\Query()
);
}
}