1
1
<?php
2
2
3
+ use PHPUnit \Framework \TestCase ;
3
4
use Swoole \Coroutine \PostgreSQL ;
4
5
use function Swoole \Coroutine \run ;
5
- use PHPUnit \Framework \TestCase ;
6
6
7
7
class PostgreSQLTest extends TestCase
8
8
{
9
- protected function getConn () {
9
+ protected function getConn ()
10
+ {
10
11
$ pg = new Swoole \Coroutine \PostgreSQL ();
11
12
$ conn = $ pg ->connect (TEST_DB_URI );
12
- $ this ->assertNotFalse ($ conn , (string )$ pg ->error );
13
+ $ this ->assertNotFalse ($ conn , (string ) $ pg ->error );
14
+
13
15
return $ pg ;
14
16
}
15
17
@@ -18,7 +20,7 @@ public function testEscape()
18
20
run (function () {
19
21
$ pg = $ this ->getConn ();
20
22
$ result = $ pg ->escape ("' or 1=1 & 2 " );
21
- $ this ->assertNotFalse ($ result , (string )$ pg ->error );
23
+ $ this ->assertNotFalse ($ result , (string ) $ pg ->error );
22
24
$ this ->assertEquals ("'' or 1=1 & 2 " , $ result );
23
25
});
24
26
}
@@ -29,7 +31,7 @@ public function testInsert()
29
31
$ pg = $ this ->getConn ();
30
32
$ result = $ pg ->query ("INSERT INTO weather(city, temp_lo, temp_hi, prcp, date)
31
33
VALUES ('Shanghai', 88, 10, 0.75,'1993-11-27') RETURNING id " );
32
- $ this ->assertNotFalse ($ result , (string )$ pg ->error );
34
+ $ this ->assertNotFalse ($ result , (string ) $ pg ->error );
33
35
$ this ->assertEquals (1 , $ pg ->numRows ($ result ));
34
36
$ this ->assertGreaterThan (1 , $ pg ->fetchAssoc ($ result )['id ' ]);
35
37
});
@@ -52,11 +54,25 @@ public function testQuery()
52
54
run (function () {
53
55
$ pg = $ this ->getConn ();
54
56
$ result = $ pg ->query ('SELECT * FROM weather; ' );
55
- $ this ->assertNotFalse ($ result , (string )$ pg ->error );
57
+ $ this ->assertNotFalse ($ result , (string ) $ pg ->error );
56
58
57
59
$ arr = $ pg ->fetchAll ($ result );
58
60
$ this ->assertIsArray ($ arr );
59
61
$ this ->assertEquals ($ arr [0 ]['city ' ], 'San Francisco ' );
60
62
});
61
63
}
64
+
65
+ public function testNoFieldName ()
66
+ {
67
+ run (function () {
68
+ $ pg = $ this ->getConn ();
69
+ $ result = $ pg ->query ('SELECT 11, 22 ' );
70
+ $ this ->assertNotFalse ($ result , (string ) $ pg ->error );
71
+
72
+ $ arr = $ pg ->fetchAll ($ result );
73
+ $ this ->assertIsArray ($ arr );
74
+ $ this ->assertEquals ($ arr [0 ]['?column? ' ], 11 );
75
+ $ this ->assertEquals ($ arr [0 ]['?column?1 ' ], 22 );
76
+ });
77
+ }
62
78
}
0 commit comments