mirror of
https://github.com/dg/dibi.git
synced 2025-08-10 08:04:32 +02:00
This commit is contained in:
92
tests/dibi/Fluent.fetch.limit.phpt
Normal file
92
tests/dibi/Fluent.fetch.limit.phpt
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @dataProvider ../databases.ini
|
||||
*/
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
$conn = new Dibi\Connection($config);
|
||||
$conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
|
||||
// fetch & limit
|
||||
$fluent = $conn->select('*')
|
||||
->from('customers')
|
||||
->limit(1)
|
||||
->offset(3)
|
||||
->orderBy('customer_id');
|
||||
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
(string) $fluent
|
||||
);
|
||||
|
||||
|
||||
$fluent->fetch();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
$fluent->fetchSingle();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
(string) $fluent
|
||||
);
|
||||
|
||||
|
||||
$fluent->limit(0);
|
||||
$fluent->fetch();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 0 OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
$fluent->fetchSingle();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 0 OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 0 OFFSET 3'),
|
||||
(string) $fluent
|
||||
);
|
||||
|
||||
|
||||
$fluent->removeClause('limit');
|
||||
$fluent->fetch();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
$fluent->fetchSingle();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1 OFFSET 3'),
|
||||
dibi::$sql
|
||||
);
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] OFFSET 3'),
|
||||
(string) $fluent
|
||||
);
|
||||
|
||||
|
||||
$fluent->removeClause('offset');
|
||||
$fluent->fetch();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1'),
|
||||
dibi::$sql
|
||||
);
|
||||
$fluent->fetchSingle();
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id] LIMIT 1'),
|
||||
dibi::$sql
|
||||
);
|
||||
Assert::same(
|
||||
reformat('SELECT * FROM [customers] ORDER BY [customer_id]'),
|
||||
(string) $fluent
|
||||
);
|
@@ -81,7 +81,7 @@ try {
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
Assert::same(
|
||||
reformat(' SELECT * FROM [table] LIMIT 1'),
|
||||
reformat('SELECT * FROM [table] LIMIT 1'),
|
||||
dibi::$sql
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user