diff options
author | Dmitry Stogov <dmitry@zend.com> | 2016-05-16 12:42:13 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2016-05-16 12:42:13 +0300 |
commit | 97bf4e0b12db6ee8dbbb448117d696becc2923fa (patch) | |
tree | 6756406fbaf62caba347c4813e364e98b3cbce6b /Zend/tests/generators | |
parent | 054446a25f1a07788ac471c5f767834c9e116d42 (diff) | |
download | php-git-97bf4e0b12db6ee8dbbb448117d696becc2923fa.tar.gz |
Check if generator object is created by GENERATOR_CREATE when throw exceptions from generator function
Diffstat (limited to 'Zend/tests/generators')
-rw-r--r-- | Zend/tests/generators/generator_with_type_check.phpt | 13 | ||||
-rw-r--r-- | Zend/tests/generators/generator_with_type_check_2.phpt | 22 |
2 files changed, 35 insertions, 0 deletions
diff --git a/Zend/tests/generators/generator_with_type_check.phpt b/Zend/tests/generators/generator_with_type_check.phpt new file mode 100644 index 0000000000..2aa16532dc --- /dev/null +++ b/Zend/tests/generators/generator_with_type_check.phpt @@ -0,0 +1,13 @@ +--TEST-- +Generator wit type check +--FILE-- +<?php +function gen(array $a) { yield; } +gen(42); +?> +--EXPECTF-- +Fatal error: Uncaught TypeError: Argument 1 passed to gen() must be of the type array, integer given, called in %sgenerator_with_type_check.php on line 3 and defined in %sgenerator_with_type_check.php:2 +Stack trace: +#0 %sgenerator_with_type_check.php(3): gen(42) +#1 {main} + thrown in %sgenerator_with_type_check.php on line 2 diff --git a/Zend/tests/generators/generator_with_type_check_2.phpt b/Zend/tests/generators/generator_with_type_check_2.phpt new file mode 100644 index 0000000000..d8ea4fbf0d --- /dev/null +++ b/Zend/tests/generators/generator_with_type_check_2.phpt @@ -0,0 +1,22 @@ +--TEST-- +Generator wit type check +--FILE-- +<?php +function gen(array $a) { yield; } +try { + gen(42); +} catch (TypeError $e) { + echo $e->getMessage()."\n"; +} + +try { + foreach (gen(42) as $val) { + var_dump($val); + } +} catch (TypeError $e) { + echo $e->getMessage()."\n"; +} +?> +--EXPECTF-- +Argument 1 passed to gen() must be of the type array, integer given, called in %sgenerator_with_type_check_2.php on line 4 +Argument 1 passed to gen() must be of the type array, integer given, called in %sgenerator_with_type_check_2.php on line 10 |