1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-30 01:09:50 +02:00

tests: fixes

This commit is contained in:
David Grudl
2015-11-04 14:23:14 +01:00
parent 5aab1ff023
commit 78d24a0e74
13 changed files with 72 additions and 88 deletions

View File

@@ -0,0 +1,76 @@
<?php
/**
* @dataProvider? ../databases.ini sqlsrv
*/
use Tester\Assert;
require __DIR__ . '/bootstrap.php';
$tests = function ($conn) {
$version = $conn->getDriver()->getResource()->getAttribute(PDO::ATTR_SERVER_VERSION);
// MsSQL2012+
if (version_compare($version, '11.0') >= 0) {
// Limit and offset
Assert::same(
'SELECT 1 OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY',
$conn->translate('SELECT 1 %ofs %lmt', 10, 10)
);
// Limit only
Assert::same(
'SELECT 1 OFFSET 0 ROWS FETCH NEXT 10 ROWS ONLY',
$conn->translate('SELECT 1 %lmt', 10)
);
// Offset only
Assert::same(
'SELECT 1 OFFSET 10 ROWS',
$conn->translate('SELECT 1 %ofs', 10)
);
// Offset invalid
Assert::same(
'SELECT 1',
$conn->translate('SELECT 1 %ofs', -10)
);
// Limit invalid
Assert::same(
'SELECT 1',
$conn->translate('SELECT 1 %lmt', -10)
);
// Limit invalid, offset valid
Assert::same(
'SELECT 1',
$conn->translate('SELECT 1 %ofs %lmt', 10, -10)
);
// Limit valid, offset invalid
Assert::same(
'SELECT 1',
$conn->translate('SELECT 1 %ofs %lmt', -10, 10)
);
} else {
Assert::same(
'SELECT TOP 1 * FROM (SELECT 1) t',
$conn->translate('SELECT 1 %lmt', 1)
);
Assert::same(
'SELECT 1',
$conn->translate('SELECT 1 %lmt', -10)
);
Assert::exception(
$conn->translate('SELECT 1 %ofs %lmt', 10, 10),
'DibiNotSupportedException'
);
}
};
$conn = new Dibi\Connection($config);
$tests($conn);