1--TEST--
2Handling OCI_SUCCESS_WITH_INFO
3--EXTENSIONS--
4pdo
5pdo_oci
6--XFAIL--
7This test frequently fails in CI
8--SKIPIF--
9<?php
10if (getenv('SKIP_SLOW_TESTS')) die('skip slow tests excluded by request');
11?>
12--FILE--
13<?php
14
15function connectAsAdmin(): PDO {
16    return PDOTest::test_factory(__DIR__ . '/../../pdo_oci/tests/common.phpt');
17}
18
19function connectAsUser(string $username, string $password): PDO {
20    return new PDO(getenv('PDOTEST_DSN'), $username, $password);
21}
22
23function dropProfile(PDO $conn): void {
24    $conn->exec(<<<'SQL'
25BEGIN
26    EXECUTE IMMEDIATE 'DROP PROFILE BUG77120_PROFILE CASCADE';
27EXCEPTION
28    WHEN OTHERS THEN
29        IF SQLCODE != -2380 THEN
30            RAISE;
31        END IF;
32END;
33SQL
34    );
35}
36
37function dropUser(PDO $conn): void {
38    $conn->exec(<<<'SQL'
39BEGIN
40    EXECUTE IMMEDIATE 'DROP USER BUG77120_USER CASCADE';
41EXCEPTION
42    WHEN OTHERS THEN
43        IF SQLCODE != -1918 THEN
44            RAISE;
45        END IF;
46END;
47SQL
48    );
49}
50
51function triggerCompilationError(PDO $conn): void {
52    $conn->exec(<<<'SQL'
53CREATE OR REPLACE FUNCTION BUG77120(INT A) RETURN INT
54AS
55BEGIN
56    RETURN 0;
57END;
58SQL
59    );
60}
61
62require __DIR__ . '/../../pdo/tests/pdo_test.inc';
63
64$conn = connectAsAdmin();
65
66dropUser($conn);
67dropProfile($conn);
68
69$password = bin2hex(random_bytes(8));
70
71$conn->exec('CREATE PROFILE BUG77120_PROFILE LIMIT PASSWORD_LIFE_TIME 1/86400 PASSWORD_GRACE_TIME 1');
72$conn->exec('CREATE USER BUG77120_USER IDENTIFIED BY "' . $password . '" PROFILE BUG77120_PROFILE');
73$conn->exec('GRANT CREATE SESSION TO BUG77120_USER');
74
75// let the password expire
76sleep(3); // 2 seconds is causing random test failures
77
78$conn = connectAsUser('BUG77120_USER', $password);
79var_dump($conn->errorInfo());
80
81$conn = connectAsAdmin();
82dropUser($conn);
83dropProfile($conn);
84
85$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
86triggerCompilationError($conn);
87var_dump($conn->errorInfo());
88
89$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
90triggerCompilationError($conn);
91var_dump($conn->errorInfo());
92
93?>
94--EXPECTF--
95array(3) {
96  [0]=>
97  string(5) "HY000"
98  [1]=>
99  int(28002)
100  [2]=>
101  string(%d) "OCISessionBegin: OCI_SUCCESS_WITH_INFO: ORA-28002: %s
102 (%s:%d)"
103}
104array(3) {
105  [0]=>
106  string(5) "HY000"
107  [1]=>
108  int(24344)
109  [2]=>
110  string(%d) "OCIStmtExecute: OCI_SUCCESS_WITH_INFO: ORA-24344: %s
111 (%s:%d)"
112}
113array(3) {
114  [0]=>
115  string(5) "HY000"
116  [1]=>
117  int(24344)
118  [2]=>
119  string(%d) "OCIStmtExecute: OCI_SUCCESS_WITH_INFO: ORA-24344: %s
120 (%s:%d)"
121}
122