1--TEST--
2Test Pdo\Sqlite::createCollation() trampoline callback
3--EXTENSIONS--
4pdo_sqlite
5--FILE--
6<?php
7
8$db = new Pdo\Sqlite('sqlite::memory:');
9
10$db->query('CREATE TABLE test_pdo_sqlite_createcollation_trampoline (s VARCHAR(4))');
11
12$stmt = $db->query('INSERT INTO test_pdo_sqlite_createcollation_trampoline VALUES ("a1"), ("a10"), ("a2")');
13
14class TrampolineTest {
15    public function __call(string $name, array $arguments) {
16        echo 'Trampoline for ', $name, PHP_EOL;
17        return strnatcmp(...$arguments);
18    }
19}
20
21var_dump($db->createCollation('NAT', [new TrampolineTest(), 'NAT']));
22
23echo "default\n";
24foreach ($db->query('SELECT s FROM test_pdo_sqlite_createcollation_trampoline ORDER BY s') as $row) {
25    var_dump($row);
26}
27
28echo "natural\n";
29foreach ($db->query('SELECT s FROM test_pdo_sqlite_createcollation_trampoline ORDER BY s COLLATE NAT') as $row) {
30    var_dump($row);
31}
32
33?>
34--EXPECT--
35bool(true)
36default
37array(2) {
38  ["s"]=>
39  string(2) "a1"
40  [0]=>
41  string(2) "a1"
42}
43array(2) {
44  ["s"]=>
45  string(3) "a10"
46  [0]=>
47  string(3) "a10"
48}
49array(2) {
50  ["s"]=>
51  string(2) "a2"
52  [0]=>
53  string(2) "a2"
54}
55natural
56Trampoline for NAT
57Trampoline for NAT
58array(2) {
59  ["s"]=>
60  string(2) "a1"
61  [0]=>
62  string(2) "a1"
63}
64array(2) {
65  ["s"]=>
66  string(2) "a2"
67  [0]=>
68  string(2) "a2"
69}
70array(2) {
71  ["s"]=>
72  string(3) "a10"
73  [0]=>
74  string(3) "a10"
75}
76