Ideally, you should not use globals you are hiding dependencies and can cause things to happen due to changes in the global variable.
It would be possible for your to hack in and replace your variable so that you can mock it. You can use the setUp method to store what is in the global $DB and then restore it in the teardown() method. This way, you don't accidentally break some other test with your mock.
public function setUp() {
global $DB;
$this->oldDB = $DB;
}
public function testCreate() {
$mockDB = $this->getMock('PDO') ... //More steps to complete mock object
global $DB;
$DB = $mockDB;
//Rest of Test here
}
public function teardown() {
global $DB;
$DB = $this->oldDB;
}
Now just because you CAN do this, doesn't mean you SHOULD do this. It would be better to refactor your code so that it doesn't depend upon the global scope. But if that isn't an option at this time, here is a work around that will at least make the test usable until you refactor.