1--TEST--
2Test Pdo\Sqlite::createAggregate() 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_createaggregate_trampoline (a INTEGER, b INTEGER)');
11
12$stmt = $db->query('INSERT INTO test_pdo_sqlite_createaggregate_trampoline VALUES (1, -1), (2, -2), (3, -3), (4, -4), (4, -4)');
13
14class TrampolineTest {
15    public function __call(string $name, array $arguments) {
16        echo 'Trampoline for ', $name, PHP_EOL;
17        $context = $arguments[0];
18        if ($name === 'finalize') {
19            return implode(',', $context['values']);
20        }
21        if (empty($context)) {
22            $context = ['total' => 0, 'values' => []];
23        }
24        $context['total'] += (int) $arguments[2];
25        $context['values'][] = $context['total'];
26        return $context;
27    }
28}
29
30var_dump($db->createAggregate('S', [new TrampolineTest(), 'step'], [new TrampolineTest(), 'finalize'], 1));
31
32foreach ($db->query('SELECT S(a), S(b) FROM test_pdo_sqlite_createaggregate_trampoline') as $row) {
33    var_dump($row);
34}
35
36?>
37--EXPECT--
38bool(true)
39Trampoline for step
40Trampoline for step
41Trampoline for step
42Trampoline for step
43Trampoline for step
44Trampoline for step
45Trampoline for step
46Trampoline for step
47Trampoline for step
48Trampoline for step
49Trampoline for finalize
50Trampoline for finalize
51array(4) {
52  ["S(a)"]=>
53  string(11) "1,3,6,10,14"
54  [0]=>
55  string(11) "1,3,6,10,14"
56  ["S(b)"]=>
57  string(16) "-1,-3,-6,-10,-14"
58  [1]=>
59  string(16) "-1,-3,-6,-10,-14"
60}
61