php-src/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt
Nikita Popov 122d759618 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.
2015-04-06 11:27:34 +02:00

62 lines
1.4 KiB
PHP

--TEST--
ReflectionMethod constructor errors
--CREDITS--
Robin Fernandes <robinf@php.net>
Steve Seear <stevseea@php.net>
--FILE--
<?php
class TestClass
{
public function foo() {
}
}
try {
echo "Too few arguments:\n";
$methodInfo = new ReflectionMethod();
} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
echo "\nToo many arguments:\n";
$methodInfo = new ReflectionMethod("TestClass", "foo", true);
} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
//invalid class
$methodInfo = new ReflectionMethod("InvalidClassName", "foo");
} catch (ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try {
//invalid 1st param
$methodInfo = new ReflectionMethod([], "foo");
} catch (ReflectionException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
try{
//invalid 2nd param
$methodInfo = new ReflectionMethod("TestClass", []);
} catch (TypeException $re) {
echo "Ok - ".$re->getMessage().PHP_EOL;
}
?>
--EXPECTF--
Too few arguments:
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given
Too many arguments:
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given
Ok - Class InvalidClassName does not exist
Ok - The parameter class is expected to be either a string or an object
Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 2 given