recently I came across Mockery Framework for PHP mock object. I have a class which has constructor which takes postgreSQL connection parameters and connects to database and other methods for DML operations. I want to write test cases for these methods without actual connecting to database, hence want to use Mockery.
Below is a simple example of DBConnection class. Could any one please give me a sample code for running test case for select method?
class DBConnection {
private $conn; //db connection
private $debug = false;
private $schema;
public function __construct($host, $user, $pass, $db, $schema = 'main', $debug = DEBUG) {
$this->debug = $debug;
$this->conn = pg_connect("host=$host user=$user password=$pass dbname=$db");
if(!$this->conn) {
throw new DatabaseException('Database connection failed');
}
}
public function select() {
$result = pg_prepare($this->conn, "my_query", 'SELECT * FROM shops WHERE name = $1');
$result = pg_execute($this->conn, "my_query", array("Joe's Widgets"));
return $result;
}
}