xref: /PHP-5.4/ext/pdo_odbc/tests/common.phpt (revision bd394953)
1--TEST--
2ODBC
3--SKIPIF--
4<?php # vim:ft=php
5if (!extension_loaded('pdo_odbc')) print 'skip';
6if (substr(PHP_OS, 0, 3) == 'WIN' &&
7	false === getenv('PDOTEST_DSN') &&
8	false === getenv('PDO_ODBC_TEST_DSN') &&
9	!extension_loaded('com_dotnet')) {
10	die('skip - either PDOTEST_DSN or com_dotnet extension is needed to setup the connection');
11}
12--REDIRECTTEST--
13# magic auto-configuration
14
15$config = array(
16	'TESTS' => 'ext/pdo/tests',
17	'ENV' => array()
18);
19
20// try loading PDO driver using ENV vars and if none given, and on Windows, try using MS Access
21// and if not, skip the test
22//
23// try to use common PDO env vars, instead of PDO_ODBC specific
24if (false !== getenv('PDOTEST_DSN')) {
25	// user should have to set PDOTEST_DSN so that:
26	// 1. test is skipped if user doesn't want to test it, even if they have MS Access installed
27	// 2. it detects if ODBC driver is not installed - to avoid test bug
28	// 3. it detects if ODBC driver is installed - so test will be run
29	// 4. so a specific ODBC driver can be tested - if system has multiple ODBC drivers
30
31	$config['ENV']['PDOTEST_DSN'] = getenv('PDOTEST_DSN');
32	$config['ENV']['PDOTEST_USER'] = getenv('PDOTEST_USER');
33	$config['ENV']['PDOTEST_PASS'] = getenv('PDOTEST_PASS');
34	if (false !== getenv('PDOTEST_ATTR')) {
35		$config['ENV']['PDOTEST_ATTR'] = getenv('PDOTEST_ATTR');
36	}
37} else if (false !== getenv('PDO_ODBC_TEST_DSN')) {
38	// user set these from their shell instead
39	$config['ENV']['PDOTEST_DSN'] = getenv('PDO_ODBC_TEST_DSN');
40	$config['ENV']['PDOTEST_USER'] = getenv('PDO_ODBC_TEST_USER');
41	$config['ENV']['PDOTEST_PASS'] = getenv('PDO_ODBC_TEST_PASS');
42	if (false !== getenv('PDO_ODBC_TEST_ATTR')) {
43		$config['ENV']['PDOTEST_ATTR'] = getenv('PDO_ODBC_TEST_ATTR');
44	}
45} elseif (preg_match('/^WIN/i', PHP_OS)) {
46	// on Windows and user didn't set PDOTEST_DSN, try this as a fallback:
47	// check if MS Access DB is installed, and if yes, try using it. create a temporary MS access database.
48	//
49	$path = realpath(dirname(__FILE__)) . '\pdo_odbc.mdb';
50	if (!file_exists($path)) {
51		try {
52			// try to create database
53			$adox = new COM('ADOX.Catalog');
54			$adox->Create('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' . $path);
55			$adox = null;
56
57		} catch (Exception $e) {
58		}
59	}
60	if (file_exists($path)) {
61		// database was created and written to file system
62		$config['ENV']['PDOTEST_DSN'] = "odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=$path;Uid=Admin";
63	} // else: $config['ENV']['PDOTEST_DSN'] not set
64} // else: $config['ENV']['PDOTEST_DSN'] not set
65//         test will be skipped. see SKIPIF section of long_columns.phpt
66
67# other magic autodetection here, eg: for DB2 by inspecting env
68/*
69$USER = 'db2inst1';
70$PASSWD = 'ibmdb2';
71$DBNAME = 'SAMPLE';
72
73$CONNECTION = "odbc:DSN=$DBNAME;UID=$USER;PWD=$PASSWD;";
74*/
75
76
77return $config;
78