1--TEST--
2PDO_Firebird: transaction isolation level (Testing for setting attribute values)
3--EXTENSIONS--
4pdo_firebird
5--SKIPIF--
6<?php require('skipif.inc'); ?>
7--XLEAK--
8A bug in firebird causes a memory leak when calling `isc_attach_database()`.
9See https://github.com/FirebirdSQL/firebird/issues/7849
10--FILE--
11<?php
12
13require("testdb.inc");
14$dbh = getDbConnection();
15unset($dbh);
16
17$levelStrs = [
18    'Pdo\\Firebird::READ_COMMITTED',
19    'Pdo\\Firebird::REPEATABLE_READ',
20    'Pdo\\Firebird::SERIALIZABLE',
21];
22
23echo "========== Set attr in construct ==========\n";
24
25foreach ($levelStrs as $levelStr) {
26    $level = constant($levelStr);
27    $dbh = new PDO(
28        PDO_FIREBIRD_TEST_DSN,
29        PDO_FIREBIRD_TEST_USER,
30        PDO_FIREBIRD_TEST_PASS,
31        [
32            Pdo\Firebird::TRANSACTION_ISOLATION_LEVEL => $level,
33        ],
34    );
35
36    if ($dbh->getAttribute(Pdo\Firebird::TRANSACTION_ISOLATION_LEVEL) === $level) {
37        echo "OK: {$levelStr}\n";
38    } else {
39        echo "NG: {$levelStr}\n";
40    }
41
42    unset($dbh);
43}
44
45echo "Invalid value\n";
46try {
47    $dbh = new PDO(
48        PDO_FIREBIRD_TEST_DSN,
49        PDO_FIREBIRD_TEST_USER,
50        PDO_FIREBIRD_TEST_PASS,
51        [
52            Pdo\Firebird::TRANSACTION_ISOLATION_LEVEL => PDO::ATTR_AUTOCOMMIT, // Invalid value
53        ],
54    );
55} catch (Throwable $e) {
56    echo $e->getMessage()."\n";
57}
58
59unset($dbh);
60
61echo "\n";
62echo "========== Set attr in setAttribute ==========\n";
63
64$dbh = new PDO(
65    PDO_FIREBIRD_TEST_DSN,
66    PDO_FIREBIRD_TEST_USER,
67    PDO_FIREBIRD_TEST_PASS,
68);
69
70foreach ($levelStrs as $levelStr) {
71    $level = constant($levelStr);
72
73    var_dump($dbh->setAttribute(Pdo\Firebird::TRANSACTION_ISOLATION_LEVEL, $level));
74
75    if ($dbh->getAttribute(Pdo\Firebird::TRANSACTION_ISOLATION_LEVEL) === $level) {
76        echo "OK: {$levelStr}\n";
77    } else {
78        echo "NG: {$levelStr}\n";
79    }
80}
81
82echo "Invalid value\n";
83try {
84    $dbh->setAttribute(Pdo\Firebird::TRANSACTION_ISOLATION_LEVEL, PDO::ATTR_AUTOCOMMIT); // Invalid value
85} catch (Throwable $e) {
86    echo $e->getMessage()."\n";
87}
88
89unset($dbh);
90?>
91--EXPECT--
92========== Set attr in construct ==========
93OK: Pdo\Firebird::READ_COMMITTED
94OK: Pdo\Firebird::REPEATABLE_READ
95OK: Pdo\Firebird::SERIALIZABLE
96Invalid value
97Pdo\Firebird::TRANSACTION_ISOLATION_LEVEL must be a valid transaction isolation level (Pdo\Firebird::READ_COMMITTED, Pdo\Firebird::REPEATABLE_READ, or Pdo\Firebird::SERIALIZABLE)
98
99========== Set attr in setAttribute ==========
100bool(true)
101OK: Pdo\Firebird::READ_COMMITTED
102bool(true)
103OK: Pdo\Firebird::REPEATABLE_READ
104bool(true)
105OK: Pdo\Firebird::SERIALIZABLE
106Invalid value
107Pdo\Firebird::TRANSACTION_ISOLATION_LEVEL must be a valid transaction isolation level (Pdo\Firebird::READ_COMMITTED, Pdo\Firebird::REPEATABLE_READ, or Pdo\Firebird::SERIALIZABLE)
108