| 1 | <?php |
| 2 | |
| 3 | // phpcs:disable |
| 4 | |
| 5 | /* |
| 6 | * Some RDBMS interfaces have methods with rather complicated Phan annotations. This test ensures |
| 7 | * that future versions of Phan still handle them correctly, and that future developers don't mess |
| 8 | * them up. |
| 9 | * |
| 10 | * If Phan reports new issues or unused suppressions in this file, DO NOT just fix the errors, |
| 11 | * and instead make sure that your patch is not breaking the annotations. |
| 12 | */ |
| 13 | |
| 14 | die( 'This file should never be loaded' ); |
| 15 | |
| 16 | class RdbmsTypeHintsTest { |
| 17 | function testExpr( \Wikimedia\Rdbms\IDatabase $db ) { |
| 18 | $conds = []; |
| 19 | |
| 20 | $expr = $db->expr( 'a', '=', 1 ); |
| 21 | // Return value of ->and() etc. must be used |
| 22 | // @phan-suppress-next-line PhanPluginUseReturnValueKnown |
| 23 | $expr->and( 'a', '=', 1 ); |
| 24 | |
| 25 | // Typo in the operator |
| 26 | // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal |
| 27 | $conds[] = $db->expr( 'a', '=<', 1 ); |
| 28 | |
| 29 | // We accept lots of types, but not all |
| 30 | // @phan-suppress-next-line PhanTypeMismatchArgumentProbablyReal |
| 31 | $conds[] = $db->expr( 'a', '=', new \stdClass ); |
| 32 | |
| 33 | // Empty arrays are not allowed |
| 34 | // @phan-suppress-next-line PhanTypeMismatchArgument |
| 35 | $conds[] = $db->expr( 'a', '=', [] ); |
| 36 | |
| 37 | // Null in arrays is not allowed (unlike in the `$qb->where( 'a' => [ ... ] )` syntax) |
| 38 | // @phan-suppress-next-line PhanTypeMismatchArgument |
| 39 | $conds[] = $db->expr( 'a', '=', [ 1, null, 2 ] ); |
| 40 | |
| 41 | // Associative arrays are not allowed |
| 42 | // @phan-suppress-next-line PhanTypeMismatchArgument |
| 43 | $conds[] = $db->expr( 'a', '=', [ 'a' => 1, 'b' => 2 ] ); |
| 44 | |
| 45 | // Arrays with gaps are not allowed (unlike in the `$qb->where( 'a' => [ ... ] )` syntax) |
| 46 | // @phan-suppress-next-line PhanTypeMismatchArgument |
| 47 | $conds[] = $db->expr( 'a', '=', array_unique( [ 1, 1, 2, 2 ] ) ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @suppress PhanParamTooFewInPHPDoc |
| 52 | */ |
| 53 | function testSelectConds( \Wikimedia\Rdbms\IDatabase $db ) { |
| 54 | // Missing key for array value |
| 55 | // @phan-suppress-next-line PhanTypeMismatchArgument |
| 56 | $db->select( 'a', 'b', [ [ 1, 2, 3 ] ] ); |
| 57 | |
| 58 | // Empty array value |
| 59 | // @phan-suppress-next-line PhanTypeMismatchArgument |
| 60 | $db->select( 'a', 'b', [ 'x' => [] ] ); |
| 61 | |
| 62 | // Unexpected key for IExpression value |
| 63 | // @phan-suppress-next-line PhanTypeMismatchArgument |
| 64 | $db->select( 'a', 'b', [ 'x' => $db->expr( 'x', '=', 1 ) ] ); |
| 65 | |
| 66 | // Nested array in array value |
| 67 | // @phan-suppress-next-line PhanTypeMismatchArgument |
| 68 | $db->select( 'a', 'b', [ 'x' => [ 1, 2, [ 3 ] ] ] ); |
| 69 | |
| 70 | // Associative arrays are not allowed |
| 71 | // @phan-suppress-next-line PhanTypeMismatchArgument |
| 72 | $db->select( 'a', 'b', [ 'x' => [ 'a' => 1, 'b' => 2 ] ] ); |
| 73 | } |
| 74 | } |