diff --git a/src/Xhgui/ServiceContainer.php b/src/Xhgui/ServiceContainer.php index e53971532..f1e357767 100644 --- a/src/Xhgui/ServiceContainer.php +++ b/src/Xhgui/ServiceContainer.php @@ -114,12 +114,19 @@ protected function _services() throw new RuntimeException('Required extension ext-pdo is missing'); } - $adapter = explode(':', $c['config']['pdo']['dsn'], 2)[0]; + $driver = explode(':', $c['config']['pdo']['dsn'], 2)[0]; + + // check the PDO driver is available + if (!in_array($driver, PDO::getAvailableDrivers(), true)) { + $drivers = implode(',', PDO::getAvailableDrivers()) ?: '(none)'; + throw new RuntimeException("Required PDO driver $driver is missing, Available drivers: $drivers"); + } + $options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, ]; - if ($adapter === 'mysql') { + if ($driver === 'mysql') { $options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SQL_MODE=ANSI_QUOTES;'; } diff --git a/tests/Controller/ImportTest.php b/tests/Controller/ImportTest.php index bc91b2d39..ab015d2a8 100644 --- a/tests/Controller/ImportTest.php +++ b/tests/Controller/ImportTest.php @@ -40,6 +40,7 @@ public function setUp() public function testImportSuccess() { + $this->skipIfPdo('getForUrl not implemented'); $data = [ 'meta' => [ 'url' => '/things?key=value', diff --git a/tests/Controller/RunTest.php b/tests/Controller/RunTest.php index 9dc84b19f..a80235437 100644 --- a/tests/Controller/RunTest.php +++ b/tests/Controller/RunTest.php @@ -110,6 +110,8 @@ public function testIndexWithSearch() public function testUrl() { + $this->skipIfPdo('getForUrl is not implemented'); + Environment::mock([ 'SCRIPT_NAME' => 'index.php', 'PATH_INFO' => '/url/view', @@ -189,6 +191,7 @@ public function testCallgraphData() public function testDeleteSubmit() { + $this->skipIfPdo('Undefined index: page'); $this->loadFixture($this->saver); Environment::mock([ @@ -218,6 +221,7 @@ public function testDeleteSubmit() public function testDeleteAllSubmit() { + $this->skipIfPdo('Undefined index: page'); $this->loadFixture($this->saver); Environment::mock([ diff --git a/tests/Controller/WatchTest.php b/tests/Controller/WatchTest.php index cb5b6a8da..46650082b 100644 --- a/tests/Controller/WatchTest.php +++ b/tests/Controller/WatchTest.php @@ -20,6 +20,8 @@ class WatchTest extends TestCase public function setUp() { + $this->skipIfPdo('Watchers not implemented'); + parent::setUp(); Environment::mock([ 'SCRIPT_NAME' => 'index.php', diff --git a/tests/Searcher/MongoTest.php b/tests/Searcher/MongoTest.php index 7f8328c15..379fb9ccb 100644 --- a/tests/Searcher/MongoTest.php +++ b/tests/Searcher/MongoTest.php @@ -16,6 +16,8 @@ class MongoTest extends TestCase public function setUp() { + $this->skipIfPdo('This is MongoDB test'); + $di = ServiceContainer::instance(); $this->mongo = $di['searcher.mongodb']; diff --git a/tests/TestCase.php b/tests/TestCase.php index f09c5155d..9eb01c4a7 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,6 +3,7 @@ namespace XHGui\Test; use XHGui\Saver\SaverInterface; +use XHGui\ServiceContainer; abstract class TestCase extends \PHPUnit\Framework\TestCase { @@ -17,4 +18,19 @@ protected function loadFixture(SaverInterface $saver, string $fileName = 'result $saver->save($record, $record['_id'] ?? null); } } + + protected function skipIfPdo($details = null) + { + $saveHandler = ServiceContainer::instance()['config']['save.handler']; + + if ($saveHandler !== 'pdo') { + return; + } + + $message = 'PDO support is not complete'; + if ($details) { + $message .= ': ' . $details; + } + $this->markTestIncomplete($message); + } }