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
});
@@ -40,11 +42,25 @@ public function testQuery()
40
42
run (function () {
41
43
$ pg = $ this ->getConn ();
42
44
$ result = $ pg ->query ('SELECT * FROM weather; ' );
43
- $ this ->assertNotFalse ($ result , (string )$ pg ->error );
45
+ $ this ->assertNotFalse ($ result , (string ) $ pg ->error );
44
46
45
47
$ arr = $ pg ->fetchAll ($ result );
46
48
$ this ->assertIsArray ($ arr );
47
49
$ this ->assertEquals ($ arr [0 ]['city ' ], 'San Francisco ' );
48
50
});
49
51
}
52
+
53
+ public function testNoFieldName ()
54
+ {
55
+ run (function () {
56
+ $ pg = $ this ->getConn ();
57
+ $ result = $ pg ->query ('SELECT 11, 22 ' );
58
+ $ this ->assertNotFalse ($ result , (string ) $ pg ->error );
59
+
60
+ $ arr = $ pg ->fetchAll ($ result );
61
+ $ this ->assertIsArray ($ arr );
62
+ $ this ->assertEquals ($ arr [0 ]['?column? ' ], 11 );
63
+ $ this ->assertEquals ($ arr [0 ]['?column?1 ' ], 22 );
64
+ });
65
+ }
50
66
}
0 commit comments