summaryrefslogtreecommitdiff
path: root/test/it_dbi.t
diff options
context:
space:
mode:
authorUrban Müller2020-04-21 01:03:53 +0200
committerUrban Müller2020-04-21 01:03:53 +0200
commitd987adefc85095f057c3d6d3eb2fa4c0d487d32b (patch)
tree4a6f7be8e35ff0c412666c41a46f22383d8ed5c2 /test/it_dbi.t
parent1bd13e02d21ba01f38cd6df04de84b25a75a5264 (diff)
downloaditools-d987adefc85095f057c3d6d3eb2fa4c0d487d32b.tar.gz
itools-d987adefc85095f057c3d6d3eb2fa4c0d487d32b.tar.bz2
itools-d987adefc85095f057c3d6d3eb2fa4c0d487d32b.zip
use new array syntax
Diffstat (limited to 'test/it_dbi.t')
-rwxr-xr-xtest/it_dbi.t128
1 files changed, 64 insertions, 64 deletions
diff --git a/test/it_dbi.t b/test/it_dbi.t
index 705e814..9f43f6e 100755
--- a/test/it_dbi.t
+++ b/test/it_dbi.t
@@ -4,7 +4,7 @@
# Tests for it_dbi.class
# Initialize DB
-$db = array('db' => "lib_search_ch", 'safety' => 0);
+$db = ['db' => "lib_search_ch", 'safety' => 0];
$dbi = new it_dbi($db);
$dbi->query('create temporary table it_dbi_test (
ID int not null auto_increment,
@@ -13,13 +13,13 @@ $dbi->query('create temporary table it_dbi_test (
dyncols JSON,
primary key(ID)
);');
-it_dbi::createclass(array('table' => "it_dbi_test", 'forcecreate' => true));
+it_dbi::createclass(['table' => "it_dbi_test", 'forcecreate' => true]);
$record = new it_dbi_test;
-$record->insert(array('x' => 42, 'foo' => null));
-$record->insert(array('foo' => "bar"));
-$record->insert(array('x' => 64738, 'foo' => "q'uux"));
+$record->insert(['x' => 42, 'foo' => null]);
+$record->insert(['foo' => "bar"]);
+$record->insert(['x' => 64738, 'foo' => "q'uux"]);
is(
$record->ID,
@@ -29,8 +29,8 @@ is(
$record->read(1);
is(
- array($record->_key, $record->x, $record->foo),
- array(1, 42, null),
+ [$record->_key, $record->x, $record->foo],
+ [1, 42, null],
"read"
);
@@ -41,7 +41,7 @@ is(
);
is(
- $record->select(array('foo <>' => ""), "LIMIT 1"),
+ $record->select(['foo <>' => ""], "LIMIT 1"),
1,
"select with multiple parameters (LIMIT part)"
);
@@ -51,32 +51,32 @@ is(
"select with multiple parameters (foo part)"
);
is(
- $record->select(array('ID IN' => array(2,3))),
+ $record->select(['ID IN' => [2,3]]),
2,
"select with IN"
);
is(
- $record->select(array('ID NI' => array(2,3))),
+ $record->select(['ID NI' => [2,3]]),
2,
"select with NI"
);
is(
- $record->select(array('ID NOT IN' => array(2,3))),
+ $record->select(['ID NOT IN' => [2,3]]),
1,
"select with NOT IN"
);
is(
- $record->select(array('ID IN' => array())),
+ $record->select(['ID IN' => []]),
0,
"select with empty IN"
);
is(
- $record->select(array('ID NOT IN' => array())),
+ $record->select(['ID NOT IN' => []]),
3,
"select with empty NOT IN"
);
is(
- $record->select(array('ID' => array(2,3))),
+ $record->select(['ID' => [2,3]]),
2,
"select with implicit IN"
);
@@ -95,14 +95,14 @@ is(
"constructor of created class with id parameter"
);
-$record = new it_dbi_test(array('x >' => 0), "ORDER BY x DESC");
+$record = new it_dbi_test(['x >' => 0], "ORDER BY x DESC");
is(
$record->x,
64738,
"constructor of created class with multiple select parameters"
);
-$record = new it_dbi_test(array('foo' => 'bar'));
+$record = new it_dbi_test(['foo' => 'bar']);
is(
$record->ID,
2,
@@ -116,96 +116,96 @@ is(
"constructor without parameters"
);
-$record = new it_dbi_test(array('x >' => 0), "ORDER BY x DESC");
+$record = new it_dbi_test(['x >' => 0], "ORDER BY x DESC");
is(
$record->x,
64738,
"constructor with multiple select parameters"
);
-$record->select(array('x' => 64738));
+$record->select(['x' => 64738]);
is(
- array($record->_key, $record->x, $record->foo),
- array(3, 64738, "q'uux"),
+ [$record->_key, $record->x, $record->foo],
+ [3, 64738, "q'uux"],
"select"
);
-$record->update(array('x' => 17));
+$record->update(['x' => 17]);
is(
- array($record->_key, $record->x, $record->foo),
- array(3, 17, "q'uux"),
+ [$record->_key, $record->x, $record->foo],
+ [3, 17, "q'uux"],
"update"
);
is(
- $record->update(array('x' => 18), array('x' => 17)),
+ $record->update(['x' => 18], ['x' => 17]),
1,
"return affected rows"
);
is(
- $record->update(array('x' => 18), array('x' => 17)),
+ $record->update(['x' => 18], ['x' => 17]),
0,
"return zero affected rows"
);
-$record->update(array('-x' => 'POW(2,2) * 10'));
+$record->update(['-x' => 'POW(2,2) * 10']);
is(
- array($record->_key, $record->x, $record->foo),
- array(3, 40, "q'uux"),
+ [$record->_key, $record->x, $record->foo],
+ [3, 40, "q'uux"],
"update with function"
);
-$record->update(array('foo' => "00"));
+$record->update(['foo' => "00"]);
$rand = $record->x;
is (
- $record->_set(array('x' => $rand, 'foo' => "0")),
+ $record->_set(['x' => $rand, 'foo' => "0"]),
"SET `foo`='0'",
'update: _set optimization'
);
-$record->update(array('foo' => NULL));
+$record->update(['foo' => NULL]);
is (
- $record->_set(array('foo' => "")),
+ $record->_set(['foo' => ""]),
"SET `foo`=''",
'update: _set optimization with NULL => ""'
);
-$record->update(array('foo' => "bar"));
-$record->update(array('foo' => ""));
+$record->update(['foo' => "bar"]);
+$record->update(['foo' => ""]);
is (
- $record->_set(array('foo' => NULL)),
+ $record->_set(['foo' => NULL]),
"SET `foo`=NULL",
'update: _set optimization with "" => NULL'
);
-$record->update(array('foo' => "bar"));
-$record->select(array('foo' => "bar"));
+$record->update(['foo' => "bar"]);
+$record->select(['foo' => "bar"]);
$record->iterate();
is(
- array($record->_key, $record->x, $record->foo),
- array(2, null, "bar"),
+ [$record->_key, $record->x, $record->foo],
+ [2, null, "bar"],
"iterate record 2"
);
-$record->update(array('foo' => "qux"));
+$record->update(['foo' => "qux"]);
$record->iterate();
is(
- array($record->_key, $record->x, $record->foo),
- array(3, $rand, "bar"),
+ [$record->_key, $record->x, $record->foo],
+ [3, $rand, "bar"],
"iterate record 3"
);
-$record->update(array('foo' => "quux"));
+$record->update(['foo' => "quux"]);
$record->read(2);
is(
- array($record->_key, isset($record->x), $record->foo),
- array(2, false, "qux"),
+ [$record->_key, isset($record->x), $record->foo],
+ [2, false, "qux"],
"iterate update record 2"
);
$record->read(3);
is(
- array($record->_key, $record->x, $record->foo),
- array(3, $rand, "quux"),
+ [$record->_key, $record->x, $record->foo],
+ [3, $rand, "quux"],
"iterate update record 3"
);
@@ -224,7 +224,7 @@ foreach (new it_dbi_test as $id => $record)
is($count, 3, "Iterator without select");
$count = 0;
-foreach (new it_dbi_test(array('foo <>' => "")) as $id => $record)
+foreach (new it_dbi_test(['foo <>' => ""]) as $id => $record)
{
$count++;
is($record->_key, $id, "Iterator id $id");
@@ -237,7 +237,7 @@ foreach ($record as $dummy_rec)
is($count, 2, "Iterator reused");
$GLOBALS['debug_sqllog'] = true;
-@$record->store(array('ID' => 5, 'x' => 6));
+@$record->store(['ID' => 5, 'x' => 6]);
like(
$record->_sqllog[1]['query'],
"REPLACE",
@@ -251,8 +251,8 @@ is(
"saving with store"
);
-$record->_sqllog = array();
-@$record->store(array('ID' => 5, 'x' => 7));
+$record->_sqllog = [];
+@$record->store(['ID' => 5, 'x' => 7]);
like(
$record->_sqllog[1]['query'],
"UPDATE",
@@ -266,8 +266,8 @@ is(
"updating with store"
);
-$record->_sqllog = array();
-@$record->store(array('ID' => 5, 'x' => 7));
+$record->_sqllog = [];
+@$record->store(['ID' => 5, 'x' => 7]);
is(
$record->_sqllog[1]['query'],
null, # Only SELECT, no UPDATE
@@ -278,7 +278,7 @@ $GLOBALS['debug_sqllog'] = false;
# test latin1 (produces warnings on stderr for failing)
$record = new it_dbi_test(['charset' => 'latin1']);
-$record->select(array('foo' => "\xc3\x28"));
+$record->select(['foo' => "\xc3\x28"]);
# Test field localization feature
@@ -289,30 +289,30 @@ $dbi->query('create temporary table it_dbi_testlocalized (
primary key(ID)
);');
-$record = new it_dbi($db + array('table' => "it_dbi_testlocalized"));
-$record->insert(array('foobar_de' => "deutsch", 'foobar_fr' => "franz"));
-$record->insert(array('foobar_de' => "deutsch2", 'foobar_fr' => "franz2"));
+$record = new it_dbi($db + ['table' => "it_dbi_testlocalized"]);
+$record->insert(['foobar_de' => "deutsch", 'foobar_fr' => "franz"]);
+$record->insert(['foobar_de' => "deutsch2", 'foobar_fr' => "franz2"]);
T_set_language('de');
-$record->select(array());
+$record->select([]);
$record->iterate();
is(
- array($record->_key, $record->foobar),
- array(1, "deutsch"),
+ [$record->_key, $record->foobar],
+ [1, "deutsch"],
"localized field foobar_de"
);
$record->iterate();
is(
- array($record->_key, $record->foobar),
- array(2, "deutsch2"),
+ [$record->_key, $record->foobar],
+ [2, "deutsch2"],
"localized field foobar_de iterate"
);
T_set_language('fr');
$record->read(1);
is(
- array($record->_key, $record->foobar),
- array(1, "franz"),
+ [$record->_key, $record->foobar],
+ [1, "franz"],
"localized field foobar_fr"
);