1--TEST--
2PDO PgSQL pgsqlCopyFromArray using Generator
3--EXTENSIONS--
4pdo_pgsql
5--SKIPIF--
6<?php
7require __DIR__ . '/config.inc';
8require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
9PDOTest::skip();
10?>
11--FILE--
12<?php
13require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
14$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
15$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
16$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
17
18$db->exec('CREATE TABLE test_copy_from_generator (v int)');
19
20$generator = (function(){
21    $position = 0;
22    $values = [1, 1, 2, 3, 5];
23
24    while(isset($values[$position])){
25        yield $values[$position];
26        ++$position;
27    }
28})();
29
30
31$db->pgsqlCopyFromArray('test_copy_from_generator',$generator);
32
33$stmt = $db->query("select * from test_copy_from_generator order by 1");
34$result = $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
35var_export($result);
36
37?>
38--CLEAN--
39<?php
40require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
41$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
42$db->query('DROP TABLE IF EXISTS test_copy_from_generator CASCADE');
43?>
44--EXPECT--
45array (
46  0 => 1,
47  1 => 1,
48  2 => 2,
49  3 => 3,
50  4 => 5,
51)
52