mirror of
https://github.com/dg/dibi.git
synced 2025-08-16 11:04:43 +02:00
used PHP 7.1 features
- ::class - ... argument unpacking - removed call_user_func - operator ?? - list() - short <?=
This commit is contained in:
@@ -34,7 +34,7 @@ test(function () use ($config) { // query string
|
||||
|
||||
Assert::null($conn->getConfig('lazy'));
|
||||
Assert::same($config['driver'], $conn->getConfig('driver'));
|
||||
Assert::type('Dibi\Driver', $conn->getDriver());
|
||||
Assert::type(Dibi\Driver::class, $conn->getDriver());
|
||||
});
|
||||
|
||||
|
||||
|
@@ -15,16 +15,16 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
/*Assert::exception(function () use ($conn) {
|
||||
$conn->rollback();
|
||||
}, 'Dibi\Exception');
|
||||
}, Dibi\Exception::class);
|
||||
|
||||
Assert::exception(function () use ($conn) {
|
||||
$conn->commit();
|
||||
}, 'Dibi\Exception');
|
||||
}, Dibi\Exception::class);
|
||||
|
||||
$conn->begin();
|
||||
Assert::exception(function () use ($conn) {
|
||||
$conn->begin();
|
||||
}, 'Dibi\Exception');
|
||||
}, Dibi\Exception::class);
|
||||
*/
|
||||
|
||||
|
||||
|
@@ -13,7 +13,7 @@ class MockResult extends Dibi\Result
|
||||
|
||||
function test($row)
|
||||
{
|
||||
$normalize = new ReflectionMethod('Dibi\Result', 'normalize');
|
||||
$normalize = new ReflectionMethod(Dibi\Result::class, 'normalize');
|
||||
$normalize->setAccessible(TRUE);
|
||||
$normalize->invokeArgs($this, [&$row]);
|
||||
return $row;
|
||||
@@ -164,7 +164,7 @@ test(function () {
|
||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
||||
Assert::exception(function () use ($result) {
|
||||
$result->test(['col' => TRUE]);
|
||||
}, 'Exception');
|
||||
}, Exception::class);
|
||||
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
|
||||
|
||||
Assert::same(['col' => NULL], $result->test(['col' => '']));
|
||||
@@ -183,7 +183,7 @@ test(function () {
|
||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
||||
Assert::exception(function () use ($result) {
|
||||
$result->test(['col' => TRUE]);
|
||||
}, 'Exception');
|
||||
}, Exception::class);
|
||||
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
|
||||
|
||||
Assert::same(['col' => NULL], $result->test(['col' => '']));
|
||||
@@ -201,7 +201,7 @@ test(function () {
|
||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
||||
Assert::exception(function () use ($result) {
|
||||
$result->test(['col' => TRUE]);
|
||||
}, 'Exception');
|
||||
}, Exception::class);
|
||||
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
|
||||
|
||||
Assert::same(['col' => NULL], $result->test(['col' => '']));
|
||||
@@ -217,7 +217,7 @@ test(function () {
|
||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
||||
Assert::exception(function () use ($result) {
|
||||
$result->test(['col' => TRUE]);
|
||||
}, 'Exception');
|
||||
}, Exception::class);
|
||||
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
|
||||
|
||||
Assert::same(['col' => NULL], $result->test(['col' => '']));
|
||||
|
@@ -39,7 +39,7 @@ $tests = function ($conn) {
|
||||
function () use ($conn) {
|
||||
$conn->translate('SELECT 1 %ofs', -10);
|
||||
},
|
||||
'Dibi\NotSupportedException',
|
||||
Dibi\NotSupportedException::class,
|
||||
'Negative offset or limit.'
|
||||
);
|
||||
|
||||
@@ -48,7 +48,7 @@ $tests = function ($conn) {
|
||||
function () use ($conn) {
|
||||
$conn->translate('SELECT 1 %lmt', -10);
|
||||
},
|
||||
'Dibi\NotSupportedException',
|
||||
Dibi\NotSupportedException::class,
|
||||
'Negative offset or limit.'
|
||||
);
|
||||
|
||||
@@ -57,7 +57,7 @@ $tests = function ($conn) {
|
||||
function () use ($conn) {
|
||||
$conn->translate('SELECT 1 %ofs %lmt', 10, -10);
|
||||
},
|
||||
'Dibi\NotSupportedException',
|
||||
Dibi\NotSupportedException::class,
|
||||
'Negative offset or limit.'
|
||||
);
|
||||
|
||||
@@ -66,7 +66,7 @@ $tests = function ($conn) {
|
||||
function () use ($conn) {
|
||||
$conn->translate('SELECT 1 %ofs %lmt', -10, 10);
|
||||
},
|
||||
'Dibi\NotSupportedException',
|
||||
Dibi\NotSupportedException::class,
|
||||
'Negative offset or limit.'
|
||||
);
|
||||
} else {
|
||||
@@ -82,7 +82,7 @@ $tests = function ($conn) {
|
||||
|
||||
Assert::exception(
|
||||
$conn->translate('SELECT 1 %ofs %lmt', 10, 10),
|
||||
'DibiNotSupportedException'
|
||||
Dibi\NotSupportedException::class
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@@ -51,53 +51,53 @@ class TestChild extends TestClass
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$obj->undeclared();
|
||||
}, 'LogicException', 'Call to undefined method TestClass::undeclared().');
|
||||
}, LogicException::class, 'Call to undefined method TestClass::undeclared().');
|
||||
|
||||
Assert::exception(function () {
|
||||
TestClass::undeclared();
|
||||
}, 'LogicException', 'Call to undefined static method TestClass::undeclared().');
|
||||
}, LogicException::class, 'Call to undefined static method TestClass::undeclared().');
|
||||
|
||||
Assert::exception(function () {
|
||||
$obj = new TestChild;
|
||||
$obj->callParent();
|
||||
}, 'LogicException', 'Call to undefined method parent::callParent().');
|
||||
}, LogicException::class, 'Call to undefined method parent::callParent().');
|
||||
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$obj->publicMethodX();
|
||||
}, 'LogicException', 'Call to undefined method TestClass::publicMethodX(), did you mean publicMethod()?');
|
||||
}, LogicException::class, 'Call to undefined method TestClass::publicMethodX(), did you mean publicMethod()?');
|
||||
|
||||
Assert::exception(function () { // suggest static method
|
||||
$obj = new TestClass;
|
||||
$obj->publicMethodStaticX();
|
||||
}, 'LogicException', 'Call to undefined method TestClass::publicMethodStaticX(), did you mean publicMethodStatic()?');
|
||||
}, LogicException::class, 'Call to undefined method TestClass::publicMethodStaticX(), did you mean publicMethodStatic()?');
|
||||
|
||||
Assert::exception(function () { // suggest only public method
|
||||
$obj = new TestClass;
|
||||
$obj->protectedMethodX();
|
||||
}, 'LogicException', 'Call to undefined method TestClass::protectedMethodX().');
|
||||
}, LogicException::class, 'Call to undefined method TestClass::protectedMethodX().');
|
||||
|
||||
|
||||
// writing
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$obj->undeclared = 'value';
|
||||
}, 'LogicException', 'Attempt to write to undeclared property TestClass::$undeclared.');
|
||||
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$undeclared.');
|
||||
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$obj->publicX = 'value';
|
||||
}, 'LogicException', 'Attempt to write to undeclared property TestClass::$publicX, did you mean $public?');
|
||||
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$publicX, did you mean $public?');
|
||||
|
||||
Assert::exception(function () { // suggest only non-static property
|
||||
$obj = new TestClass;
|
||||
$obj->publicStaticX = 'value';
|
||||
}, 'LogicException', 'Attempt to write to undeclared property TestClass::$publicStaticX.');
|
||||
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$publicStaticX.');
|
||||
|
||||
Assert::exception(function () { // suggest only public property
|
||||
$obj = new TestClass;
|
||||
$obj->protectedX = 'value';
|
||||
}, 'LogicException', 'Attempt to write to undeclared property TestClass::$protectedX.');
|
||||
}, LogicException::class, 'Attempt to write to undeclared property TestClass::$protectedX.');
|
||||
|
||||
|
||||
// property getter
|
||||
@@ -112,29 +112,29 @@ Assert::same(456, $obj->foo);
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$val = $obj->undeclared;
|
||||
}, 'LogicException', 'Attempt to read undeclared property TestClass::$undeclared.');
|
||||
}, LogicException::class, 'Attempt to read undeclared property TestClass::$undeclared.');
|
||||
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
$val = $obj->publicX;
|
||||
}, 'LogicException', 'Attempt to read undeclared property TestClass::$publicX, did you mean $public?');
|
||||
}, LogicException::class, 'Attempt to read undeclared property TestClass::$publicX, did you mean $public?');
|
||||
|
||||
Assert::exception(function () { // suggest only non-static property
|
||||
$obj = new TestClass;
|
||||
$val = $obj->publicStaticX;
|
||||
}, 'LogicException', 'Attempt to read undeclared property TestClass::$publicStaticX.');
|
||||
}, LogicException::class, 'Attempt to read undeclared property TestClass::$publicStaticX.');
|
||||
|
||||
Assert::exception(function () { // suggest only public property
|
||||
$obj = new TestClass;
|
||||
$val = $obj->protectedX;
|
||||
}, 'LogicException', 'Attempt to read undeclared property TestClass::$protectedX.');
|
||||
}, LogicException::class, 'Attempt to read undeclared property TestClass::$protectedX.');
|
||||
|
||||
|
||||
// unset/isset
|
||||
Assert::exception(function () {
|
||||
$obj = new TestClass;
|
||||
unset($obj->undeclared);
|
||||
}, 'LogicException', 'Attempt to unset undeclared property TestClass::$undeclared.');
|
||||
}, LogicException::class, 'Attempt to unset undeclared property TestClass::$undeclared.');
|
||||
|
||||
Assert::false(isset($obj->undeclared));
|
||||
|
||||
|
@@ -77,7 +77,7 @@ Assert::same(
|
||||
// invalid input
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->translate('SELECT %s', (object) [123], ', %m', 123);
|
||||
}, 'Dibi\Exception', 'SQL translate error: Invalid combination of type stdClass and modifier %s');
|
||||
}, Dibi\Exception::class, 'SQL translate error: Invalid combination of type stdClass and modifier %s');
|
||||
Assert::same('SELECT **Invalid combination of type stdClass and modifier %s** , **Unknown or unexpected modifier %m**', $e->getSql());
|
||||
|
||||
Assert::same(
|
||||
@@ -150,7 +150,7 @@ Assert::same(
|
||||
if ($config['system'] === 'odbc') {
|
||||
Assert::exception(function () use ($conn) {
|
||||
$conn->translate('SELECT * FROM [products] %lmt %ofs', 2, 1);
|
||||
}, 'Dibi\Exception');
|
||||
}, Dibi\Exception::class);
|
||||
} else {
|
||||
// with limit = 2, offset = 1
|
||||
Assert::same(
|
||||
@@ -198,7 +198,7 @@ Assert::same(
|
||||
|
||||
Assert::exception(function () use ($conn) {
|
||||
$conn->translate('SELECT %s', new DateTime('1212-09-26'));
|
||||
}, 'Dibi\Exception', 'SQL translate error: Invalid combination of type Dibi\DateTime and modifier %s');
|
||||
}, Dibi\Exception::class, 'SQL translate error: Invalid combination of type Dibi\DateTime and modifier %s');
|
||||
|
||||
|
||||
|
||||
@@ -240,7 +240,7 @@ if ($config['system'] === 'postgre') {
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->translate("SELECT '");
|
||||
}, 'Dibi\Exception', 'SQL translate error: Alone quote');
|
||||
}, Dibi\Exception::class, 'SQL translate error: Alone quote');
|
||||
Assert::same('SELECT **Alone quote**', $e->getSql());
|
||||
|
||||
Assert::match(
|
||||
@@ -491,7 +491,7 @@ $e = Assert::exception(function () use ($conn) {
|
||||
'num%i' => ['1', ''],
|
||||
];
|
||||
$conn->translate('INSERT INTO test %m', $array6);
|
||||
}, 'Dibi\Exception', 'SQL translate error: Multi-insert array "num%i" is different');
|
||||
}, Dibi\Exception::class, 'SQL translate error: Multi-insert array "num%i" is different');
|
||||
Assert::same('INSERT INTO test **Multi-insert array "num%i" is different**', $e->getSql());
|
||||
|
||||
$array6 = [
|
||||
|
@@ -15,27 +15,27 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('SELECT');
|
||||
}, 'Dibi\DriverException', "%a% error in your SQL syntax;%a%", 1064);
|
||||
}, Dibi\DriverException::class, "%a% error in your SQL syntax;%a%", 1064);
|
||||
|
||||
Assert::same('SELECT', $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
|
||||
}, 'Dibi\UniqueConstraintViolationException', "%a?%Duplicate entry '1' for key 'PRIMARY'", 1062);
|
||||
}, Dibi\UniqueConstraintViolationException::class, "%a?%Duplicate entry '1' for key 'PRIMARY'", 1062);
|
||||
|
||||
Assert::same("INSERT INTO products (product_id, title) VALUES (1, 'New')", $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (title) VALUES (NULL)');
|
||||
}, 'Dibi\NotNullConstraintViolationException', "%a?%Column 'title' cannot be null", 1048);
|
||||
}, Dibi\NotNullConstraintViolationException::class, "%a?%Column 'title' cannot be null", 1048);
|
||||
|
||||
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)');
|
||||
}, 'Dibi\ForeignKeyConstraintViolationException', '%a% a foreign key constraint fails %a%', 1452);
|
||||
}, Dibi\ForeignKeyConstraintViolationException::class, '%a% a foreign key constraint fails %a%', 1452);
|
||||
|
||||
Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());
|
||||
|
@@ -15,27 +15,27 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('SELECT INTO');
|
||||
}, 'Dibi\DriverException', '%a?%syntax error %A%');
|
||||
}, Dibi\DriverException::class, '%a?%syntax error %A%');
|
||||
|
||||
Assert::same('SELECT INTO', $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
|
||||
}, 'Dibi\UniqueConstraintViolationException', '%a% violates unique constraint %A%', '23505');
|
||||
}, Dibi\UniqueConstraintViolationException::class, '%a% violates unique constraint %A%', '23505');
|
||||
|
||||
Assert::same("INSERT INTO products (product_id, title) VALUES (1, 'New')", $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (title) VALUES (NULL)');
|
||||
}, 'Dibi\NotNullConstraintViolationException', '%a?%null value in column "title" violates not-null constraint%A?%', '23502');
|
||||
}, Dibi\NotNullConstraintViolationException::class, '%a?%null value in column "title" violates not-null constraint%A?%', '23502');
|
||||
|
||||
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)');
|
||||
}, 'Dibi\ForeignKeyConstraintViolationException', '%a% violates foreign key constraint %A%', '23503');
|
||||
}, Dibi\ForeignKeyConstraintViolationException::class, '%a% violates foreign key constraint %A%', '23503');
|
||||
|
||||
Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());
|
||||
|
@@ -15,21 +15,21 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql");
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('SELECT');
|
||||
}, 'Dibi\DriverException', '%a% syntax error', 1);
|
||||
}, Dibi\DriverException::class, '%a% syntax error', 1);
|
||||
|
||||
Assert::same('SELECT', $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (product_id, title) VALUES (1, "New")');
|
||||
}, 'Dibi\UniqueConstraintViolationException', NULL, 19);
|
||||
}, Dibi\UniqueConstraintViolationException::class, NULL, 19);
|
||||
|
||||
Assert::same("INSERT INTO products (product_id, title) VALUES (1, 'New')", $e->getSql());
|
||||
|
||||
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('INSERT INTO products (title) VALUES (NULL)');
|
||||
}, 'Dibi\NotNullConstraintViolationException', NULL, 19);
|
||||
}, Dibi\NotNullConstraintViolationException::class, NULL, 19);
|
||||
|
||||
Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
||||
|
||||
@@ -37,6 +37,6 @@ Assert::same('INSERT INTO products (title) VALUES (NULL)', $e->getSql());
|
||||
$e = Assert::exception(function () use ($conn) {
|
||||
$conn->query('PRAGMA foreign_keys=true');
|
||||
$conn->query('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)');
|
||||
}, 'Dibi\ForeignKeyConstraintViolationException', NULL, 19);
|
||||
}, Dibi\ForeignKeyConstraintViolationException::class, NULL, 19);
|
||||
|
||||
Assert::same('INSERT INTO orders (customer_id, product_id, amount) VALUES (100, 1, 1)', $e->getSql());
|
||||
|
Reference in New Issue
Block a user