mirror of
https://github.com/dg/dibi.git
synced 2025-08-03 12:47:33 +02:00
tests: fixes
This commit is contained in:
Binary file not shown.
@@ -12,16 +12,6 @@ $conn = new DibiConnection($config);
|
|||||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||||
|
|
||||||
|
|
||||||
function num($n)
|
|
||||||
{
|
|
||||||
global $config;
|
|
||||||
if (substr(@$config['dsn'], 0, 5) === 'odbc:' || $config['driver'] === 'sqlite') {
|
|
||||||
$n = is_float($n) ? "$n.0" : (string) $n;
|
|
||||||
}
|
|
||||||
return $n;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// fetch a single value
|
// fetch a single value
|
||||||
$res = $conn->query('SELECT [title] FROM [products]');
|
$res = $conn->query('SELECT [title] FROM [products]');
|
||||||
Assert::same('Chair', $res->fetchSingle());
|
Assert::same('Chair', $res->fetchSingle());
|
||||||
|
@@ -12,16 +12,6 @@ $conn = new DibiConnection($config);
|
|||||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||||
|
|
||||||
|
|
||||||
function num($n)
|
|
||||||
{
|
|
||||||
global $config;
|
|
||||||
if (substr(@$config['dsn'], 0, 5) === 'odbc:' || $config['driver'] === 'sqlite') {
|
|
||||||
$n = is_float($n) ? "$n.0" : (string) $n;
|
|
||||||
}
|
|
||||||
return $n;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// fetch a single value
|
// fetch a single value
|
||||||
$res = $conn->select('title')->from('products')->orderBy('product_id');
|
$res = $conn->select('title')->from('products')->orderBy('product_id');
|
||||||
Assert::equal('Chair', $res->fetchSingle());
|
Assert::equal('Chair', $res->fetchSingle());
|
||||||
|
@@ -80,16 +80,6 @@ Assert::same(
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
$fluent = $conn->select('*')->from('table')->fetch();
|
|
||||||
} catch (Exception $e) {
|
|
||||||
}
|
|
||||||
Assert::same(
|
|
||||||
reformat(' SELECT * FROM [table] LIMIT 1'),
|
|
||||||
dibi::$sql
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$fluent = $conn->select('*')
|
$fluent = $conn->select('*')
|
||||||
->select(
|
->select(
|
||||||
$conn->select('count(*)')
|
$conn->select('count(*)')
|
||||||
|
@@ -35,8 +35,8 @@ Assert::false(isset($row['missing']));
|
|||||||
|
|
||||||
|
|
||||||
// to array
|
// to array
|
||||||
Assert::same(array('product_id' => 1, 'title' => 'Chair'), iterator_to_array($row));
|
Assert::same(array('product_id' => num(1), 'title' => 'Chair'), iterator_to_array($row));
|
||||||
Assert::same(array('product_id' => 1, 'title' => 'Chair'), $row->toArray());
|
Assert::same(array('product_id' => num(1), 'title' => 'Chair'), $row->toArray());
|
||||||
|
|
||||||
// counting
|
// counting
|
||||||
Assert::same(2, count($row));
|
Assert::same(2, count($row));
|
||||||
|
@@ -69,3 +69,13 @@ function reformat($s)
|
|||||||
trigger_error("Unsupported driver $config[system]", E_USER_WARNING);
|
trigger_error("Unsupported driver $config[system]", E_USER_WARNING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function num($n)
|
||||||
|
{
|
||||||
|
global $config;
|
||||||
|
if (substr(@$config['dsn'], 0, 5) === 'odbc:' || $config['driver'] === 'sqlite') {
|
||||||
|
$n = is_float($n) ? "$n.0" : (string) $n;
|
||||||
|
}
|
||||||
|
return $n;
|
||||||
|
}
|
||||||
|
@@ -20,7 +20,7 @@ INSERT INTO `customers` (`customer_id`, `name`) VALUES (5, 'Kryten');
|
|||||||
INSERT INTO `customers` (`customer_id`, `name`) VALUES (6, 'Kristine Kochanski');
|
INSERT INTO `customers` (`customer_id`, `name`) VALUES (6, 'Kristine Kochanski');
|
||||||
|
|
||||||
CREATE TABLE [orders] (
|
CREATE TABLE [orders] (
|
||||||
[order_id] INTEGER,
|
[order_id] COUNTER,
|
||||||
[customer_id] INTEGER,
|
[customer_id] INTEGER,
|
||||||
[product_id] INTEGER,
|
[product_id] INTEGER,
|
||||||
[amount] FLOAT
|
[amount] FLOAT
|
||||||
|
Reference in New Issue
Block a user