-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Tests] Optimized pdo_odbc tests #12654
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
$env = [ | ||
'PDO_ODBC_TEST_DSN' => false !== getenv('PDO_ODBC_TEST_DSN') ? getenv('PDO_ODBC_TEST_DSN') : '', | ||
'PDO_ODBC_TEST_USER' => false !== getenv('PDO_ODBC_TEST_USER') ? getenv('PDO_ODBC_TEST_USER') : null, | ||
'PDO_ODBC_TEST_PASS' => false !== getenv('PDO_ODBC_TEST_PASS') ? getenv('PDO_ODBC_TEST_PASS') : null, | ||
'PDO_ODBC_TEST_ATTR' => false !== getenv('PDO_ODBC_TEST_ATTR') ? getenv('PDO_ODBC_TEST_ATTR') : null, | ||
]; | ||
|
||
if (!$env['PDO_ODBC_TEST_DSN'] && preg_match('/^WIN/i', PHP_OS) && extension_loaded('com_dotnet')) { | ||
// on Windows and user didn't set PDOTEST_DSN, try this as a fallback: | ||
// check if MS Access DB is installed, and if yes, try using it. create a temporary MS access database. | ||
|
||
$path = realpath(__DIR__) . '\..\pdo_odbc.mdb'; | ||
if (!file_exists($path)) { | ||
try { | ||
// try to create database | ||
$adox = new COM('ADOX.Catalog'); | ||
$adox->Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' . $path); | ||
$adox = null; | ||
|
||
} catch (Exception $e) { | ||
// do nothing | ||
} | ||
} | ||
if (file_exists($path)) { | ||
// database was created and written to file system | ||
$env['PDO_ODBC_TEST_DSN'] = 'odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=$path;Uid=Admin'; | ||
} | ||
} | ||
?> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
require_once __DIR__ . '/config.inc'; | ||
require_once __DIR__ . '/../../../../ext/pdo/tests/pdo_test.inc'; | ||
|
||
foreach ($env as $k => $v) { | ||
define($k, $v); | ||
} | ||
|
||
class ODBCPDOTest extends PDOTest { | ||
|
||
static function factory($classname = 'PDO') { | ||
$dsn = PDO_ODBC_TEST_DSN; | ||
$user = PDO_ODBC_TEST_USER; | ||
$pass = PDO_ODBC_TEST_PASS; | ||
$attr = PDO_ODBC_TEST_ATTR; | ||
|
||
$attr = is_string($attr) && strlen($attr) ? unserialize($attr) : null; | ||
|
||
$db = new $classname($dsn, $user, $pass, $attr); | ||
if (!$db) { | ||
die("Could not create PDO object (DSN=$dsn, user=$user)\n"); | ||
} | ||
|
||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); | ||
$db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); | ||
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); | ||
|
||
return $db; | ||
} | ||
|
||
static function skip() { | ||
if (substr(PHP_OS, 0, 3) == 'WIN' && | ||
PDO_ODBC_TEST_DSN === '' && | ||
!extension_loaded('com_dotnet') | ||
) { | ||
die('skip - either PDOTEST_DSN or com_dotnet extension is needed to setup the connection'); | ||
} | ||
|
||
try { | ||
$db = self::factory(); | ||
} catch (PDOException $e) { | ||
die('skip could not connect'); | ||
} | ||
Comment on lines
+39
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to eventually make parent skip like this, but the scope is too wide, so I won't change it yet in this PR. |
||
} | ||
|
||
static function skipWithUnixODBC() { | ||
if (PDO_ODBC_TYPE === "unixODBC") { | ||
die("skip Fails with unixODBC"); | ||
} | ||
} | ||
|
||
static function skipNoDirect() { | ||
$dsn = PDO_ODBC_TEST_DSN; | ||
if (!$dsn || strpos($dsn, '=') === false) { | ||
die('skip this test is for direct connections only.'); | ||
} | ||
} | ||
|
||
static function skipToofewCredentials() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: should be |
||
if (PDO_ODBC_TEST_DSN === '' || PDO_ODBC_TEST_USER === null || PDO_ODBC_TEST_PASS === null) { | ||
die('skip too few credentials.'); | ||
} | ||
} | ||
} | ||
?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General comment on the pattern: I like removing the hardcoded table names from the query strings. It’s a little annoying that it has to be hardcoded here after it was unhardcoded for all the tests in their
FILE
sections, but I see why you probably didn’t do it forCLEAN
(it’d be an ugly use ofENV
/ARGS
, and I’m not sure if those get propagated toCLEAN
to begin with).