Skip to content

Commit f449746

Browse files
committed
tests: improved descriptions
1 parent 23914ef commit f449746

20 files changed

+94
-94
lines changed

tests/Database/Explorer/Explorer.aggregation.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ $connection = $explorer->getConnection();
1717
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");
1818

1919

20-
test('', function () use ($explorer) {
20+
test('basic count aggregation', function () use ($explorer) {
2121
$count = $explorer->table('book')->count('*'); // SELECT COUNT(*) FROM `book`
2222
Assert::same(4, $count);
2323
});
2424

2525

26-
test('', function () use ($explorer) {
26+
test('related count aggregation', function () use ($explorer) {
2727
$tags = [];
2828
foreach ($explorer->table('book') as $book) { // SELECT * FROM `book`
2929
$count = $book->related('book_tag')->count('*'); // SELECT COUNT(*), `book_id` FROM `book_tag` WHERE (`book_tag`.`book_id` IN (1, 2, 3, 4)) GROUP BY `book_id`
@@ -39,21 +39,21 @@ test('', function () use ($explorer) {
3939
});
4040

4141

42-
test('', function () use ($explorer) {
42+
test('group by with join condition', function () use ($explorer) {
4343
$authors = $explorer->table('author')->where(':book.translator_id IS NOT NULL')->group('author.id'); // SELECT `author`.* FROM `author` INNER JOIN `book` ON `author`.`id` = `book`.`author_id` WHERE (`book`.`translator_id` IS NOT NULL) GROUP BY `author`.`id`
4444
Assert::count(2, $authors);
4545
Assert::same(2, $authors->count('DISTINCT author.id')); // SELECT COUNT(DISTINCT author.id) FROM `author` INNER JOIN `book` ON `author`.`id` = `book`.`author_id` WHERE (`book`.`translator_id` IS NOT NULL)
4646
});
4747

4848

49-
test('', function () use ($explorer) {
49+
test('having clause with group by', function () use ($explorer) {
5050
$authors = $explorer->table('book')->group('book.id')->having('COUNT(DISTINCT :book_tag.tag_id) < 2'); // SELECT `author`.* FROM `author` INNER JOIN `book` ON `author`.`id` = `book`.`author_id` WHERE (`book`.`translator_id` IS NOT NULL) GROUP BY `author`.`id`
5151
Assert::count(2, $authors);
5252
Assert::same(2, $authors->count('DISTINCT author.id')); // SELECT COUNT(DISTINCT author.id) FROM `author` INNER JOIN `book` ON `author`.`id` = `book`.`author_id` WHERE (`book`.`translator_id` IS NOT NULL)
5353
});
5454

5555

56-
test('', function () use ($explorer) {
56+
test('distinct count in related aggregation', function () use ($explorer) {
5757
$bookTags = [];
5858
foreach ($explorer->table('book') as $book) {
5959
$book_tags = $book->related('book_tag');
@@ -69,7 +69,7 @@ test('', function () use ($explorer) {
6969
});
7070

7171

72-
test('', function () use ($explorer) {
72+
test('filtering groups by related count', function () use ($explorer) {
7373
$bookTags = [];
7474
foreach ($explorer->table('book')->group('book.id, book.title')->having('COUNT(DISTINCT :book_tag.tag_id) < 2') as $book) {
7575
$book_tags = $book->related('book_tag');
@@ -82,7 +82,7 @@ test('', function () use ($explorer) {
8282
], $bookTags);
8383
});
8484

85-
test('', function () use ($explorer) {
85+
test('nested group by and having', function () use ($explorer) {
8686
$bookTags = [];
8787
foreach ($explorer->table('author') as $author) {
8888
$books = $author->related('book');

tests/Database/Explorer/Explorer.backjoin.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN
1919
$driver = $connection->getDriver();
2020

2121

22-
test('', function () use ($explorer) {
22+
test('backward join aggregation with having', function () use ($explorer) {
2323
$authorTagsCount = [];
2424
$authors = $explorer
2525
->table('author')
@@ -39,7 +39,7 @@ test('', function () use ($explorer) {
3939
});
4040

4141

42-
test('', function () use ($explorer, $driver) {
42+
test('left join SQL structure verification', function () use ($explorer, $driver) {
4343
$authorsSelection = $explorer->table('author')->where(':book.translator_id IS NOT NULL')->wherePrimary(12);
4444

4545
if ($driver->isSupported(Driver::SupportSchema)) {
@@ -63,7 +63,7 @@ test('', function () use ($explorer, $driver) {
6363
});
6464

6565

66-
test('', function () use ($explorer) {
66+
test('join condition with translated book', function () use ($explorer) {
6767
$count = $explorer->table('author')->where(':book(translator).title LIKE ?', '%JUSH%')->count('*'); // by translator_id
6868
Assert::same(0, $count);
6969
});

tests/Database/Explorer/Explorer.basic.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $connection = $explorer->getConnection();
1717
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");
1818

1919

20-
test('', function () use ($explorer) {
20+
test('select specific columns', function () use ($explorer) {
2121
$book = $explorer->table('book')->where('id = ?', 1)->select('id, title')->fetch()->toArray(); // SELECT `id`, `title` FROM `book` WHERE (`id` = ?)
2222
Assert::same([
2323
'id' => 1,
@@ -26,7 +26,7 @@ test('', function () use ($explorer) {
2626
});
2727

2828

29-
test('', function () use ($explorer) {
29+
test('select and where clause ordering', function () use ($explorer) {
3030
$book = $explorer->table('book')->select('id, title')->where('id = ?', 1)->fetch()->toArray(); // SELECT `id`, `title` FROM `book` WHERE (`id` = ?)
3131
Assert::same([
3232
'id' => 1,
@@ -35,7 +35,7 @@ test('', function () use ($explorer) {
3535
});
3636

3737

38-
test('', function () use ($explorer) {
38+
test('undefined column access exception', function () use ($explorer) {
3939
$book = $explorer->table('book')->get(1);
4040
Assert::exception(
4141
fn() => $book->unknown_column,
@@ -45,7 +45,7 @@ test('', function () use ($explorer) {
4545
});
4646

4747

48-
test('', function () use ($explorer) {
48+
test('related data fetching with joins', function () use ($explorer) {
4949
$bookTags = [];
5050
foreach ($explorer->table('book') as $book) { // SELECT * FROM `book`
5151
$bookTags[$book->title] = [
@@ -79,7 +79,7 @@ test('', function () use ($explorer) {
7979
});
8080

8181

82-
test('', function () use ($explorer) {
82+
test('error handling for invalid properties', function () use ($explorer) {
8383
$book = $explorer->table('book')->get(1);
8484
Assert::exception(
8585
fn() => $book->test,

tests/Database/Explorer/Explorer.cache.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $connection = $explorer->getConnection();
1717
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");
1818

1919

20-
test('Testing Selection caching', function () use ($explorer) {
20+
test('column access caching across queries', function () use ($explorer) {
2121
$sql = [];
2222
for ($i = 0; $i < 4; ++$i) {
2323
if ($i !== 2) {
@@ -56,7 +56,7 @@ test('Testing Selection caching', function () use ($explorer) {
5656
});
5757

5858

59-
test('Testing GroupedSelection reinvalidation caching', function () use ($explorer) {
59+
test('related selection caching consistency', function () use ($explorer) {
6060
foreach ($explorer->table('author') as $author) {
6161
$stack[] = $selection = $author->related('book.author_id')->order('title');
6262
foreach ($selection as $book) {
@@ -86,7 +86,7 @@ $cacheMemoryStorage = new Nette\Caching\Storages\MemoryStorage;
8686
setUp(fn() => $cacheMemoryStorage->clean([Nette\Caching\Cache::ALL => true]));
8787

8888

89-
test('', function () use ($explorer) {
89+
test('cache invalidation after destruction', function () use ($explorer) {
9090
$selection = $explorer->table('book');
9191
foreach ($selection as $book) {
9292
$book->id;
@@ -109,7 +109,7 @@ test('', function () use ($explorer) {
109109
});
110110

111111

112-
test('', function () use ($explorer) {
112+
test('shared accessed columns in related instances', function () use ($explorer) {
113113
$relatedStack = [];
114114
foreach ($explorer->table('author') as $author) {
115115
$relatedStack[] = $related = $author->related('book.author_id');
@@ -127,7 +127,7 @@ test('', function () use ($explorer) {
127127
});
128128

129129

130-
test('Test saving joining keys even with 0 rows', function () use ($explorer) {
130+
test('previous accessed columns tracking', function () use ($explorer) {
131131
$cols = [];
132132
for ($i = 0; $i < 2; ++$i) {
133133
$author = $explorer->table('author')->get(11);
@@ -146,7 +146,7 @@ test('Test saving joining keys even with 0 rows', function () use ($explorer) {
146146
});
147147

148148

149-
test('Test saving the union of needed cols, the second call is subset', function () use ($explorer) {
149+
test('accessed columns across iterations', function () use ($explorer) {
150150
$cols = [];
151151
for ($i = 0; $i < 3; ++$i) {
152152
$author = $explorer->table('author')->get(11);
@@ -171,7 +171,7 @@ test('Test saving the union of needed cols, the second call is subset', function
171171
});
172172

173173

174-
test('Test saving the union of needed cols, the second call is not subset', function () use ($explorer) {
174+
test('incremental column access tracking', function () use ($explorer) {
175175
$cols = [];
176176
for ($i = 0; $i < 3; ++$i) {
177177
$author = $explorer->table('author')->get(11);
@@ -196,7 +196,7 @@ test('Test saving the union of needed cols, the second call is not subset', func
196196
});
197197

198198

199-
test('Test multiple use of same selection', function () use ($explorer) {
199+
test('SQL query logging with caching', function () use ($explorer) {
200200
$sql = [];
201201
$explorer->getConnection()->onQuery[] = function ($_, $result) use (&$sql) {
202202
$sql[] = $result->getQueryString();

tests/Database/Explorer/Explorer.discoveredReflection.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $connection = $explorer->getConnection();
1717
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");
1818

1919

20-
test('', function () use ($explorer) {
20+
test('reflection-based related data fetching', function () use ($explorer) {
2121
$appTags = [];
2222
foreach ($explorer->table('book') as $book) {
2323
$appTags[$book->title] = [
@@ -51,7 +51,7 @@ test('', function () use ($explorer) {
5151
});
5252

5353

54-
test('', function () use ($explorer) {
54+
test('reflection in related entity iteration', function () use ($explorer) {
5555
$books = [];
5656
foreach ($explorer->table('author') as $author) {
5757
foreach ($author->related('book') as $book) {
@@ -68,13 +68,13 @@ test('', function () use ($explorer) {
6868
});
6969

7070

71-
test('', function () use ($explorer) {
71+
test('reflection-based translator access', function () use ($explorer) {
7272
$book = $explorer->table('book')->get(1);
7373
Assert::same('Jakub Vrana', $book->translator->name);
7474
});
7575

7676

77-
test('', function () use ($explorer) {
77+
test('property existence and empty checks', function () use ($explorer) {
7878
$book = $explorer->table('book')->get(2);
7979
Assert::true(isset($book->author_id));
8080
Assert::false(empty($book->author_id));
@@ -90,7 +90,7 @@ test('', function () use ($explorer) {
9090
});
9191

9292

93-
test('', function () use ($connection, $explorer, $driverName) {
93+
test('case-insensitive table reflection', function () use ($connection, $explorer, $driverName) {
9494
if (
9595
$driverName === 'mysql' &&
9696
($lowerCase = $connection->query('SHOW VARIABLES LIKE "lower_case_table_names"')->fetch()) &&
@@ -114,7 +114,7 @@ test('', function () use ($connection, $explorer, $driverName) {
114114
});
115115

116116

117-
test('', function () use ($explorer) {
117+
test('where clause with related model attribute', function () use ($explorer) {
118118
$count = $explorer->table('book')->where('translator.name LIKE ?', '%David%')->count();
119119
Assert::same(2, $count);
120120
$count = $explorer->table('book')->where('author.name LIKE ?', '%David%')->count();

tests/Database/Explorer/Explorer.join.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN
1919
$driver = $connection->getDriver();
2020

2121

22-
test('', function () use ($explorer) {
22+
test('join with order by related column', function () use ($explorer) {
2323
$apps = [];
2424
foreach ($explorer->table('book')->order('author.name, title') as $book) { // SELECT `book`.* FROM `book` LEFT JOIN `author` ON `book`.`author_id` = `author`.`id` ORDER BY `author`.`name`, `title`
2525
$apps[$book->title] = $book->author->name; // SELECT * FROM `author` WHERE (`author`.`id` IN (12, 11))
@@ -34,7 +34,7 @@ test('', function () use ($explorer) {
3434
});
3535

3636

37-
test('', function () use ($explorer, $driver) {
37+
test('join SQL structure verification', function () use ($explorer, $driver) {
3838
$joinSql = $explorer->table('book_tag')->where('book_id', 1)->select('tag.*')->getSql();
3939

4040
if ($driver->isSupported(Driver::SupportSchema)) {
@@ -51,7 +51,7 @@ test('', function () use ($explorer, $driver) {
5151
});
5252

5353

54-
test('', function () use ($explorer, $driver) {
54+
test('aliased column selection in join', function () use ($explorer, $driver) {
5555
$joinSql = $explorer->table('book_tag')->where('book_id', 1)->select('Tag.id')->getSql();
5656

5757
if ($driver->isSupported(Driver::SupportSchema)) {
@@ -68,7 +68,7 @@ test('', function () use ($explorer, $driver) {
6868
});
6969

7070

71-
test('', function () use ($explorer) {
71+
test('multi-table join with group by', function () use ($explorer) {
7272
$tags = [];
7373
foreach ($explorer->table('book_tag')->where('book.author.name', 'Jakub Vrana')->group('book_tag.tag_id')->order('book_tag.tag_id') as $book_tag) { // SELECT `book_tag`.* FROM `book_tag` INNER JOIN `book` ON `book_tag`.`book_id` = `book`.`id` INNER JOIN `author` ON `book`.`author_id` = `author`.`id` WHERE (`author`.`name` = ?) GROUP BY `book_tag`.`tag_id`
7474
$tags[] = $book_tag->tag->name; // SELECT * FROM `tag` WHERE (`tag`.`id` IN (21, 22, 23))
@@ -82,12 +82,12 @@ test('', function () use ($explorer) {
8282
});
8383

8484

85-
test('', function () use ($explorer) {
85+
test('count through joined table', function () use ($explorer) {
8686
Assert::same(2, $explorer->table('author')->where('author_id', 11)->count(':book.id')); // SELECT COUNT(book.id) FROM `author` LEFT JOIN `book` ON `author`.`id` = `book`.`author_id` WHERE (`author_id` = 11)
8787
});
8888

8989

90-
test('', function () use ($explorer) {
90+
test('multiple column selection from joins', function () use ($explorer) {
9191
$books = $explorer->table('book')->select('book.*, author.name, translator.name');
9292
iterator_to_array($books);
9393
});

tests/Database/Explorer/Explorer.multi-primary-key.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $connection = $explorer->getConnection();
1717
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");
1818

1919

20-
test('', function () use ($explorer) {
20+
test('deletion through multi-key relation', function () use ($explorer) {
2121
$book = $explorer->table('book')->get(1);
2222
foreach ($book->related('book_tag') as $bookTag) {
2323
if ($bookTag->tag->name === 'PHP') {
@@ -36,7 +36,7 @@ test('', function () use ($explorer) {
3636
});
3737

3838

39-
test('', function () use ($explorer) {
39+
test('alternate key relation iteration', function () use ($explorer) {
4040
$book = $explorer->table('book')->get(3);
4141
foreach ($related = $book->related('book_tag_alt') as $bookTag) {
4242
}
@@ -58,7 +58,7 @@ test('', function () use ($explorer) {
5858
});
5959

6060

61-
test('', function () use ($explorer) {
61+
test('insert into multi-key table', function () use ($explorer) {
6262
$explorer->table('book_tag')->insert([
6363
'book_id' => 1,
6464
'tag_id' => 21, // PHP tag

tests/Database/Explorer/Explorer.placeholders.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ $connection = $explorer->getConnection();
1818
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");
1919

2020

21-
test('Leave literals lower-cased, also not-delimiting them is tested.', function () use ($explorer, $driverName) {
21+
test('dynamic SQL function placeholders', function () use ($explorer, $driverName) {
2222
$literal = match ($driverName) {
2323
'mysql' => new SqlLiteral('year(now())'),
2424
'pgsql' => new SqlLiteral('extract(year from now())::int'),
@@ -38,7 +38,7 @@ test('Leave literals lower-cased, also not-delimiting them is tested.', function
3838
});
3939

4040

41-
test('', function () use ($explorer) {
41+
test('group by with having on related count', function () use ($explorer) {
4242
$bookTagsCount = [];
4343
$books = $explorer
4444
->table('book')
@@ -58,7 +58,7 @@ test('', function () use ($explorer) {
5858
});
5959

6060

61-
test('', function () use ($explorer, $driverName) {
61+
test('custom field order with placeholders', function () use ($explorer, $driverName) {
6262
if ($driverName === 'mysql') {
6363
$authors = [];
6464
$selection = $explorer->table('author')->order('FIELD(name, ?)', ['Jakub Vrana', 'David Grudl', 'Geek']);
@@ -71,7 +71,7 @@ test('', function () use ($explorer, $driverName) {
7171
});
7272

7373

74-
test('Test placeholder for GroupedSelection', function () use ($explorer, $driverName) {
74+
test('unsupported syntax handling', function () use ($explorer, $driverName) {
7575
if ($driverName === 'sqlsrv') { // This syntax is not supported on SQL Server
7676
return;
7777
}

tests/Database/Explorer/Explorer.ref().phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverN
2020
Assert::same('Jakub Vrana', $explorer->table('book')->get(1)->ref('author')->name);
2121

2222

23-
test('', function () use ($explorer) {
23+
test('reference update and retrieval', function () use ($explorer) {
2424
$book = $explorer->table('book')->get(1);
2525
$book->update([
2626
'translator_id' => 12,
@@ -32,11 +32,11 @@ test('', function () use ($explorer) {
3232
});
3333

3434

35-
test('', function () use ($explorer) {
35+
test('null reference handling', function () use ($explorer) {
3636
Assert::null($explorer->table('book')->get(2)->ref('author', 'translator_id'));
3737
});
3838

39-
test('', function () use ($explorer, $connection) {
39+
test('query count on reference access', function () use ($explorer, $connection) {
4040
$counter = 0;
4141

4242
$connection->onQuery[] = function ($connection, $result) use (&$counter) {

0 commit comments

Comments
 (0)