From fe02fd509563395fca38f36f7c20d588abba8f5d Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 23 Sep 2024 20:24:01 +0100 Subject: [PATCH] ext/gmp: Add behavioural tests for operator overloading --- .../tests/overloading_cmp_op_with_null.phpt | 53 +++++++ ext/gmp/tests/overloading_with_array.phpt | 93 ++++++++++++ ext/gmp/tests/overloading_with_float.phpt | 117 ++++++++++++++++ .../overloading_with_float_fractional.phpt | 132 ++++++++++++++++++ .../tests/overloading_with_float_string.phpt | 93 ++++++++++++ .../tests/overloading_with_int_string.phpt | 117 ++++++++++++++++ .../overloading_with_non_numeric_string.phpt | 93 ++++++++++++ ext/gmp/tests/overloading_with_null.phpt | 76 ++++++++++ ...verloading_with_object_not_stringable.phpt | 100 +++++++++++++ .../overloading_with_object_stringable.phpt | 106 ++++++++++++++ ext/gmp/tests/overloading_with_resource.phpt | 93 ++++++++++++ 11 files changed, 1073 insertions(+) create mode 100644 ext/gmp/tests/overloading_cmp_op_with_null.phpt create mode 100644 ext/gmp/tests/overloading_with_array.phpt create mode 100644 ext/gmp/tests/overloading_with_float.phpt create mode 100644 ext/gmp/tests/overloading_with_float_fractional.phpt create mode 100644 ext/gmp/tests/overloading_with_float_string.phpt create mode 100644 ext/gmp/tests/overloading_with_int_string.phpt create mode 100644 ext/gmp/tests/overloading_with_non_numeric_string.phpt create mode 100644 ext/gmp/tests/overloading_with_null.phpt create mode 100644 ext/gmp/tests/overloading_with_object_not_stringable.phpt create mode 100644 ext/gmp/tests/overloading_with_object_stringable.phpt create mode 100644 ext/gmp/tests/overloading_with_resource.phpt diff --git a/ext/gmp/tests/overloading_cmp_op_with_null.phpt b/ext/gmp/tests/overloading_cmp_op_with_null.phpt new file mode 100644 index 00000000000..d84ef967868 --- /dev/null +++ b/ext/gmp/tests/overloading_cmp_op_with_null.phpt @@ -0,0 +1,53 @@ +--TEST-- +GMP comparison operator overloading supports null +--EXTENSIONS-- +gmp +--FILE-- +getMessage(), PHP_EOL; +} + +try { + var_dump($num > null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num <= null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num >= null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num == null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num <=> null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +int(1) diff --git a/ext/gmp/tests/overloading_with_array.phpt b/ext/gmp/tests/overloading_with_array.phpt new file mode 100644 index 00000000000..834860c79a3 --- /dev/null +++ b/ext/gmp/tests/overloading_with_array.phpt @@ -0,0 +1,93 @@ +--TEST-- +GMP operator overloading does not support [] +--EXTENSIONS-- +gmp +--FILE-- +getMessage(), PHP_EOL; +} + +try { + var_dump($num - []); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num * []); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num / []); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num % []); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num ** []); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num | []); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num & []); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num ^ []); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num << []); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num >> []); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +TypeError: Number must be of type GMP|string|int, array given +TypeError: Number must be of type GMP|string|int, array given +TypeError: Number must be of type GMP|string|int, array given +TypeError: Number must be of type GMP|string|int, array given +TypeError: Number must be of type GMP|string|int, array given +object(GMP)#3 (1) { + ["num"]=> + string(1) "1" +} +TypeError: Number must be of type GMP|string|int, array given +TypeError: Number must be of type GMP|string|int, array given +TypeError: Number must be of type GMP|string|int, array given +object(GMP)#2 (1) { + ["num"]=> + string(2) "42" +} +object(GMP)#2 (1) { + ["num"]=> + string(2) "42" +} diff --git a/ext/gmp/tests/overloading_with_float.phpt b/ext/gmp/tests/overloading_with_float.phpt new file mode 100644 index 00000000000..f2bcfa7d514 --- /dev/null +++ b/ext/gmp/tests/overloading_with_float.phpt @@ -0,0 +1,117 @@ +--TEST-- +GMP operator overloading does support float with no fractional +--EXTENSIONS-- +gmp +--FILE-- +getMessage(), PHP_EOL; +} + +try { + var_dump($num - 42.0); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num * 42.0); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num / 42.0); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num % 42.0); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num ** 42.0); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num | 42.0); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num & 42.0); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num ^ 42.0); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num << 42.0); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num >> 42.0); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +object(GMP)#2 (1) { + ["num"]=> + string(2) "84" +} +object(GMP)#2 (1) { + ["num"]=> + string(1) "0" +} +object(GMP)#2 (1) { + ["num"]=> + string(4) "1764" +} +object(GMP)#2 (1) { + ["num"]=> + string(1) "1" +} +object(GMP)#2 (1) { + ["num"]=> + string(1) "0" +} +object(GMP)#2 (1) { + ["num"]=> + string(69) "150130937545296572356771972164254457814047970568738777235893533016064" +} +object(GMP)#2 (1) { + ["num"]=> + string(2) "42" +} +object(GMP)#2 (1) { + ["num"]=> + string(2) "42" +} +object(GMP)#2 (1) { + ["num"]=> + string(1) "0" +} +object(GMP)#2 (1) { + ["num"]=> + string(15) "184717953466368" +} +object(GMP)#2 (1) { + ["num"]=> + string(1) "0" +} diff --git a/ext/gmp/tests/overloading_with_float_fractional.phpt b/ext/gmp/tests/overloading_with_float_fractional.phpt new file mode 100644 index 00000000000..fc078eeec3e --- /dev/null +++ b/ext/gmp/tests/overloading_with_float_fractional.phpt @@ -0,0 +1,132 @@ +--TEST-- +GMP operator overloading support for float with fractional is deprecated +--EXTENSIONS-- +gmp +--FILE-- +getMessage(), PHP_EOL; +} + +try { + var_dump($num - 42.5); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num * 42.5); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num / 42.5); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num % 42.5); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num ** 42.5); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num | 42.5); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num & 42.5); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num ^ 42.5); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num << 42.5); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num >> 42.5); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECTF-- +Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d +object(GMP)#2 (1) { + ["num"]=> + string(2) "84" +} + +Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d +object(GMP)#2 (1) { + ["num"]=> + string(1) "0" +} + +Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d +object(GMP)#2 (1) { + ["num"]=> + string(4) "1764" +} + +Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d +object(GMP)#2 (1) { + ["num"]=> + string(1) "1" +} + +Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d +object(GMP)#2 (1) { + ["num"]=> + string(1) "0" +} +object(GMP)#2 (1) { + ["num"]=> + string(69) "150130937545296572356771972164254457814047970568738777235893533016064" +} + +Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d +object(GMP)#2 (1) { + ["num"]=> + string(2) "42" +} + +Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d +object(GMP)#2 (1) { + ["num"]=> + string(2) "42" +} + +Deprecated: Implicit conversion from float 42.5 to int loses precision in %s on line %d +object(GMP)#2 (1) { + ["num"]=> + string(1) "0" +} +object(GMP)#2 (1) { + ["num"]=> + string(15) "184717953466368" +} +object(GMP)#2 (1) { + ["num"]=> + string(1) "0" +} diff --git a/ext/gmp/tests/overloading_with_float_string.phpt b/ext/gmp/tests/overloading_with_float_string.phpt new file mode 100644 index 00000000000..f715d5740b3 --- /dev/null +++ b/ext/gmp/tests/overloading_with_float_string.phpt @@ -0,0 +1,93 @@ +--TEST-- +GMP operator overloading does not support float strings +--EXTENSIONS-- +gmp +--FILE-- +getMessage(), PHP_EOL; +} + +try { + var_dump($num - "2.0"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num * "2.0"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num / "2.0"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num % "2.0"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num ** "2.0"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num | "2.0"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num & "2.0"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num ^ "2.0"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num << "2.0"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num >> "2.0"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +ValueError: Number is not an integer string +ValueError: Number is not an integer string +ValueError: Number is not an integer string +ValueError: Number is not an integer string +ValueError: Number is not an integer string +object(GMP)#3 (1) { + ["num"]=> + string(4) "1764" +} +ValueError: Number is not an integer string +ValueError: Number is not an integer string +ValueError: Number is not an integer string +object(GMP)#2 (1) { + ["num"]=> + string(3) "168" +} +object(GMP)#2 (1) { + ["num"]=> + string(2) "10" +} diff --git a/ext/gmp/tests/overloading_with_int_string.phpt b/ext/gmp/tests/overloading_with_int_string.phpt new file mode 100644 index 00000000000..252916ef9a5 --- /dev/null +++ b/ext/gmp/tests/overloading_with_int_string.phpt @@ -0,0 +1,117 @@ +--TEST-- +GMP operator overloading does support int strings +--EXTENSIONS-- +gmp +--FILE-- +getMessage(), PHP_EOL; +} + +try { + var_dump($num - "2"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num * "2"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num / "2"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num % "2"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num ** "2"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num | "2"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num & "2"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num ^ "2"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num << "2"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num >> "2"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +object(GMP)#2 (1) { + ["num"]=> + string(2) "44" +} +object(GMP)#2 (1) { + ["num"]=> + string(2) "40" +} +object(GMP)#2 (1) { + ["num"]=> + string(2) "84" +} +object(GMP)#2 (1) { + ["num"]=> + string(2) "21" +} +object(GMP)#2 (1) { + ["num"]=> + string(1) "0" +} +object(GMP)#2 (1) { + ["num"]=> + string(4) "1764" +} +object(GMP)#2 (1) { + ["num"]=> + string(2) "42" +} +object(GMP)#2 (1) { + ["num"]=> + string(1) "2" +} +object(GMP)#2 (1) { + ["num"]=> + string(2) "40" +} +object(GMP)#2 (1) { + ["num"]=> + string(3) "168" +} +object(GMP)#2 (1) { + ["num"]=> + string(2) "10" +} diff --git a/ext/gmp/tests/overloading_with_non_numeric_string.phpt b/ext/gmp/tests/overloading_with_non_numeric_string.phpt new file mode 100644 index 00000000000..3068c31dd8a --- /dev/null +++ b/ext/gmp/tests/overloading_with_non_numeric_string.phpt @@ -0,0 +1,93 @@ +--TEST-- +GMP operator overloading does not support non-numeric strings +--EXTENSIONS-- +gmp +--FILE-- +getMessage(), PHP_EOL; +} + +try { + var_dump($num - "string"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num * "string"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num / "string"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num % "string"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num ** "string"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num | "string"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num & "string"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num ^ "string"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num << "string"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num >> "string"); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +ValueError: Number is not an integer string +ValueError: Number is not an integer string +ValueError: Number is not an integer string +ValueError: Number is not an integer string +ValueError: Number is not an integer string +object(GMP)#3 (1) { + ["num"]=> + string(1) "1" +} +ValueError: Number is not an integer string +ValueError: Number is not an integer string +ValueError: Number is not an integer string +object(GMP)#2 (1) { + ["num"]=> + string(2) "42" +} +object(GMP)#2 (1) { + ["num"]=> + string(2) "42" +} diff --git a/ext/gmp/tests/overloading_with_null.phpt b/ext/gmp/tests/overloading_with_null.phpt new file mode 100644 index 00000000000..4087e499f46 --- /dev/null +++ b/ext/gmp/tests/overloading_with_null.phpt @@ -0,0 +1,76 @@ +--TEST-- +GMP operator overloading does not support null +--EXTENSIONS-- +gmp +--XFAIL-- +Test showcasing segfaulting behaviour +--FILE-- +getMessage(), PHP_EOL; +} + +try { + var_dump($num - null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num * null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num / null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num % null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num ** null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num | null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num & null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num ^ null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num << null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num >> null); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +SEGFAULT diff --git a/ext/gmp/tests/overloading_with_object_not_stringable.phpt b/ext/gmp/tests/overloading_with_object_not_stringable.phpt new file mode 100644 index 00000000000..a3db01c6933 --- /dev/null +++ b/ext/gmp/tests/overloading_with_object_not_stringable.phpt @@ -0,0 +1,100 @@ +--TEST-- +GMP operator overloading does not support non-stringable objects +--EXTENSIONS-- +gmp +--FILE-- +getMessage(), PHP_EOL; +} + +try { + var_dump($num - $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num * $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num / $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num % $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num ** $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num | $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num & $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num ^ $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num << $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num >> $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECTF-- +TypeError: Number must be of type GMP|string|int, stdClass given +TypeError: Number must be of type GMP|string|int, stdClass given +TypeError: Number must be of type GMP|string|int, stdClass given +TypeError: Number must be of type GMP|string|int, stdClass given +TypeError: Number must be of type GMP|string|int, stdClass given + +Warning: Object of class stdClass could not be converted to int in %s on line %d +object(GMP)#4 (1) { + ["num"]=> + string(2) "42" +} +TypeError: Number must be of type GMP|string|int, stdClass given +TypeError: Number must be of type GMP|string|int, stdClass given +TypeError: Number must be of type GMP|string|int, stdClass given + +Warning: Object of class stdClass could not be converted to int in %s on line %d +object(GMP)#3 (1) { + ["num"]=> + string(2) "84" +} + +Warning: Object of class stdClass could not be converted to int in %s on line %d +object(GMP)#3 (1) { + ["num"]=> + string(2) "21" +} diff --git a/ext/gmp/tests/overloading_with_object_stringable.phpt b/ext/gmp/tests/overloading_with_object_stringable.phpt new file mode 100644 index 00000000000..01bf7df6ea7 --- /dev/null +++ b/ext/gmp/tests/overloading_with_object_stringable.phpt @@ -0,0 +1,106 @@ +--TEST-- +GMP operator overloading does not support stringable objects +--EXTENSIONS-- +gmp +--FILE-- +getMessage(), PHP_EOL; +} + +try { + var_dump($num - $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num * $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num / $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num % $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num ** $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num | $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num & $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num ^ $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num << $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num >> $o); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECTF-- +TypeError: Number must be of type GMP|string|int, T given +TypeError: Number must be of type GMP|string|int, T given +TypeError: Number must be of type GMP|string|int, T given +TypeError: Number must be of type GMP|string|int, T given +TypeError: Number must be of type GMP|string|int, T given + +Warning: Object of class T could not be converted to int in %s on line %d +object(GMP)#4 (1) { + ["num"]=> + string(2) "42" +} +TypeError: Number must be of type GMP|string|int, T given +TypeError: Number must be of type GMP|string|int, T given +TypeError: Number must be of type GMP|string|int, T given + +Warning: Object of class T could not be converted to int in %s on line %d +object(GMP)#3 (1) { + ["num"]=> + string(2) "84" +} + +Warning: Object of class T could not be converted to int in %s on line %d +object(GMP)#3 (1) { + ["num"]=> + string(2) "21" +} diff --git a/ext/gmp/tests/overloading_with_resource.phpt b/ext/gmp/tests/overloading_with_resource.phpt new file mode 100644 index 00000000000..05f52492a64 --- /dev/null +++ b/ext/gmp/tests/overloading_with_resource.phpt @@ -0,0 +1,93 @@ +--TEST-- +GMP operator overloading does not support resources +--EXTENSIONS-- +gmp +--FILE-- +getMessage(), PHP_EOL; +} + +try { + var_dump($num - STDERR); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num * STDERR); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num / STDERR); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num % STDERR); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num ** STDERR); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +try { + var_dump($num | STDERR); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num & STDERR); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num ^ STDERR); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num << STDERR); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} +try { + var_dump($num >> STDERR); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +TypeError: Number must be of type GMP|string|int, resource given +TypeError: Number must be of type GMP|string|int, resource given +TypeError: Number must be of type GMP|string|int, resource given +TypeError: Number must be of type GMP|string|int, resource given +TypeError: Number must be of type GMP|string|int, resource given +object(GMP)#3 (1) { + ["num"]=> + string(5) "74088" +} +TypeError: Number must be of type GMP|string|int, resource given +TypeError: Number must be of type GMP|string|int, resource given +TypeError: Number must be of type GMP|string|int, resource given +object(GMP)#2 (1) { + ["num"]=> + string(3) "336" +} +object(GMP)#2 (1) { + ["num"]=> + string(1) "5" +}