Skip to content

Commit 70566ef

Browse files
committed
add pdo simple test
1 parent 073a03f commit 70566ef

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@
5353
<scope>test</scope>
5454
</dependency>
5555

56+
<dependency>
57+
<groupId>jdbc.mysql</groupId>
58+
<artifactId>mysql-connector</artifactId>
59+
<version>5.1.5</version>
60+
<scope>test</scope>
61+
</dependency>
62+
5663
</dependencies>
5764
<build>
5865
<plugins>

src/test/java/com/caucho/quercus/QuercusBaseTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
*/
2828
public abstract class QuercusBaseTest {
2929
protected Quercus quercus;
30-
protected Env env;
3130
protected int timeout;
3231
protected Path path;
3332
protected String encode = "GBK";
@@ -44,6 +43,7 @@ public void setUp() throws Exception {
4443
}
4544

4645
protected String eval(InputStream in, Map<String, Object> context) {
46+
Env env = null;
4747
try {
4848
QuercusProgram program = QuercusParser.parse(quercus, path, Vfs.openRead(new InputStreamReader(in, encode)));
4949
Writer writer = new StringWriter();
@@ -59,12 +59,17 @@ protected String eval(InputStream in, Map<String, Object> context) {
5959
}
6060
simpleScriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
6161
env.setScriptContext(simpleScriptContext);
62+
env.start();
6263
program.execute(env);
6364
writerStream.flushBuffer();
6465
writerStream.free();
6566
return writer.toString();
6667
}catch (Exception e) {
6768
throw new RuntimeException(e);
69+
}finally {
70+
if (env != null) {
71+
env.close();
72+
}
6873
}
6974
}
7075

src/test/java/com/caucho/quercus/javaclssses/Java1Test.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.caucho.quercus.javaclssses;
22

33
import com.caucho.quercus.QuercusBaseTest;
4+
import org.junit.Assert;
45
import org.junit.Test;
56

67
/**
@@ -14,6 +15,6 @@ public class Java1Test extends QuercusBaseTest {
1415
public void test_php() {
1516
String path = "javaclasses/java1.php";
1617
String ret = evalFile(path) ;
17-
System.out.println(ret);
18+
Assert.assertNotNull(ret);
1819
}
1920
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.caucho.quercus.lib.db;
2+
3+
import com.caucho.quercus.QuercusBaseTest;
4+
import org.junit.Test;
5+
6+
/**
7+
* User: chao.liuc
8+
* Date: 13-5-8
9+
* Time: ÉÏÎç10:43
10+
*/
11+
public class PDOTest1 extends QuercusBaseTest {
12+
13+
@Test
14+
public void test_php() {
15+
String path = "lib/db/pdo1.php";
16+
String ret = evalFile(path) ;
17+
System.out.println(ret);
18+
}
19+
}

src/test/resources/lib/db/pdo1.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
$dbms='mysql';
3+
$host='localhost:3306';
4+
$dbname='test';
5+
$user='tae';
6+
$pass='tae';
7+
$dsn="$dbms:host=$host;dbname=$dbname";
8+
try{
9+
$dbh = new PDO($dsn, $user, $pass);
10+
foreach ($dbh->query('SELECT * from test') as $row) {
11+
print_r($row);
12+
}
13+
$dbh = null;
14+
}catch(PDOException $e){
15+
die("Error!:".$e->getMessage()."<br/>");
16+
}
17+
18+
?>

0 commit comments

Comments
 (0)