简体   繁体   中英

Unable to reference mysqli in PHPStorm, using PHPUnit

On my Windows 7 machine, with PHP v5.6.7 and MySQL v5.6.23, and using PHPStorm 8, I am attempting to instantiate a mysqli object within a PHPUnit test. When I try, I get:

Fatal error: Class 'mysqli' not found in...

If I am running the project as a "Built-in Web Server," it IS able to instantiate mysqli objects. Just not when using PHPUnit. Also, I am able to get other autoloaded classes that that I create in PHPUnit tests. The combination of PHPUnit test and mysqli specifically fails.

Here is regular server code that works:

include_once("app/MysqliFactory.php");
use HeloAuth\Sql\MysqliFactory;
$object = MysqliFactory::create();
echo "Success";

, and here is the unit test code that does not:

namespace HeloAuth\Sql;
include_once("MysqliFactory.php");
use PHPUnit_Framework_TestCase;

class MysqliFactoryTest extends PHPUnit_Framework_TestCase {

    public function testCreate_shouldReturnValidMysqli()
    {
        $actual = MysqliFactory::create();
    }
}

MysqliFactory does nothing but create a new mysqli object with the right host, user, etc.

Is the mysqli being loaded in the CLI? It could be loaded in web requests, but not on the command line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM