This repository was archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
issue.global
Edson Medina edited this page Jul 7, 2017
·
10 revisions
function query ($sql)
{
global $db;
return $db->doQuery ($sql);
}
- Global variables can be changed outside of the scope of your function, so its behavior is unpredictable in a running environment.
- It would force your test to set globals, which could then affect subsequent tests that depend on the same globals.
- Unit-tests should only test units in isolation. Having external (global) dependencies breaks that rule.
function query ($sql, $db)
class foo
{
public function __construct ($db)
{
$this->db = $db;
}
public function query ($sql)
{
return $this->db->doQuery ($sql);
}
}
$db = $this->dbFactory->getInstance();