I am kind of new to PHPUnit test so appreciate your help to see whether I'm following the right approach or not.
I'm trying to test my methods; I have two questions
1) How can I have my test database with dummy data? right now I have all of my database settings in pdo_connect class and in constructor of that class I'm doing all of the database initializations, including dbname, host,...; I have included my method that I want to test here and my test case as well; my question is whether it is a good practice to change my database for test based on different environments; for example if the 'environment' variable in my settings is 'test' I use the 'test' database which has dummy data and ...
2) Also I really appreciate it if you confirm my example test case which is mentioned below is the right way of functionality testing of my method!
static public function get_images($id) {
try {
$conn = new pdo_connect();
$query = " SELECT ....";
$result = $conn->prepare($query);
$result->bindParam(':id', $id);
$result->execute();
$array_result = $result->fetchAll(PDO::FETCH_OBJ);
$result_Set = array($paginate_result, TRUE);
}
catch (Exception $e) {
$result_Set = array($e->getMessage(), FALSE);
}
return $result_Set;
}
and my test:
class SomeTest extends PHPUnit_Framework_TestCase {
public function __construct() {
require_once('../includes/model.php');
}
public function test_id_not_exist() {
$con = $this->getMock('conn');
$dao = new Model($con);
$result = MODEL::get_images(555);
$expected = array(array(), True);
self::assertEquals($expected, $result);
}
}
Please let me know if you need more clarification... and again I appreciate it in advance...