com php-src: Fixed tests: Zend/tests/typehints/scalar_return _basic.phpt Zend/tests/typehints/scalar_return_basic _64bit.phpt
Zend/tests/typehints/scalar_strict.ph pt Zend/tests/typehints/scalar_strict_64bit.phpt
| From: | Dmitry Stogov | Date: | Fri, 20 Mar 2015 14:56:32 +0000 |
| Subject: | com php-src: Fixed tests: Zend/tests/typehints/scalar_return _basic.phpt Zend/tests/typehints/scalar_return_basic _64bit.phpt Zend/tests/typehints/scalar_strict.ph pt Zend/tests/typehints/scalar_strict_64bit.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-85673@lists.php.net to get a copy of this message | ||
Commit: 139c6c644c97098b0d57eb25b5d7c169423b5ca0
Author: Dmitry Stogov <dmitry@zend.com> Fri, 20 Mar 2015 17:56:32 +0300
Parents: 054591ab9ae17daeea630699c640a79b6f9291db
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=139c6c644c97098b0d57eb25b5d7c169423b5ca0
Log:
Fixed tests
Changed paths:
M Zend/tests/typehints/scalar_return_basic.phpt
A Zend/tests/typehints/scalar_return_basic_64bit.phpt
M Zend/tests/typehints/scalar_strict.phpt
A Zend/tests/typehints/scalar_strict_64bit.phpt
diff --git a/Zend/tests/typehints/scalar_return_basic.phpt b/Zend/tests/typehints/scalar_return_basic.phpt index d33fb5d..65bef01 100644 --- a/Zend/tests/typehints/scalar_return_basic.phpt +++ b/Zend/tests/typehints/scalar_return_basic.phpt @@ -1,5 +1,7 @@ --TEST-- Return scalar type hint basics +--SKIPIF-- +<?php if (PHP_INT_SIZE != 4) die("skip this test is for 64bit platform only"); ?> --FILE-- <?php @@ -77,8 +79,8 @@ int(1) *** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d *** Trying string(0) "" *** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d -*** Trying int(9223372036854775807) -int(9223372036854775807) +*** Trying int(2147483647) +int(2147483647) *** Trying float(NAN) *** Caught Return value of {closure}() must be of the type integer, float returned in %s on line %d *** Trying bool(true) @@ -115,8 +117,8 @@ float(1) *** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d *** Trying string(0) "" *** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d -*** Trying int(9223372036854775807) -float(9.2233720368548E+18) +*** Trying int(2147483647) +float(2147483647) *** Trying float(NAN) float(NAN) *** Trying bool(true) @@ -152,8 +154,8 @@ string(2) "1a" string(1) "a" *** Trying string(0) "" string(0) "" -*** Trying int(9223372036854775807) -string(19) "9223372036854775807" +*** Trying int(2147483647) +string(10) "2147483647" *** Trying float(NAN) string(3) "NAN" *** Trying bool(true) @@ -189,7 +191,7 @@ bool(true) bool(true) *** Trying string(0) "" bool(false) -*** Trying int(9223372036854775807) +*** Trying int(2147483647) bool(true) *** Trying float(NAN) bool(true) diff --git a/Zend/tests/typehints/scalar_return_basic_64bit.phpt b/Zend/tests/typehints/scalar_return_basic_64bit.phpt new file mode 100644 index 0000000..edb5231 --- /dev/null +++ b/Zend/tests/typehints/scalar_return_basic_64bit.phpt @@ -0,0 +1,216 @@ +--TEST-- +Return scalar type hint basics +--SKIPIF-- +<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> +--FILE-- +<?php + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function ($i): int { return $i; }, + 'float' => function ($f): float { return $f; }, + 'string' => function ($s): string { return $s; }, + 'bool' => function ($b): bool { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; + foreach ($values as $value) { + echo "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' typehint: +*** Trying int(1) +int(1) +*** Trying string(1) "1" +int(1) +*** Trying float(1) +int(1) +*** Trying float(1.5) +int(1) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +int(1) +*** Trying string(1) "a" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d +*** Trying string(0) "" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d +*** Trying int(9223372036854775807) +int(9223372036854775807) +*** Trying float(NAN) +*** Caught Return value of {closure}() must be of the type integer, float returned in %s on line %d +*** Trying bool(true) +int(1) +*** Trying bool(false) +int(0) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type integer, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type integer, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type integer, resource returned in %s on line %d + +Testing 'float' typehint: +*** Trying int(1) +float(1) +*** Trying string(1) "1" +float(1) +*** Trying float(1) +float(1) +*** Trying float(1.5) +float(1.5) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +float(1) +*** Trying string(1) "a" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d +*** Trying string(0) "" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d +*** Trying int(9223372036854775807) +float(9.2233720368548E+18) +*** Trying float(NAN) +float(NAN) +*** Trying bool(true) +float(1) +*** Trying bool(false) +float(0) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type float, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type float, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type float, resource returned in %s on line %d + +Testing 'string' typehint: +*** Trying int(1) +string(1) "1" +*** Trying string(1) "1" +string(1) "1" +*** Trying float(1) +string(1) "1" +*** Trying float(1.5) +string(3) "1.5" +*** Trying string(2) "1a" +string(2) "1a" +*** Trying string(1) "a" +string(1) "a" +*** Trying string(0) "" +string(0) "" +*** Trying int(9223372036854775807) +string(19) "9223372036854775807" +*** Trying float(NAN) +string(3) "NAN" +*** Trying bool(true) +string(1) "1" +*** Trying bool(false) +string(0) "" +*** Trying NULL +*** Caught Return value of {closure}() must be of the type string, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type string, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type string, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +string(6) "foobar" +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type string, resource returned in %s on line %d + +Testing 'bool' typehint: +*** Trying int(1) +bool(true) +*** Trying string(1) "1" +bool(true) +*** Trying float(1) +bool(true) +*** Trying float(1.5) +bool(true) +*** Trying string(2) "1a" +bool(true) +*** Trying string(1) "a" +bool(true) +*** Trying string(0) "" +bool(false) +*** Trying int(9223372036854775807) +bool(true) +*** Trying float(NAN) +bool(true) +*** Trying bool(true) +bool(true) +*** Trying bool(false) +bool(false) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type boolean, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type boolean, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type boolean, resource returned in %s on line %d + +Done diff --git a/Zend/tests/typehints/scalar_strict.phpt b/Zend/tests/typehints/scalar_strict.phpt index 400c7d5..9984367 100644 --- a/Zend/tests/typehints/scalar_strict.phpt +++ b/Zend/tests/typehints/scalar_strict.phpt @@ -1,5 +1,7 @@ --TEST-- Scalar type hint strict mode +--SKIPIF-- +<?php if (PHP_INT_SIZE != 4) die("skip this test is for 64bit platform only"); ?> --FILE-- <?php declare(strict_types=1); @@ -85,8 +87,8 @@ int(1) *** Trying string(0) "" *** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d -*** Trying int(9223372036854775807) -int(9223372036854775807) +*** Trying int(2147483647) +int(2147483647) *** Trying float(NAN) *** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d @@ -138,8 +140,8 @@ float(1.5) *** Trying string(0) "" *** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d -*** Trying int(9223372036854775807) -float(9.2233720368548E+18) +*** Trying int(2147483647) +float(2147483647) *** Trying float(NAN) float(NAN) @@ -191,7 +193,7 @@ string(1) "a" *** Trying string(0) "" string(0) "" -*** Trying int(9223372036854775807) +*** Trying int(2147483647) *** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d *** Trying float(NAN) @@ -244,7 +246,7 @@ Testing 'bool' typehint: *** Trying string(0) "" *** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d -*** Trying int(9223372036854775807) +*** Trying int(2147483647) *** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d *** Trying float(NAN) diff --git a/Zend/tests/typehints/scalar_strict_64bit.phpt b/Zend/tests/typehints/scalar_strict_64bit.phpt new file mode 100644 index 0000000..da3e1e4 --- /dev/null +++ b/Zend/tests/typehints/scalar_strict_64bit.phpt @@ -0,0 +1,279 @@ +--TEST-- +Scalar type hint strict mode +--SKIPIF-- +<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> +--FILE-- +<?php +declare(strict_types=1); + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; + foreach ($values as $value) { + echo PHP_EOL . "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' typehint: + +*** Trying int(1) +int(1) + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying int(9223372036854775807) +int(9223372036854775807) + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d + +Testing 'float' typehint: + +*** Trying int(1) +float(1) + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying float(1) +float(1) + +*** Trying float(1.5) +float(1.5) + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying int(9223372036854775807) +float(9.2233720368548E+18) + +*** Trying float(NAN) +float(NAN) + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d + +Testing 'string' typehint: + +*** Trying int(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying string(1) "1" +string(1) "1" + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying string(2) "1a" +string(2) "1a" + +*** Trying string(1) "a" +string(1) "a" + +*** Trying string(0) "" +string(0) "" + +*** Trying int(9223372036854775807) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d + +Testing 'bool' typehint: + +*** Trying int(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying int(9223372036854775807) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying bool(true) +bool(true) + +*** Trying bool(false) +bool(false) + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d + +Done
diff --git a/Zend/tests/typehints/scalar_return_basic.phpt b/Zend/tests/typehints/scalar_return_basic.phpt index d33fb5d..65bef01 100644 --- a/Zend/tests/typehints/scalar_return_basic.phpt +++ b/Zend/tests/typehints/scalar_return_basic.phpt @@ -1,5 +1,7 @@ --TEST-- Return scalar type hint basics +--SKIPIF-- +<?php if (PHP_INT_SIZE != 4) die("skip this test is for 64bit platform only"); ?> --FILE-- <?php @@ -77,8 +79,8 @@ int(1) *** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d *** Trying string(0) "" *** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d -*** Trying int(9223372036854775807) -int(9223372036854775807) +*** Trying int(2147483647) +int(2147483647) *** Trying float(NAN) *** Caught Return value of {closure}() must be of the type integer, float returned in %s on line %d *** Trying bool(true) @@ -115,8 +117,8 @@ float(1) *** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d *** Trying string(0) "" *** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d -*** Trying int(9223372036854775807) -float(9.2233720368548E+18) +*** Trying int(2147483647) +float(2147483647) *** Trying float(NAN) float(NAN) *** Trying bool(true) @@ -152,8 +154,8 @@ string(2) "1a" string(1) "a" *** Trying string(0) "" string(0) "" -*** Trying int(9223372036854775807) -string(19) "9223372036854775807" +*** Trying int(2147483647) +string(10) "2147483647" *** Trying float(NAN) string(3) "NAN" *** Trying bool(true) @@ -189,7 +191,7 @@ bool(true) bool(true) *** Trying string(0) "" bool(false) -*** Trying int(9223372036854775807) +*** Trying int(2147483647) bool(true) *** Trying float(NAN) bool(true) diff --git a/Zend/tests/typehints/scalar_return_basic_64bit.phpt b/Zend/tests/typehints/scalar_return_basic_64bit.phpt new file mode 100644 index 0000000..edb5231 --- /dev/null +++ b/Zend/tests/typehints/scalar_return_basic_64bit.phpt @@ -0,0 +1,216 @@ +--TEST-- +Return scalar type hint basics +--SKIPIF-- +<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> +--FILE-- +<?php + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function ($i): int { return $i; }, + 'float' => function ($f): float { return $f; }, + 'string' => function ($s): string { return $s; }, + 'bool' => function ($b): bool { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; + foreach ($values as $value) { + echo "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' typehint: +*** Trying int(1) +int(1) +*** Trying string(1) "1" +int(1) +*** Trying float(1) +int(1) +*** Trying float(1.5) +int(1) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +int(1) +*** Trying string(1) "a" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d +*** Trying string(0) "" +*** Caught Return value of {closure}() must be of the type integer, string returned in %s on line %d +*** Trying int(9223372036854775807) +int(9223372036854775807) +*** Trying float(NAN) +*** Caught Return value of {closure}() must be of the type integer, float returned in %s on line %d +*** Trying bool(true) +int(1) +*** Trying bool(false) +int(0) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type integer, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type integer, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type integer, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type integer, resource returned in %s on line %d + +Testing 'float' typehint: +*** Trying int(1) +float(1) +*** Trying string(1) "1" +float(1) +*** Trying float(1) +float(1) +*** Trying float(1.5) +float(1.5) +*** Trying string(2) "1a" +E_NOTICE: A non well formed numeric value encountered on line %d +float(1) +*** Trying string(1) "a" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d +*** Trying string(0) "" +*** Caught Return value of {closure}() must be of the type float, string returned in %s on line %d +*** Trying int(9223372036854775807) +float(9.2233720368548E+18) +*** Trying float(NAN) +float(NAN) +*** Trying bool(true) +float(1) +*** Trying bool(false) +float(0) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type float, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type float, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type float, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type float, resource returned in %s on line %d + +Testing 'string' typehint: +*** Trying int(1) +string(1) "1" +*** Trying string(1) "1" +string(1) "1" +*** Trying float(1) +string(1) "1" +*** Trying float(1.5) +string(3) "1.5" +*** Trying string(2) "1a" +string(2) "1a" +*** Trying string(1) "a" +string(1) "a" +*** Trying string(0) "" +string(0) "" +*** Trying int(9223372036854775807) +string(19) "9223372036854775807" +*** Trying float(NAN) +string(3) "NAN" +*** Trying bool(true) +string(1) "1" +*** Trying bool(false) +string(0) "" +*** Trying NULL +*** Caught Return value of {closure}() must be of the type string, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type string, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type string, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +string(6) "foobar" +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type string, resource returned in %s on line %d + +Testing 'bool' typehint: +*** Trying int(1) +bool(true) +*** Trying string(1) "1" +bool(true) +*** Trying float(1) +bool(true) +*** Trying float(1.5) +bool(true) +*** Trying string(2) "1a" +bool(true) +*** Trying string(1) "a" +bool(true) +*** Trying string(0) "" +bool(false) +*** Trying int(9223372036854775807) +bool(true) +*** Trying float(NAN) +bool(true) +*** Trying bool(true) +bool(true) +*** Trying bool(false) +bool(false) +*** Trying NULL +*** Caught Return value of {closure}() must be of the type boolean, null returned in %s on line %d +*** Trying array(0) { +} +*** Caught Return value of {closure}() must be of the type boolean, array returned in %s on line %d +*** Trying object(stdClass)#6 (0) { +} +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying object(Stringable)#7 (0) { +} +*** Caught Return value of {closure}() must be of the type boolean, object returned in %s on line %d +*** Trying resource(5) of type (stream) +*** Caught Return value of {closure}() must be of the type boolean, resource returned in %s on line %d + +Done diff --git a/Zend/tests/typehints/scalar_strict.phpt b/Zend/tests/typehints/scalar_strict.phpt index 400c7d5..9984367 100644 --- a/Zend/tests/typehints/scalar_strict.phpt +++ b/Zend/tests/typehints/scalar_strict.phpt @@ -1,5 +1,7 @@ --TEST-- Scalar type hint strict mode +--SKIPIF-- +<?php if (PHP_INT_SIZE != 4) die("skip this test is for 64bit platform only"); ?> --FILE-- <?php declare(strict_types=1); @@ -85,8 +87,8 @@ int(1) *** Trying string(0) "" *** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d -*** Trying int(9223372036854775807) -int(9223372036854775807) +*** Trying int(2147483647) +int(2147483647) *** Trying float(NAN) *** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d @@ -138,8 +140,8 @@ float(1.5) *** Trying string(0) "" *** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d -*** Trying int(9223372036854775807) -float(9.2233720368548E+18) +*** Trying int(2147483647) +float(2147483647) *** Trying float(NAN) float(NAN) @@ -191,7 +193,7 @@ string(1) "a" *** Trying string(0) "" string(0) "" -*** Trying int(9223372036854775807) +*** Trying int(2147483647) *** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d *** Trying float(NAN) @@ -244,7 +246,7 @@ Testing 'bool' typehint: *** Trying string(0) "" *** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d -*** Trying int(9223372036854775807) +*** Trying int(2147483647) *** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d *** Trying float(NAN) diff --git a/Zend/tests/typehints/scalar_strict_64bit.phpt b/Zend/tests/typehints/scalar_strict_64bit.phpt new file mode 100644 index 0000000..da3e1e4 --- /dev/null +++ b/Zend/tests/typehints/scalar_strict_64bit.phpt @@ -0,0 +1,279 @@ +--TEST-- +Scalar type hint strict mode +--SKIPIF-- +<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> +--FILE-- +<?php +declare(strict_types=1); + +$errnames = [ + E_NOTICE => 'E_NOTICE', + E_WARNING => 'E_WARNING', + E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR' +]; +set_error_handler(function (int $errno, string $errmsg, string $file, int $line) use ($errnames) { + echo "$errnames[$errno]: $errmsg on line $line\n"; + return true; +}); + +$functions = [ + 'int' => function (int $i) { return $i; }, + 'float' => function (float $f) { return $f; }, + 'string' => function (string $s) { return $s; }, + 'bool' => function (bool $b) { return $b; } +]; + +class Stringable { + public function __toString() { + return "foobar"; + } +} + +$values = [ + 1, + "1", + 1.0, + 1.5, + "1a", + "a", + "", + PHP_INT_MAX, + NAN, + TRUE, + FALSE, + NULL, + [], + new StdClass, + new Stringable, + fopen("data:text/plain,foobar", "r") +]; + +foreach ($functions as $type => $function) { + echo PHP_EOL, "Testing '$type' typehint:", PHP_EOL; + foreach ($values as $value) { + echo PHP_EOL . "*** Trying "; + var_dump($value); + try { + var_dump($function($value)); + } catch (TypeException $e) { + echo "*** Caught " . $e->getMessage() . PHP_EOL; + } + } +} + +echo PHP_EOL . "Done"; +?> +--EXPECTF-- +Testing 'int' typehint: + +*** Trying int(1) +int(1) + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type integer, string given, called in %s on line %d + +*** Trying int(9223372036854775807) +int(9223372036854775807) + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type integer, float given, called in %s on line %d + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type integer, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type integer, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type integer, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type integer, resource given, called in %s on line %d + +Testing 'float' typehint: + +*** Trying int(1) +float(1) + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying float(1) +float(1) + +*** Trying float(1.5) +float(1.5) + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type float, string given, called in %s on line %d + +*** Trying int(9223372036854775807) +float(9.2233720368548E+18) + +*** Trying float(NAN) +float(NAN) + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type float, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type float, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type float, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type float, resource given, called in %s on line %d + +Testing 'string' typehint: + +*** Trying int(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying string(1) "1" +string(1) "1" + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying string(2) "1a" +string(2) "1a" + +*** Trying string(1) "a" +string(1) "a" + +*** Trying string(0) "" +string(0) "" + +*** Trying int(9223372036854775807) +*** Caught Argument 1 passed to {closure}() must be of the type string, integer given, called in %s on line %d + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type string, float given, called in %s on line %d + +*** Trying bool(true) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying bool(false) +*** Caught Argument 1 passed to {closure}() must be of the type string, boolean given, called in %s on line %d + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type string, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type string, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type string, resource given, called in %s on line %d + +Testing 'bool' typehint: + +*** Trying int(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying string(1) "1" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying float(1) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying float(1.5) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying string(2) "1a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying string(1) "a" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying string(0) "" +*** Caught Argument 1 passed to {closure}() must be of the type boolean, string given, called in %s on line %d + +*** Trying int(9223372036854775807) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, integer given, called in %s on line %d + +*** Trying float(NAN) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, float given, called in %s on line %d + +*** Trying bool(true) +bool(true) + +*** Trying bool(false) +bool(false) + +*** Trying NULL +*** Caught Argument 1 passed to {closure}() must be of the type boolean, null given, called in %s on line %d + +*** Trying array(0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, array given, called in %s on line %d + +*** Trying object(stdClass)#6 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying object(Stringable)#7 (0) { +} +*** Caught Argument 1 passed to {closure}() must be of the type boolean, object given, called in %s on line %d + +*** Trying resource(5) of type (stream) +*** Caught Argument 1 passed to {closure}() must be of the type boolean, resource given, called in %s on line %d + +Done