diff options
author | Nikita Popov <nikic@php.net> | 2015-04-02 18:52:32 +0200 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2015-04-06 11:27:34 +0200 |
commit | 122d759618a42bff105971b923fbbb5be02e34b9 (patch) | |
tree | fd4487414ffa3f120c77b19b9eb7dc409659c57e /ext/spl/tests | |
parent | 884b0365dbe718f667d048dbc3d1cd9d9f12ab84 (diff) | |
download | php-git-122d759618a42bff105971b923fbbb5be02e34b9.tar.gz |
Always throw TypeException on throwing zpp failures
Introduces a ZEND_PARSE_PARAMS_THROW flag for zpp, which forces to
report FAILURE errors using a TypeException instead of a Warning,
like it would happen in strict mode.
Adds a zend_parse_parameters_throw() convenience function, which
invokes zpp with this flag.
Converts all cases I could identify, where we currently have
throwing zpp usage in constructors and replaces them with this API.
Error handling is still replaced to EH_THROW in some cases to handle
other, domain-specific errors in constructors.
Diffstat (limited to 'ext/spl/tests')
22 files changed, 105 insertions, 174 deletions
diff --git a/ext/spl/tests/CallbackFilterIteratorTest-002.phpt b/ext/spl/tests/CallbackFilterIteratorTest-002.phpt index bc4fd14647..1f71d3032a 100644 --- a/ext/spl/tests/CallbackFilterIteratorTest-002.phpt +++ b/ext/spl/tests/CallbackFilterIteratorTest-002.phpt @@ -10,27 +10,25 @@ set_error_handler(function($errno, $errstr){ try { new CallbackFilterIterator(); -} catch(InvalidArgumentException $e) { +} catch (TypeException $e) { echo $e->getMessage() . "\n"; } try { new CallbackFilterIterator(null); -} catch(InvalidArgumentException $e) { - echo $e->getMessage() . "\n"; -} catch(EngineException $e) { +} catch (TypeException $e) { echo $e->getMessage() . "\n"; } try { new CallbackFilterIterator(new ArrayIterator(array()), null); -} catch(InvalidArgumentException $e) { +} catch (TypeException $e) { echo $e->getMessage() . "\n"; } try { new CallbackFilterIterator(new ArrayIterator(array()), array()); -} catch(InvalidArgumentException $e) { +} catch (TypeException $e) { echo $e->getMessage() . "\n"; } diff --git a/ext/spl/tests/SplFixedArray__construct_param_array.phpt b/ext/spl/tests/SplFixedArray__construct_param_array.phpt index aa5933ebdb..e1515c4039 100644 --- a/ext/spl/tests/SplFixedArray__construct_param_array.phpt +++ b/ext/spl/tests/SplFixedArray__construct_param_array.phpt @@ -7,11 +7,10 @@ PHPNW Test Fest 2009 - Jordan Hatch try { $array = new SplFixedArray( array("string", 1) ); -} -catch(InvalidArgumentException $iae) { +} catch (TypeException $iae) { echo "Ok - ".$iae->getMessage().PHP_EOL; } ?> --EXPECTF-- -Ok - SplFixedArray::__construct() expects parameter 1 to be integer, array given
\ No newline at end of file +Ok - SplFixedArray::__construct() expects parameter 1 to be integer, array given diff --git a/ext/spl/tests/SplFixedArray__construct_param_string.phpt b/ext/spl/tests/SplFixedArray__construct_param_string.phpt index 411d7402df..66c7fe6a59 100644 --- a/ext/spl/tests/SplFixedArray__construct_param_string.phpt +++ b/ext/spl/tests/SplFixedArray__construct_param_string.phpt @@ -6,8 +6,7 @@ PHPNW Test Fest 2009 - Jordan Hatch <?php try { $array = new SplFixedArray( "string" ); -} -catch(InvalidArgumentException $iae) { +} catch (TypeException $iae) { echo "Ok - ".$iae->getMessage().PHP_EOL; } diff --git a/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt b/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt index 10d4c64a0c..20f4e7970c 100644 --- a/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt +++ b/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt @@ -6,8 +6,7 @@ Philip Norton philipnorton42@gmail.com <?php try { $array = new SplFixedArray(new SplFixedArray(3)); -} -catch(InvalidArgumentException $iae) { +} catch (TypeException $iae) { echo "Ok - ".$iae->getMessage().PHP_EOL; } diff --git a/ext/spl/tests/SplTempFileObject_constructor_error.phpt b/ext/spl/tests/SplTempFileObject_constructor_error.phpt index a6c71717b5..8eb306689d 100644 --- a/ext/spl/tests/SplTempFileObject_constructor_error.phpt +++ b/ext/spl/tests/SplTempFileObject_constructor_error.phpt @@ -2,11 +2,11 @@ SPL SplTempFileObject constructor sets correct defaults when pass 0 arguments --FILE-- <?php -new SplTempFileObject('invalid'); +try { + new SplTempFileObject('invalid'); +} catch (TypeException $e) { + echo $e->getMessage(), "\n"; +} ?> --EXPECTF-- -Fatal error: Uncaught exception 'RuntimeException' with message 'SplTempFileObject::__construct() expects parameter 1 to be integer, string given' in %s -Stack trace: -#0 %s: SplTempFileObject->__construct('invalid') -#1 {main} - thrown in %s +SplTempFileObject::__construct() expects parameter 1 to be integer, string given diff --git a/ext/spl/tests/arrayObject___construct_error1.phpt b/ext/spl/tests/arrayObject___construct_error1.phpt index 21c312d2d0..cff0dd048d 100644 --- a/ext/spl/tests/arrayObject___construct_error1.phpt +++ b/ext/spl/tests/arrayObject___construct_error1.phpt @@ -7,14 +7,14 @@ $a = new stdClass; $a->p = 1; try { var_dump(new ArrayObject($a, 0, "Exception")); -} catch (InvalidArgumentException $e) { +} catch (TypeException $e) { echo $e->getMessage() . "(" . $e->getLine() . ")\n"; } echo "Non-existent class:\n"; try { var_dump(new ArrayObject(new stdClass, 0, "nonExistentClassName")); -} catch (InvalidArgumentException $e) { +} catch (TypeException $e) { echo $e->getMessage() . "(" . $e->getLine() . ")\n"; } ?> diff --git a/ext/spl/tests/arrayObject___construct_error2.phpt b/ext/spl/tests/arrayObject___construct_error2.phpt index 850a2cb3fc..d075516725 100644 --- a/ext/spl/tests/arrayObject___construct_error2.phpt +++ b/ext/spl/tests/arrayObject___construct_error2.phpt @@ -13,10 +13,10 @@ Class C implements Iterator { try { var_dump(new ArrayObject(new stdClass, 0, "C", "extra")); -} catch (InvalidArgumentException $e) { +} catch (TypeException $e) { echo $e->getMessage() . "(" . $e->getLine() . ")\n"; } ?> --EXPECTF-- Too many arguments: -ArrayObject::__construct() expects at most 3 parameters, 4 given(12)
\ No newline at end of file +ArrayObject::__construct() expects at most 3 parameters, 4 given(12) diff --git a/ext/spl/tests/arrayObject_setIteratorClass_error1.phpt b/ext/spl/tests/arrayObject_setIteratorClass_error1.phpt index 4715eea986..b4c3756cb5 100644 --- a/ext/spl/tests/arrayObject_setIteratorClass_error1.phpt +++ b/ext/spl/tests/arrayObject_setIteratorClass_error1.phpt @@ -28,7 +28,7 @@ try { foreach($ao as $key=>$value) { echo " $key=>$value\n"; } -} catch (Exception $e) { +} catch (TypeException $e) { var_dump($e->getMessage()); } @@ -37,7 +37,7 @@ try { foreach($ao as $key=>$value) { echo " $key=>$value\n"; } -} catch (Exception $e) { +} catch (TypeException $e) { var_dump($e->getMessage()); } diff --git a/ext/spl/tests/bug54292.phpt b/ext/spl/tests/bug54292.phpt index d9175f7e6f..44d12ee242 100644 --- a/ext/spl/tests/bug54292.phpt +++ b/ext/spl/tests/bug54292.phpt @@ -5,7 +5,7 @@ Bug #54292 (Wrong parameter causes crash in SplFileObject::__construct()) try { new SplFileObject('foo', array()); -} catch (Exception $e) { +} catch (TypeException $e) { var_dump($e->getMessage()); } diff --git a/ext/spl/tests/fixedarray_005.phpt b/ext/spl/tests/fixedarray_005.phpt index 72970a9a1f..83727a23b9 100644 --- a/ext/spl/tests/fixedarray_005.phpt +++ b/ext/spl/tests/fixedarray_005.phpt @@ -1,18 +1,30 @@ --TEST-- -SPL: FixedArray: Trying to instantiate passing object to constructor parameter +SPL: FixedArray: Invalid arguments --FILE-- <?php -$b = new stdClass; - try { - $a = new SplFixedArray($b); + $a = new SplFixedArray(new stdClass); +} catch (TypeException $iae) { + echo "Ok - ".$iae->getMessage().PHP_EOL; } -catch(InvalidArgumentException $iae) { + +try { + $a = new SplFixedArray('FOO'); +} catch (TypeException $iae) { echo "Ok - ".$iae->getMessage().PHP_EOL; } +try { + $a = new SplFixedArray(''); +} catch (TypeException $iae) { + echo "Ok - ".$iae->getMessage().PHP_EOL; +} ?> ---EXPECTF-- +===DONE=== +--EXPECT-- Ok - SplFixedArray::__construct() expects parameter 1 to be integer, object given +Ok - SplFixedArray::__construct() expects parameter 1 to be integer, string given +Ok - SplFixedArray::__construct() expects parameter 1 to be integer, string given +===DONE=== diff --git a/ext/spl/tests/fixedarray_009.phpt b/ext/spl/tests/fixedarray_009.phpt index d67c7ccb69..f255ed299a 100644 --- a/ext/spl/tests/fixedarray_009.phpt +++ b/ext/spl/tests/fixedarray_009.phpt @@ -5,8 +5,7 @@ SPL: FixedArray: Trying to instantiate passing string to construtor parameter try { $a = new SplFixedArray('FOO'); -} -catch(InvalidArgumentException $iae) { +} catch (TypeException $iae) { echo "Ok - ".$iae->getMessage().PHP_EOL; } ?> diff --git a/ext/spl/tests/fixedarray_015.phpt b/ext/spl/tests/fixedarray_015.phpt index f12d83bb39..d189d41da3 100644 --- a/ext/spl/tests/fixedarray_015.phpt +++ b/ext/spl/tests/fixedarray_015.phpt @@ -5,8 +5,7 @@ SPL: FixedArray: accessing uninitialized array try { $a = new SplFixedArray(''); -} -catch(InvalidArgumentException $iae) { +} catch (TypeException $iae) { echo "Ok - ".$iae->getMessage().PHP_EOL; } diff --git a/ext/spl/tests/iterator_056.phpt b/ext/spl/tests/iterator_056.phpt index 4b0e75a7d4..ee98263638 100644 --- a/ext/spl/tests/iterator_056.phpt +++ b/ext/spl/tests/iterator_056.phpt @@ -1,19 +1,64 @@ --TEST-- -SPL: FilterIterator::__construct(void) +SPL: Calling __construct(void) on class extending SPL iterator --CREDITS-- Sebastian Schürmann --FILE-- <?php + class myFilterIterator extends FilterIterator { - function accept() { - - } + function accept() { } } + +class myCachingIterator extends CachingIterator { } + +class myRecursiveCachingIterator extends RecursiveCachingIterator { } + +class myParentIterator extends ParentIterator { } + +class myLimitIterator extends LimitIterator { } + +class myNoRewindIterator extends NoRewindIterator {} + try { $it = new myFilterIterator(); -} catch (InvalidArgumentException $e) { - echo 'InvalidArgumentException thrown'; +} catch (TypeException $e) { + echo $e->getMessage(), "\n"; } + +try { + $it = new myCachingIterator(); +} catch (TypeException $e) { + echo $e->getMessage(), "\n"; +} + +try { + $it = new myRecursiveCachingIterator(); +} catch (TypeException $e) { + echo $e->getMessage(), "\n"; +} + +try { + $it = new myParentIterator(); +} catch (TypeException $e) { + echo $e->getMessage(), "\n"; +} + +try { + $it = new myLimitIterator(); +} catch (TypeException $e) { + echo $e->getMessage(), "\n"; +} +try { + $it = new myNoRewindIterator(); +} catch (TypeException $e) { + echo $e->getMessage(), "\n"; +} + ?> --EXPECT-- -InvalidArgumentException thrown +FilterIterator::__construct() expects exactly 1 parameter, 0 given +CachingIterator::__construct() expects at least 1 parameter, 0 given +RecursiveCachingIterator::__construct() expects at least 1 parameter, 0 given +ParentIterator::__construct() expects exactly 1 parameter, 0 given +LimitIterator::__construct() expects at least 1 parameter, 0 given +NoRewindIterator::__construct() expects exactly 1 parameter, 0 given diff --git a/ext/spl/tests/iterator_059.phpt b/ext/spl/tests/iterator_059.phpt deleted file mode 100644 index 8c579ae43a..0000000000 --- a/ext/spl/tests/iterator_059.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -SPL: CachingIterator::__construct(void) ---CREDITS-- -Sebastian Schürmann ---FILE-- -<?php -class myCachingIterator extends CachingIterator { - -} -try { - $it = new myCachingIterator(); -} catch (InvalidArgumentException $e) { - echo 'InvalidArgumentException thrown'; -} -?> ---EXPECT-- -InvalidArgumentException thrown diff --git a/ext/spl/tests/iterator_060.phpt b/ext/spl/tests/iterator_060.phpt deleted file mode 100644 index 0c3b6c21d2..0000000000 --- a/ext/spl/tests/iterator_060.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -SPL: RecursiveCachingIterator::__construct(void) ---CREDITS-- -Sebastian Schürmann ---FILE-- -<?php -class myRecursiveCachingIterator extends RecursiveCachingIterator { - -} -try { - $it = new myRecursiveCachingIterator(); -} catch (InvalidArgumentException $e) { - echo 'InvalidArgumentException thrown'; -} -?> ---EXPECT-- -InvalidArgumentException thrown diff --git a/ext/spl/tests/iterator_061.phpt b/ext/spl/tests/iterator_061.phpt deleted file mode 100644 index 472f8da196..0000000000 --- a/ext/spl/tests/iterator_061.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -SPL: ParentIterator::__construct(void) ---CREDITS-- -Sebastian Schürmann ---FILE-- -<?php -class myParentIterator extends ParentIterator { - -} -try { - $it = new myParentIterator(); -} catch (InvalidArgumentException $e) { - echo 'InvalidArgumentException thrown'; -} -?> ---EXPECT-- -InvalidArgumentException thrown diff --git a/ext/spl/tests/iterator_063.phpt b/ext/spl/tests/iterator_063.phpt deleted file mode 100644 index 4d4112bac5..0000000000 --- a/ext/spl/tests/iterator_063.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -SPL: LimitIterator::__construct(void) ---CREDITS-- -Sebastian Schürmann ---FILE-- -<?php -class myLimitIterator extends LimitIterator { - -} -try { - $it = new myLimitIterator(); -} catch (InvalidArgumentException $e) { - echo 'InvalidArgumentException thrown'; -} -?> ---EXPECT-- -InvalidArgumentException thrown diff --git a/ext/spl/tests/iterator_064.phpt b/ext/spl/tests/iterator_064.phpt deleted file mode 100644 index 6a62e6c9c5..0000000000 --- a/ext/spl/tests/iterator_064.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -SPL: CachingIterator::__construct(void) ---CREDITS-- -Sebastian Schürmann ---FILE-- -<?php -class myCachingIterator extends CachingIterator {} -try { - $it = new myCachingIterator(); -} catch (InvalidArgumentException $e) { - echo 'InvalidArgumentException thrown'; -} -?> ---EXPECT-- -InvalidArgumentException thrown diff --git a/ext/spl/tests/iterator_065.phpt b/ext/spl/tests/iterator_065.phpt deleted file mode 100644 index 9ea2974cd4..0000000000 --- a/ext/spl/tests/iterator_065.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -SPL: RecursiveCachingIterator::__construct(void) ---CREDITS-- -Sebastian Schürmann ---FILE-- -<?php -class myRecursiveCachingIterator extends RecursiveCachingIterator {} -try { - $it = new myRecursiveCachingIterator(); -} catch (InvalidArgumentException $e) { - echo 'InvalidArgumentException thrown'; -} -?> ---EXPECT-- -InvalidArgumentException thrown diff --git a/ext/spl/tests/iterator_066.phpt b/ext/spl/tests/iterator_066.phpt deleted file mode 100644 index 008c47ccc5..0000000000 --- a/ext/spl/tests/iterator_066.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -SPL: NoRewindIterator::__construct(void) ---CREDITS-- -Sebastian Schürmann ---FILE-- -<?php -class myNoRewindIterator extends NoRewindIterator {} -try { - $it = new myNoRewindIterator(); -} catch (InvalidArgumentException $e) { - echo 'InvalidArgumentException thrown'; -} -?> ---EXPECT-- -InvalidArgumentException thrown diff --git a/ext/spl/tests/recursive_tree_iterator_003.phpt b/ext/spl/tests/recursive_tree_iterator_003.phpt index 83c8553942..4cc7000a19 100644 --- a/ext/spl/tests/recursive_tree_iterator_003.phpt +++ b/ext/spl/tests/recursive_tree_iterator_003.phpt @@ -1,16 +1,14 @@ --TEST-- SPL: RecursiveTreeIterator(non-traversable) ---INI-- -error_reporting=E_ALL&~E_NOTICE --FILE-- <?php try { new RecursiveTreeIterator(new ArrayIterator(array())); -} catch (InvalidArgumentException $e) { - echo "InvalidArgumentException thrown\n"; +} catch (TypeException $e) { + echo $e->getMessage(), "\n"; } ?> ===DONE=== ---EXPECTF-- -InvalidArgumentException thrown +--EXPECT-- +RecursiveCachingIterator::__construct() expects parameter 1 to be RecursiveIterator, object given ===DONE=== diff --git a/ext/spl/tests/spl_iterator_iterator_constructor.phpt b/ext/spl/tests/spl_iterator_iterator_constructor.phpt index d4fdb14c13..ec103f5c9c 100644 --- a/ext/spl/tests/spl_iterator_iterator_constructor.phpt +++ b/ext/spl/tests/spl_iterator_iterator_constructor.phpt @@ -6,23 +6,19 @@ TestFest London May 2009 --FILE-- <?php - //I think this is testing line 1297 of spl_iterators.c - - $array = array(array(7,8,9),1,2,3,array(4,5,6)); +$array = array(array(7,8,9),1,2,3,array(4,5,6)); $arrayIterator = new ArrayIterator($array); try { -$test = new IteratorIterator($arrayIterator); - -$test = new IteratorIterator($arrayIterator, 1); -$test = new IteratorIterator($arrayIterator, 1, 1); -$test = new IteratorIterator($arrayIterator, 1, 1, 1); -$test = new IteratorIterator($arrayIterator, 1, 1, 1, 1); + $test = new IteratorIterator($arrayIterator); -} catch (InvalidArgumentException $e){ - print $e->getMessage() . "\n"; + $test = new IteratorIterator($arrayIterator, 1); + $test = new IteratorIterator($arrayIterator, 1, 1); + $test = new IteratorIterator($arrayIterator, 1, 1, 1); + $test = new IteratorIterator($arrayIterator, 1, 1, 1, 1); +} catch (TypeException $e){ + echo $e->getMessage() . "\n"; } - ?> ===DONE=== --EXPECTF-- |