2024-05-11 23:18:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
// phpcs:disable
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Some RDBMS interfaces have methods with rather complicated Phan annotations. This test ensures
|
|
|
|
|
* that future versions of Phan still handle them correctly, and that future developers don't mess
|
|
|
|
|
* them up.
|
|
|
|
|
*
|
|
|
|
|
* If Phan reports new issues or unused suppressions in this file, DO NOT just fix the errors,
|
|
|
|
|
* and instead make sure that your patch is not breaking the annotations.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
die( 'This file should never be loaded' );
|
|
|
|
|
|
|
|
|
|
class RdbmsTypeHintsTest {
|
|
|
|
|
function testExpr( \Wikimedia\Rdbms\IDatabase $db ) {
|
|
|
|
|
$conds = [];
|
|
|
|
|
|
|
|
|
|
$expr = $db->expr( 'a', '=', 1 );
|
|
|
|
|
// Return value of ->and() etc. must be used
|
|
|
|
|
// @phan-suppress-next-line PhanPluginUseReturnValueKnown
|
|
|
|
|
$expr->and( 'a', '=', 1 );
|
|
|
|
|
|
2024-05-21 23:27:22 +00:00
|
|
|
// Typo in the operator
|
|
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal
|
|
|
|
|
$conds[] = $db->expr( 'a', '=<', 1 );
|
|
|
|
|
|
2024-05-11 23:18:25 +00:00
|
|
|
// We accept lots of types, but not all
|
|
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal
|
|
|
|
|
$conds[] = $db->expr( 'a', '=', new \stdClass );
|
|
|
|
|
|
|
|
|
|
// Empty arrays are not allowed
|
|
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgument
|
|
|
|
|
$conds[] = $db->expr( 'a', '=', [] );
|
|
|
|
|
|
|
|
|
|
// Null in arrays is not allowed (unlike in the `$qb->where( 'a' => [ ... ] )` syntax)
|
|
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgument
|
|
|
|
|
$conds[] = $db->expr( 'a', '=', [ 1, null, 2 ] );
|
2024-05-11 20:58:12 +00:00
|
|
|
|
|
|
|
|
// Associative arrays are not allowed
|
|
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgument
|
|
|
|
|
$conds[] = $db->expr( 'a', '=', [ 'a' => 1, 'b' => 2 ] );
|
|
|
|
|
|
|
|
|
|
// Arrays with gaps are not allowed (unlike in the `$qb->where( 'a' => [ ... ] )` syntax)
|
|
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgument
|
|
|
|
|
$conds[] = $db->expr( 'a', '=', array_unique( [ 1, 1, 2, 2 ] ) );
|
2024-05-11 23:18:25 +00:00
|
|
|
}
|
2024-05-11 18:10:35 +00:00
|
|
|
|
2024-09-19 19:05:48 +00:00
|
|
|
/**
|
|
|
|
|
* @suppress PhanParamTooFewInPHPDoc
|
|
|
|
|
*/
|
2024-05-11 18:10:35 +00:00
|
|
|
function testSelectConds( \Wikimedia\Rdbms\IDatabase $db ) {
|
|
|
|
|
// Missing key for array value
|
|
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgument
|
|
|
|
|
$db->select( 'a', 'b', [ [ 1, 2, 3 ] ] );
|
|
|
|
|
|
|
|
|
|
// Empty array value
|
|
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgument
|
|
|
|
|
$db->select( 'a', 'b', [ 'x' => [] ] );
|
|
|
|
|
|
|
|
|
|
// Unexpected key for IExpression value
|
|
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgument
|
|
|
|
|
$db->select( 'a', 'b', [ 'x' => $db->expr( 'x', '=', 1 ) ] );
|
|
|
|
|
|
|
|
|
|
// Nested array in array value
|
|
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgument
|
|
|
|
|
$db->select( 'a', 'b', [ 'x' => [ 1, 2, [ 3 ] ] ] );
|
2024-05-11 20:58:12 +00:00
|
|
|
|
|
|
|
|
// Associative arrays are not allowed
|
|
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgument
|
|
|
|
|
$db->select( 'a', 'b', [ 'x' => [ 'a' => 1, 'b' => 2 ] ] );
|
2024-05-11 18:10:35 +00:00
|
|
|
}
|
2024-05-11 23:18:25 +00:00
|
|
|
}
|