Skip to content

Commit 389c41c

Browse files
committed
tests: some $context -> $connection
1 parent 7f8b8c3 commit 389c41c

13 files changed

+87
-87
lines changed

tests/Database/ResultSet.exceptions.mysql.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,32 @@ require __DIR__ . '/connect.inc.php'; // create $connection
1414
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
1515

1616

17-
$e = Assert::exception(function () use ($context) {
18-
$context->query('SELECT');
17+
$e = Assert::exception(function () use ($connection) {
18+
$connection->query('SELECT');
1919
}, Nette\Database\DriverException::class, '%a% Syntax error %a%', '42000');
2020

2121
Assert::same(1064, $e->getDriverCode());
2222
Assert::same($e->getCode(), $e->getSqlState());
2323

2424

25-
$e = Assert::exception(function () use ($context) {
26-
$context->query('INSERT INTO author (id, name, web, born) VALUES (11, "", "", NULL)');
25+
$e = Assert::exception(function () use ($connection) {
26+
$connection->query('INSERT INTO author (id, name, web, born) VALUES (11, "", "", NULL)');
2727
}, Nette\Database\UniqueConstraintViolationException::class, '%a% Integrity constraint violation: %a%', '23000');
2828

2929
Assert::same(1062, $e->getDriverCode());
3030
Assert::same($e->getCode(), $e->getSqlState());
3131

3232

33-
$e = Assert::exception(function () use ($context) {
34-
$context->query('INSERT INTO author (name, web, born) VALUES (NULL, "", NULL)');
33+
$e = Assert::exception(function () use ($connection) {
34+
$connection->query('INSERT INTO author (name, web, born) VALUES (NULL, "", NULL)');
3535
}, Nette\Database\NotNullConstraintViolationException::class, '%a% Integrity constraint violation: %a%', '23000');
3636

3737
Assert::same(1048, $e->getDriverCode());
3838
Assert::same($e->getCode(), $e->getSqlState());
3939

4040

41-
$e = Assert::exception(function () use ($context) {
42-
$context->query('INSERT INTO book (author_id, translator_id, title) VALUES (999, 12, "")');
41+
$e = Assert::exception(function () use ($connection) {
42+
$connection->query('INSERT INTO book (author_id, translator_id, title) VALUES (999, 12, "")');
4343
}, Nette\Database\ForeignKeyConstraintViolationException::class, '%a% a foreign key constraint fails %a%', '23000');
4444

4545
Assert::same(1452, $e->getDriverCode());

tests/Database/ResultSet.exceptions.postgre.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,32 @@ require __DIR__ . '/connect.inc.php'; // create $connection
1414
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
1515

1616

17-
$e = Assert::exception(function () use ($context) {
18-
$context->query('SELECT INTO');
17+
$e = Assert::exception(function () use ($connection) {
18+
$connection->query('SELECT INTO');
1919
}, Nette\Database\DriverException::class, '%a% syntax error %A%', '42601');
2020

2121
Assert::same(7, $e->getDriverCode());
2222
Assert::same($e->getCode(), $e->getSqlState());
2323

2424

25-
$e = Assert::exception(function () use ($context) {
26-
$context->query("INSERT INTO author (id, name, web, born) VALUES (11, '', '', NULL)");
25+
$e = Assert::exception(function () use ($connection) {
26+
$connection->query("INSERT INTO author (id, name, web, born) VALUES (11, '', '', NULL)");
2727
}, Nette\Database\UniqueConstraintViolationException::class, '%a% Unique violation: %A%', '23505');
2828

2929
Assert::same(7, $e->getDriverCode());
3030
Assert::same($e->getCode(), $e->getSqlState());
3131

3232

33-
$e = Assert::exception(function () use ($context) {
34-
$context->query("INSERT INTO author (name, web, born) VALUES (NULL, '', NULL)");
33+
$e = Assert::exception(function () use ($connection) {
34+
$connection->query("INSERT INTO author (name, web, born) VALUES (NULL, '', NULL)");
3535
}, Nette\Database\NotNullConstraintViolationException::class, '%a% Not null violation: %A%', '23502');
3636

3737
Assert::same(7, $e->getDriverCode());
3838
Assert::same($e->getCode(), $e->getSqlState());
3939

4040

41-
$e = Assert::exception(function () use ($context) {
42-
$context->query("INSERT INTO book (author_id, translator_id, title) VALUES (999, 12, '')");
41+
$e = Assert::exception(function () use ($connection) {
42+
$connection->query("INSERT INTO book (author_id, translator_id, title) VALUES (999, 12, '')");
4343
}, Nette\Database\ForeignKeyConstraintViolationException::class, '%a% Foreign key violation: %A%', '23503');
4444

4545
Assert::same(7, $e->getDriverCode());

tests/Database/ResultSet.exceptions.sqlite.phpt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,33 @@ require __DIR__ . '/connect.inc.php'; // create $connection
1414
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
1515

1616

17-
$e = Assert::exception(function () use ($context) {
18-
$context->query('SELECT');
17+
$e = Assert::exception(function () use ($connection) {
18+
$connection->query('SELECT');
1919
}, Nette\Database\DriverException::class, '%a% syntax error', 'HY000');
2020

2121
Assert::same(1, $e->getDriverCode());
2222
Assert::same($e->getCode(), $e->getSqlState());
2323

2424

25-
$e = Assert::exception(function () use ($context) {
26-
$context->query('INSERT INTO author (id, name, web, born) VALUES (11, "", "", NULL)');
25+
$e = Assert::exception(function () use ($connection) {
26+
$connection->query('INSERT INTO author (id, name, web, born) VALUES (11, "", "", NULL)');
2727
}, Nette\Database\UniqueConstraintViolationException::class, '%a% Integrity constraint violation: %a%', '23000');
2828

2929
Assert::same(19, $e->getDriverCode());
3030
Assert::same($e->getCode(), $e->getSqlState());
3131

3232

33-
$e = Assert::exception(function () use ($context) {
34-
$context->query('INSERT INTO author (name, web, born) VALUES (NULL, "", NULL)');
33+
$e = Assert::exception(function () use ($connection) {
34+
$connection->query('INSERT INTO author (name, web, born) VALUES (NULL, "", NULL)');
3535
}, Nette\Database\NotNullConstraintViolationException::class, '%a% Integrity constraint violation: %a%', '23000');
3636

3737
Assert::same(19, $e->getDriverCode());
3838
Assert::same($e->getCode(), $e->getSqlState());
3939

4040

41-
$e = Assert::exception(function () use ($context) {
42-
$context->query('PRAGMA foreign_keys=true');
43-
$context->query('INSERT INTO book (author_id, translator_id, title) VALUES (999, 12, "")');
41+
$e = Assert::exception(function () use ($connection) {
42+
$connection->query('PRAGMA foreign_keys=true');
43+
$connection->query('INSERT INTO book (author_id, translator_id, title) VALUES (999, 12, "")');
4444
}, Nette\Database\ForeignKeyConstraintViolationException::class, '%a% Integrity constraint violation: %a%', '23000');
4545

4646
Assert::same(19, $e->getDriverCode());

tests/Database/ResultSet.fetch().phpt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ require __DIR__ . '/connect.inc.php'; // create $connection
1414
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
1515

1616

17-
test(function () use ($context, $driverName) {
18-
$res = $context->query('SELECT name, name FROM author');
17+
test(function () use ($connection, $driverName) {
18+
$res = $connection->query('SELECT name, name FROM author');
1919
switch ($driverName) {
2020
case 'mysql':
2121
$message = "Found duplicate columns in database result set: 'name' (from author).";
@@ -40,24 +40,24 @@ test(function () use ($context, $driverName) {
4040
});
4141

4242

43-
test(function () use ($context, $driverName) { // tests closeCursor()
43+
test(function () use ($connection, $driverName) { // tests closeCursor()
4444
if ($driverName === 'mysql') {
45-
$context->query('CREATE DEFINER = CURRENT_USER PROCEDURE `testProc`(IN param int(10) unsigned) BEGIN SELECT * FROM book WHERE id != param; END;;');
46-
$context->getConnection()->getPdo()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
45+
$connection->query('CREATE DEFINER = CURRENT_USER PROCEDURE `testProc`(IN param int(10) unsigned) BEGIN SELECT * FROM book WHERE id != param; END;;');
46+
$connection->getPdo()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
4747

48-
$res = $context->query('CALL testProc(1)');
48+
$res = $connection->query('CALL testProc(1)');
4949
foreach ($res as $row) {
5050
}
5151

52-
$res = $context->query('SELECT * FROM book');
52+
$res = $connection->query('SELECT * FROM book');
5353
foreach ($res as $row) {
5454
}
5555
}
5656
});
5757

5858

59-
test(function () use ($context, $driverName) {
60-
$res = $context->query('SELECT book.id, author.id, author.name, translator.name FROM book JOIN author ON (author.id = book.author_id) JOIN author translator ON (translator.id = book.translator_id)');
59+
test(function () use ($connection, $driverName) {
60+
$res = $connection->query('SELECT book.id, author.id, author.name, translator.name FROM book JOIN author ON (author.id = book.author_id) JOIN author translator ON (translator.id = book.translator_id)');
6161
switch ($driverName) {
6262
case 'mysql':
6363
$message = "Found duplicate columns in database result set: 'id' (from book, author), 'name' (from author, translator).";
@@ -80,8 +80,8 @@ test(function () use ($context, $driverName) {
8080
});
8181

8282

83-
test(function () use ($context, $driverName) {
84-
$res = $context->query('SELECT id FROM author WHERE id = ?', 666);
83+
test(function () use ($connection, $driverName) {
84+
$res = $connection->query('SELECT id FROM author WHERE id = ?', 666);
8585

8686
Assert::null($res->fetch());
8787
});

tests/Database/ResultSet.fetchAll().phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require __DIR__ . '/connect.inc.php'; // create $connection
1414
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
1515

1616

17-
$res = $context->query('SELECT id FROM book ORDER BY id');
17+
$res = $connection->query('SELECT id FROM book ORDER BY id');
1818

1919
switch ($driverName) {
2020
case 'sqlite': // sqlite: rowCount for SELECT queries is not supported

tests/Database/ResultSet.fetchAssoc().phpt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ require __DIR__ . '/connect.inc.php'; // create $connection
1414
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
1515

1616

17-
test(function () use ($context) {
18-
$res = $context->query('SELECT * FROM book ORDER BY title');
17+
test(function () use ($connection) {
18+
$res = $connection->query('SELECT * FROM book ORDER BY title');
1919
Assert::same([
2020
1 => '1001 tipu a triku pro PHP',
2121
4 => 'Dibi',
@@ -25,8 +25,8 @@ test(function () use ($context) {
2525
});
2626

2727

28-
test(function () use ($context) {
29-
$pairs = $context->query('SELECT id FROM book ORDER BY id')->fetchAssoc('id');
28+
test(function () use ($connection) {
29+
$pairs = $connection->query('SELECT id FROM book ORDER BY id')->fetchAssoc('id');
3030
Assert::equal([
3131
1 => ['id' => 1],
3232
2 => ['id' => 2],
@@ -35,8 +35,8 @@ test(function () use ($context) {
3535
], $pairs);
3636
});
3737

38-
test(function () use ($context) {
39-
$pairs = $context->query('SELECT id FROM book ORDER BY id')->fetchAssoc('id[]=id');
38+
test(function () use ($connection) {
39+
$pairs = $connection->query('SELECT id FROM book ORDER BY id')->fetchAssoc('id[]=id');
4040
Assert::equal([
4141
1 => [1],
4242
2 => [2],
@@ -46,10 +46,10 @@ test(function () use ($context) {
4646
});
4747

4848

49-
test(function () use ($context) {
50-
$pairs = $context->query('UPDATE author SET born = ? WHERE id = 11', new DateTime('2002-02-20'));
51-
$pairs = $context->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02'));
52-
$pairs = $context->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchAssoc('born=name');
49+
test(function () use ($connection) {
50+
$pairs = $connection->query('UPDATE author SET born = ? WHERE id = 11', new DateTime('2002-02-20'));
51+
$pairs = $connection->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02'));
52+
$pairs = $connection->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchAssoc('born=name');
5353
Assert::same([
5454
'2002-02-02 00:00:00' => 'David Grudl',
5555
'2002-02-20 00:00:00' => 'Jakub Vrana',

tests/Database/ResultSet.fetchField().phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ require __DIR__ . '/connect.inc.php'; // create $connection
1414
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
1515

1616

17-
test(function () use ($context) {
18-
$res = $context->query('SELECT name, id FROM author ORDER BY id');
17+
test(function () use ($connection) {
18+
$res = $connection->query('SELECT name, id FROM author ORDER BY id');
1919

2020
Assert::same('Jakub Vrana', $res->fetchField());
2121
Assert::same(12, $res->fetchField(1));
2222
Assert::same('Geek', $res->fetchField('name'));
2323
});
2424

2525

26-
test(function () use ($context) {
27-
$res = $context->query('SELECT id FROM author WHERE id = ?', 666);
26+
test(function () use ($connection) {
27+
$res = $connection->query('SELECT id FROM author WHERE id = ?', 666);
2828

2929
Assert::null($res->fetchField());
3030
});

tests/Database/ResultSet.fetchPairs().phpt

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ require __DIR__ . '/connect.inc.php'; // create $connection
1414
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/files/{$driverName}-nette_test1.sql");
1515

1616

17-
test(function () use ($context) {
18-
$res = $context->query('SELECT * FROM book ORDER BY title');
17+
test(function () use ($connection) {
18+
$res = $connection->query('SELECT * FROM book ORDER BY title');
1919
Assert::same([
2020
1 => '1001 tipu a triku pro PHP',
2121
4 => 'Dibi',
@@ -32,8 +32,8 @@ test(function () use ($context) {
3232
});
3333

3434

35-
test(function () use ($context) {
36-
$pairs = $context->query('SELECT title, id FROM book ORDER BY title')->fetchPairs(1, 0);
35+
test(function () use ($connection) {
36+
$pairs = $connection->query('SELECT title, id FROM book ORDER BY title')->fetchPairs(1, 0);
3737
Assert::same([
3838
1 => '1001 tipu a triku pro PHP',
3939
4 => 'Dibi',
@@ -43,8 +43,8 @@ test(function () use ($context) {
4343
});
4444

4545

46-
test(function () use ($context) {
47-
$pairs = $context->query('SELECT * FROM book ORDER BY id')->fetchPairs('id', 'id');
46+
test(function () use ($connection) {
47+
$pairs = $connection->query('SELECT * FROM book ORDER BY id')->fetchPairs('id', 'id');
4848
Assert::same([
4949
1 => 1,
5050
2 => 2,
@@ -54,8 +54,8 @@ test(function () use ($context) {
5454
});
5555

5656

57-
test(function () use ($context) {
58-
$pairs = $context->query('SELECT id FROM book ORDER BY id')->fetchPairs('id');
57+
test(function () use ($connection) {
58+
$pairs = $connection->query('SELECT id FROM book ORDER BY id')->fetchPairs('id');
5959
Assert::equal([
6060
1 => Nette\Database\Row::from(['id' => 1]),
6161
2 => Nette\Database\Row::from(['id' => 2]),
@@ -65,18 +65,18 @@ test(function () use ($context) {
6565
});
6666

6767

68-
test(function () use ($context) {
69-
$pairs = $context->query('UPDATE author SET born = ? WHERE id = 11', new DateTime('2002-02-20'));
70-
$pairs = $context->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02'));
71-
$pairs = $context->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchPairs('born', 'name');
68+
test(function () use ($connection) {
69+
$pairs = $connection->query('UPDATE author SET born = ? WHERE id = 11', new DateTime('2002-02-20'));
70+
$pairs = $connection->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02'));
71+
$pairs = $connection->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchPairs('born', 'name');
7272
Assert::same([
7373
'2002-02-02 00:00:00' => 'David Grudl',
7474
'2002-02-20 00:00:00' => 'Jakub Vrana',
7575
], $pairs);
7676
});
7777

7878

79-
$pairs = $context->query('SELECT id FROM book ORDER BY id')->fetchPairs('id');
79+
$pairs = $connection->query('SELECT id FROM book ORDER BY id')->fetchPairs('id');
8080
Assert::equal([
8181
1 => Nette\Database\Row::from(['id' => 1]),
8282
2 => Nette\Database\Row::from(['id' => 2]),
@@ -85,7 +85,7 @@ Assert::equal([
8585
], $pairs);
8686

8787

88-
$pairs = $context->query('SELECT id FROM book ORDER BY id')->fetchPairs(null, 'id');
88+
$pairs = $connection->query('SELECT id FROM book ORDER BY id')->fetchPairs(null, 'id');
8989
Assert::equal([
9090
0 => 1,
9191
1 => 2,
@@ -94,7 +94,7 @@ Assert::equal([
9494
], $pairs);
9595

9696

97-
$pairs = $context->query('SELECT id FROM book ORDER BY id')->fetchPairs();
97+
$pairs = $connection->query('SELECT id FROM book ORDER BY id')->fetchPairs();
9898
Assert::equal([
9999
0 => 1,
100100
1 => 2,
@@ -103,7 +103,7 @@ Assert::equal([
103103
], $pairs);
104104

105105

106-
$pairs = $context->query('SELECT id, id + 1 AS id1 FROM book ORDER BY id')->fetchPairs();
106+
$pairs = $connection->query('SELECT id, id + 1 AS id1 FROM book ORDER BY id')->fetchPairs();
107107
Assert::equal([
108108
1 => 2,
109109
2 => 3,
@@ -112,7 +112,7 @@ Assert::equal([
112112
], $pairs);
113113

114114

115-
$pairs = $context->query('SELECT id, id + 1 AS id1, title FROM book ORDER BY id')->fetchPairs();
115+
$pairs = $connection->query('SELECT id, id + 1 AS id1, title FROM book ORDER BY id')->fetchPairs();
116116
Assert::equal([
117117
1 => 2,
118118
2 => 3,
@@ -121,16 +121,16 @@ Assert::equal([
121121
], $pairs);
122122

123123

124-
$pairs = $context->query('UPDATE author SET born = ? WHERE id = 11', new DateTime('2002-02-20'));
125-
$pairs = $context->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02'));
126-
$pairs = $context->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchPairs('born', 'name');
124+
$pairs = $connection->query('UPDATE author SET born = ? WHERE id = 11', new DateTime('2002-02-20'));
125+
$pairs = $connection->query('UPDATE author SET born = ? WHERE id = 12', new DateTime('2002-02-02'));
126+
$pairs = $connection->query('SELECT * FROM author WHERE born IS NOT NULL ORDER BY born')->fetchPairs('born', 'name');
127127
Assert::same([
128128
'2002-02-02 00:00:00' => 'David Grudl',
129129
'2002-02-20 00:00:00' => 'Jakub Vrana',
130130
], $pairs);
131131

132132

133-
$pairs = $context->query('SELECT 1.5 AS k, 1 AS v')->fetchPairs();
133+
$pairs = $connection->query('SELECT 1.5 AS k, 1 AS v')->fetchPairs();
134134
Assert::equal([
135135
'1.5' => 1,
136136
], $pairs);

0 commit comments

Comments
 (0)