mirror of
https://github.com/dg/dibi.git
synced 2025-08-07 06:36:44 +02:00
tests: improved testing environment
This commit is contained in:
@@ -11,7 +11,7 @@ matrix:
|
|||||||
- php: hhvm
|
- php: hhvm
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- vendor/bin/tester tests -s -c tests/php-unix.ini
|
- vendor/bin/tester tests -s -p php -c tests/php-unix.ini
|
||||||
- php code-checker/src/code-checker.php
|
- php code-checker/src/code-checker.php
|
||||||
|
|
||||||
after_failure:
|
after_failure:
|
||||||
@@ -22,3 +22,9 @@ before_script:
|
|||||||
# Install Nette Tester & Code Checker
|
# Install Nette Tester & Code Checker
|
||||||
- composer install --no-interaction --dev --prefer-source
|
- composer install --no-interaction --dev --prefer-source
|
||||||
- composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source
|
- composer create-project nette/code-checker code-checker ~2.3 --no-interaction --prefer-source
|
||||||
|
|
||||||
|
# Create databases.ini
|
||||||
|
- cp ./tests/databases.sample.ini ./tests/databases.ini
|
||||||
|
|
||||||
|
# Create Postgre database
|
||||||
|
- psql -c 'CREATE DATABASE dibi_test' -U postgres
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"tracy/tracy": "~2.2",
|
"tracy/tracy": "~2.2",
|
||||||
"nette/tester": "~1.1"
|
"nette/tester": "~1.3"
|
||||||
},
|
},
|
||||||
"replace": {
|
"replace": {
|
||||||
"dg/dibi": "self.version"
|
"dg/dibi": "self.version"
|
||||||
|
6
tests/.gitignore
vendored
6
tests/.gitignore
vendored
@@ -1,4 +1,4 @@
|
|||||||
/*/output
|
output
|
||||||
/coverage.dat
|
|
||||||
/test.log
|
|
||||||
/tmp
|
/tmp
|
||||||
|
/test.log
|
||||||
|
/databases.ini
|
||||||
|
76
tests/databases.sample.ini
Normal file
76
tests/databases.sample.ini
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
[mysql]
|
||||||
|
driver = mysql
|
||||||
|
host = 127.0.0.1
|
||||||
|
username = root
|
||||||
|
password =
|
||||||
|
charset = utf8
|
||||||
|
system = mysql
|
||||||
|
|
||||||
|
[mysqli]
|
||||||
|
driver = mysqli
|
||||||
|
host = 127.0.0.1
|
||||||
|
username = root
|
||||||
|
password =
|
||||||
|
charset = utf8
|
||||||
|
system = mysql
|
||||||
|
|
||||||
|
[sqlite2]
|
||||||
|
driver = sqlite
|
||||||
|
database = :memory:
|
||||||
|
system = sqlite
|
||||||
|
|
||||||
|
[sqlite3] ; default
|
||||||
|
driver = sqlite3
|
||||||
|
database = :memory:
|
||||||
|
system = sqlite
|
||||||
|
|
||||||
|
[pgsql]
|
||||||
|
driver = postgre
|
||||||
|
host = 127.0.0.1
|
||||||
|
username = postgres
|
||||||
|
password =
|
||||||
|
system = pgsql
|
||||||
|
|
||||||
|
[odbc]
|
||||||
|
driver = odbc
|
||||||
|
dsn = "Driver={Microsoft Access Driver (*.mdb)}Dbq=data/odbc_tmp.mdb"
|
||||||
|
system = odbc
|
||||||
|
|
||||||
|
[mssql]
|
||||||
|
driver = mssql
|
||||||
|
host = 127.0.0.1
|
||||||
|
username = dibi
|
||||||
|
password =
|
||||||
|
system = mssql
|
||||||
|
|
||||||
|
[mssql2005]
|
||||||
|
driver = mssql2005
|
||||||
|
host = (local)
|
||||||
|
username = dibi
|
||||||
|
password =
|
||||||
|
system = mssql
|
||||||
|
|
||||||
|
[oracle]
|
||||||
|
driver = oracle
|
||||||
|
username = dibi
|
||||||
|
password =
|
||||||
|
system = oracle
|
||||||
|
|
||||||
|
[sqlite-pdo]
|
||||||
|
driver = pdo
|
||||||
|
dsn = "sqlite::memory:"
|
||||||
|
system = sqlite
|
||||||
|
|
||||||
|
[mysql-pdo]
|
||||||
|
driver = pdo
|
||||||
|
dsn = "mysql:host=127.0.0.1"
|
||||||
|
username = root
|
||||||
|
password =
|
||||||
|
system = mysql
|
||||||
|
|
||||||
|
[pgsql-pdo]
|
||||||
|
driver = pdo
|
||||||
|
dsn = "pgsql:host=127.0.0.1;dbname=dibi_test"
|
||||||
|
username = postgres
|
||||||
|
password =
|
||||||
|
system = pgsql
|
@@ -1,40 +1,35 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* Test: Cloning of DibiFluent
|
|
||||||
*
|
|
||||||
* @author David Grudl
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Tester\Assert;
|
use Tester\Assert;
|
||||||
|
|
||||||
require __DIR__ . '/bootstrap.php';
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
|
|
||||||
dibi::connect($config['sqlite3']);
|
$conn = new DibiConnection($config);
|
||||||
|
|
||||||
|
$fluent = new DibiFluent($conn);
|
||||||
$fluent = new DibiFluent(dibi::getConnection());
|
|
||||||
$fluent->select('*')->from('table')->where('x=1');
|
$fluent->select('*')->from('table')->where('x=1');
|
||||||
$dolly = clone $fluent;
|
$dolly = clone $fluent;
|
||||||
$dolly->where('y=1');
|
$dolly->where('y=1');
|
||||||
$dolly->clause('FOO');
|
$dolly->clause('FOO');
|
||||||
|
|
||||||
Assert::same( 'SELECT * FROM [table] WHERE x=1', (string) $fluent );
|
Assert::same( reformat('SELECT * FROM [table] WHERE x=1'), (string) $fluent );
|
||||||
Assert::same( 'SELECT * FROM [table] WHERE x=1 AND y=1 FOO', (string) $dolly );
|
Assert::same( reformat('SELECT * FROM [table] WHERE x=1 AND y=1 FOO'), (string) $dolly );
|
||||||
|
|
||||||
|
|
||||||
$fluent = dibi::select('id')->from('table')->where('id = %i',1);
|
$fluent = new DibiFluent($conn);
|
||||||
|
$fluent->select('id')->from('table')->where('id = %i',1);
|
||||||
$dolly = clone $fluent;
|
$dolly = clone $fluent;
|
||||||
$dolly->where('cd = %i',5);
|
$dolly->where('cd = %i',5);
|
||||||
|
|
||||||
Assert::same( 'SELECT [id] FROM [table] WHERE id = 1', (string) $fluent );
|
Assert::same( reformat('SELECT [id] FROM [table] WHERE id = 1'), (string) $fluent );
|
||||||
Assert::same( 'SELECT [id] FROM [table] WHERE id = 1 AND cd = 5', (string) $dolly );
|
Assert::same( reformat('SELECT [id] FROM [table] WHERE id = 1 AND cd = 5'), (string) $dolly );
|
||||||
|
|
||||||
|
|
||||||
$fluent = dibi::select("*")->from("table");
|
$fluent = new DibiFluent($conn);
|
||||||
|
$fluent->select("*")->from("table");
|
||||||
$dolly = clone $fluent;
|
$dolly = clone $fluent;
|
||||||
$dolly->removeClause("select")->select("count(*)");
|
$dolly->removeClause("select")->select("count(*)");
|
||||||
|
|
||||||
Assert::same( 'SELECT * FROM [table]', (string) $fluent );
|
Assert::same( reformat('SELECT * FROM [table]'), (string) $fluent );
|
||||||
Assert::same( 'SELECT count(*) FROM [table]', (string) $dolly );
|
Assert::same( reformat('SELECT count(*) FROM [table]'), (string) $dolly );
|
||||||
|
@@ -1,9 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test: DateTimeInterface of DibiTranslator
|
|
||||||
*
|
|
||||||
* @author Patrik Votoček
|
|
||||||
* @phpversion 5.5
|
* @phpversion 5.5
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -11,11 +8,8 @@ use Tester\Assert;
|
|||||||
|
|
||||||
require __DIR__ . '/bootstrap.php';
|
require __DIR__ . '/bootstrap.php';
|
||||||
|
|
||||||
$connection = new DibiConnection(array(
|
$conn = new DibiConnection($config);
|
||||||
'driver' => 'sqlite3',
|
$translator = new DibiTranslator($conn);
|
||||||
'database' => ':memory:',
|
|
||||||
));
|
|
||||||
$translator = new DibiTranslator($connection);
|
|
||||||
|
|
||||||
$datetime = new DateTime('1978-01-23 00:00:00');
|
$datetime = new DateTime('1978-01-23 00:00:00');
|
||||||
|
|
||||||
|
@@ -14,5 +14,51 @@ Tester\Environment::setup();
|
|||||||
date_default_timezone_set('Europe/Prague');
|
date_default_timezone_set('Europe/Prague');
|
||||||
|
|
||||||
|
|
||||||
// load connections
|
// load connection
|
||||||
$config = require __DIR__ . '/config.php';
|
try {
|
||||||
|
$config = Tester\Environment::loadData();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$config = parse_ini_file(__DIR__ . '/../databases.ini', TRUE);
|
||||||
|
$config = $config['sqlite3'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// lock
|
||||||
|
define('TEMP_DIR', __DIR__ . '/../tmp');
|
||||||
|
@mkdir(TEMP_DIR); // @ - directory may already exist
|
||||||
|
Tester\Environment::lock($config['system'], TEMP_DIR);
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
new DibiConnection($config);
|
||||||
|
} catch (DibiNotSupportedException $e) {
|
||||||
|
Tester\Environment::skip($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function test(\Closure $function)
|
||||||
|
{
|
||||||
|
$function();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Replaces [] with driver-specific quotes */
|
||||||
|
function reformat($s)
|
||||||
|
{
|
||||||
|
global $config;
|
||||||
|
if (is_array($s)) {
|
||||||
|
if (isset($s[$config['system']])) {
|
||||||
|
return $s[$config['system']];
|
||||||
|
}
|
||||||
|
$s = $s[0];
|
||||||
|
}
|
||||||
|
if ($config['system'] === 'mysql') {
|
||||||
|
return strtr($s, '[]', '``');
|
||||||
|
} elseif ($config['system'] === 'pgsql') {
|
||||||
|
return strtr($s, '[]', '""');
|
||||||
|
} elseif ($config['system'] === 'odbc' || $config['system'] === 'sqlite') {
|
||||||
|
return $s;
|
||||||
|
} else {
|
||||||
|
trigger_error("Unsupported driver $config[system]", E_USER_WARNING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -1,77 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return array(
|
|
||||||
'mysql' => array(
|
|
||||||
'driver' => 'mysql',
|
|
||||||
'host' => 'localhost',
|
|
||||||
'username' => 'root',
|
|
||||||
'password' => 'xxx',
|
|
||||||
'charset' => 'utf8',
|
|
||||||
),
|
|
||||||
|
|
||||||
'mysqli' => array(
|
|
||||||
'driver' => 'mysqli',
|
|
||||||
'host' => 'localhost',
|
|
||||||
'username' => 'dibi',
|
|
||||||
'password' => 'dibi',
|
|
||||||
'charset' => 'utf8',
|
|
||||||
),
|
|
||||||
|
|
||||||
'sqlite' => array(
|
|
||||||
'driver' => 'sqlite',
|
|
||||||
'database' => dirname(__FILE__) . '/data/sample.sdb',
|
|
||||||
),
|
|
||||||
|
|
||||||
'sqlite3' => array(
|
|
||||||
'driver' => 'sqlite3',
|
|
||||||
'database' => dirname(__FILE__) . '/data/sample.sdb3',
|
|
||||||
),
|
|
||||||
|
|
||||||
'odbc' => array(
|
|
||||||
'driver' => 'odbc',
|
|
||||||
'username' => 'dibi',
|
|
||||||
'password' => 'dibi',
|
|
||||||
'dsn' => 'Driver={Microsoft Access Driver (*.mdb)};Dbq=' . dirname(__FILE__) . '/data/sample.mdb',
|
|
||||||
),
|
|
||||||
|
|
||||||
'postgresql' => array(
|
|
||||||
'driver' => 'postgre',
|
|
||||||
'host' => 'localhost',
|
|
||||||
'port' => '5432',
|
|
||||||
'username' => 'dibi',
|
|
||||||
'password' => 'dibi',
|
|
||||||
'persistent' => '1',
|
|
||||||
),
|
|
||||||
|
|
||||||
'sqlite-pdo' => array(
|
|
||||||
'driver' => 'pdo',
|
|
||||||
'dsn' => 'sqlite2::' . dirname(__FILE__) . '/data/sample.sdb',
|
|
||||||
),
|
|
||||||
|
|
||||||
'mysql-pdo' => array(
|
|
||||||
'driver' => 'pdo',
|
|
||||||
'dsn' => 'mysql:host=localhost',
|
|
||||||
'username' => 'dibi',
|
|
||||||
'password' => 'dibi',
|
|
||||||
),
|
|
||||||
|
|
||||||
'mssql' => array(
|
|
||||||
'driver' => 'mssql',
|
|
||||||
'host' => 'localhost',
|
|
||||||
'username' => 'dibi',
|
|
||||||
'password' => 'dibi',
|
|
||||||
),
|
|
||||||
|
|
||||||
'mssql2005' => array(
|
|
||||||
'driver' => 'mssql2005',
|
|
||||||
'host' => '(local)',
|
|
||||||
'username' => 'dibi',
|
|
||||||
'password' => 'dibi',
|
|
||||||
),
|
|
||||||
|
|
||||||
'oracle' => array(
|
|
||||||
'driver' => 'oracle',
|
|
||||||
'username' => 'dibi',
|
|
||||||
'password' => 'dibi',
|
|
||||||
),
|
|
||||||
);
|
|
Binary file not shown.
@@ -1,92 +0,0 @@
|
|||||||
-- MySQL: 5.0.45
|
|
||||||
|
|
||||||
SET FOREIGN_KEY_CHECKS=0;
|
|
||||||
|
|
||||||
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
|
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `customers`;
|
|
||||||
CREATE TABLE IF NOT EXISTS `customers` (
|
|
||||||
`customer_id` int(11) NOT NULL auto_increment,
|
|
||||||
`name` varchar(100) default NULL,
|
|
||||||
PRIMARY KEY (`customer_id`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO `customers` (`customer_id`, `name`) VALUES
|
|
||||||
(1, 'Dave Lister'),
|
|
||||||
(2, 'Arnold Rimmer'),
|
|
||||||
(3, 'The Cat'),
|
|
||||||
(4, 'Holly'),
|
|
||||||
(5, 'Kryten'),
|
|
||||||
(6, 'Kristine Kochanski');
|
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `enumtest`;
|
|
||||||
CREATE TABLE IF NOT EXISTS `enumtest` (
|
|
||||||
`id` int(11) NOT NULL auto_increment,
|
|
||||||
`test` enum('a','b','c') NOT NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
|
|
||||||
|
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `orders`;
|
|
||||||
CREATE TABLE IF NOT EXISTS `orders` (
|
|
||||||
`order_id` int(11) NOT NULL,
|
|
||||||
`customer_id` int(11) NOT NULL,
|
|
||||||
`product_id` int(11) NOT NULL,
|
|
||||||
`amount` float NOT NULL
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO `orders` (`order_id`, `customer_id`, `product_id`, `amount`) VALUES
|
|
||||||
(1, 2, 1, 7),
|
|
||||||
(2, 2, 3, 2),
|
|
||||||
(3, 1, 2, 3),
|
|
||||||
(4, 6, 3, 5);
|
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `products`;
|
|
||||||
CREATE TABLE IF NOT EXISTS `products` (
|
|
||||||
`product_id` int(11) NOT NULL auto_increment,
|
|
||||||
`title` varchar(100) default NULL,
|
|
||||||
PRIMARY KEY (`product_id`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO `products` (`product_id`, `title`) VALUES
|
|
||||||
(1, 'Chair'),
|
|
||||||
(2, 'Table'),
|
|
||||||
(3, 'Computer');
|
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `settest`;
|
|
||||||
CREATE TABLE IF NOT EXISTS `settest` (
|
|
||||||
`id` int(11) NOT NULL auto_increment,
|
|
||||||
`test` set('a','b','c') NOT NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
|
|
||||||
|
|
||||||
-- --------------------------------------------------------
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `where`;
|
|
||||||
CREATE TABLE IF NOT EXISTS `where` (
|
|
||||||
`select` int(11) NOT NULL,
|
|
||||||
`dot.dot` int(11) NOT NULL,
|
|
||||||
`is` int(11) NOT NULL,
|
|
||||||
`quot'n' space` int(11) NOT NULL
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO `where` (`select`, `dot.dot`, `is`, `quot'n' space`) VALUES
|
|
||||||
(1, 2, 3, 4);
|
|
||||||
|
|
||||||
SET FOREIGN_KEY_CHECKS=1;
|
|
||||||
|
|
||||||
SET SQL_MODE="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";
|
|
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,18 @@
|
|||||||
[PHP]
|
[PHP]
|
||||||
extension_dir = "./ext"
|
extension_dir = "./ext"
|
||||||
|
;extension=php_mssql.dll
|
||||||
|
extension=php_mysql.dll
|
||||||
|
extension=php_mysqli.dll
|
||||||
|
;extension=php_oci8.dll
|
||||||
|
;extension=php_oci8_11g.dll
|
||||||
|
;extension=php_pdo_firebird.dll
|
||||||
|
;extension=php_pdo_mssql.dll
|
||||||
|
extension=php_pdo_mysql.dll
|
||||||
|
;extension=php_pdo_oci.dll
|
||||||
|
extension=php_pdo_odbc.dll
|
||||||
|
extension=php_pdo_pgsql.dll
|
||||||
|
extension=php_pdo_sqlite.dll
|
||||||
|
extension=php_pgsql.dll
|
||||||
|
extension=php_sqlite.dll
|
||||||
extension=php_sqlite3.dll
|
extension=php_sqlite3.dll
|
||||||
|
;extension=php_sqlsrv_ts.dll
|
||||||
|
Reference in New Issue
Block a user