Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Skip known failing PDO tests #367

Merged
merged 6 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Xhgui/ServiceContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;';
}

Expand Down
1 change: 1 addition & 0 deletions tests/Controller/ImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function setUp()

public function testImportSuccess()
{
$this->skipIfPdo('getForUrl not implemented');
$data = [
'meta' => [
'url' => '/things?key=value',
Expand Down
4 changes: 4 additions & 0 deletions tests/Controller/RunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -189,6 +191,7 @@ public function testCallgraphData()

public function testDeleteSubmit()
{
$this->skipIfPdo('Undefined index: page');
$this->loadFixture($this->saver);

Environment::mock([
Expand Down Expand Up @@ -218,6 +221,7 @@ public function testDeleteSubmit()

public function testDeleteAllSubmit()
{
$this->skipIfPdo('Undefined index: page');
$this->loadFixture($this->saver);

Environment::mock([
Expand Down
2 changes: 2 additions & 0 deletions tests/Controller/WatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class WatchTest extends TestCase

public function setUp()
{
$this->skipIfPdo('Watchers not implemented');

parent::setUp();
Environment::mock([
'SCRIPT_NAME' => 'index.php',
Expand Down
2 changes: 2 additions & 0 deletions tests/Searcher/MongoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace XHGui\Test;

use XHGui\Saver\SaverInterface;
use XHGui\ServiceContainer;

abstract class TestCase extends \PHPUnit\Framework\TestCase
{
Expand All @@ -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);
}
}