我有一堂课,我正在编写使用 SimpleTest 的测试。类中有静态函数需要传递给我的 SQL 连接对象,它位于 Variables.php 中。我该怎么做呢?
<?
require_once('../Variables.php');
class TestOfMember extends UnitTestCase {
function testGetMembersFromEmailAddress() {
$this->assertTrue($Member::getMembersFromEmailAddress("xxx@xxx.com", $conn)==null);
$this->assertTrue($Member::getMembersFromEmailAddress("xxx@gmail.com", $conn)!=null);
}
}
?>
class Member {
public static function getMembersFromEmailAddress($emailAddress, $conn) {
$args = array();
$args[] = $conn;
try {
$result = $conn->query("SELECT * FROM members WHERE Members_Email ='" . $emailAddress . "'");
$members = $result->fetchAll(PDO::FETCH_CLASS, 'Member', $args);
return $members;
} catch (PDOException $e) {
echo $e->getMessage();
}
}
}