summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2015-03-09 13:57:15 +0100
committerNikita Popov <nikic@php.net>2015-03-09 14:01:32 +0100
commit1c94ff0595bbe6f3df8058aff7252bda09dc4a15 (patch)
treeefe488bc3292d544657fca92c4347c9b872931eb /tests
parent2f156c61f19a889c8ed39fe8eb3b3220555db647 (diff)
downloadphp-git-1c94ff0595bbe6f3df8058aff7252bda09dc4a15.tar.gz
Implement engine exceptions
RFC: https://wiki.php.net/rfc/engine_exceptions_for_php7 Pending changes regarding naming of BaseException and whether it should be an interface.
Diffstat (limited to 'tests')
-rw-r--r--tests/classes/type_hinting_004.phpt136
-rw-r--r--tests/lang/catchable_error_002.phpt20
2 files changed, 110 insertions, 46 deletions
diff --git a/tests/classes/type_hinting_004.phpt b/tests/classes/type_hinting_004.phpt
index 9068909a82..70637173bd 100644
--- a/tests/classes/type_hinting_004.phpt
+++ b/tests/classes/type_hinting_004.phpt
@@ -16,13 +16,36 @@ Ensure type hints are enforced for functions invoked as callbacks.
function f2(A $a = null) {
echo "in f2;\n";
}
- call_user_func('f1', 1);
- call_user_func('f1', new A);
- call_user_func('f2', 1);
- call_user_func('f2');
- call_user_func('f2', new A);
- call_user_func('f2', null);
-
+ try {
+ call_user_func('f1', 1);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func('f1', new A);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func('f2', 1);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func('f2');
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func('f2', new A);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func('f2', null);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
echo "\n\n---> Type hints with callback static method:\n";
class C {
@@ -41,13 +64,37 @@ Ensure type hints are enforced for functions invoked as callbacks.
}
}
}
- call_user_func(array('C', 'f1'), 1);
- call_user_func(array('C', 'f1'), new A);
- call_user_func(array('C', 'f2'), 1);
- call_user_func(array('C', 'f2'));
- call_user_func(array('C', 'f2'), new A);
- call_user_func(array('C', 'f2'), null);
-
+
+ try {
+ call_user_func(array('C', 'f1'), 1);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func(array('C', 'f1'), new A);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func(array('C', 'f2'), 1);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func(array('C', 'f2'));
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func(array('C', 'f2'), new A);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func(array('C', 'f2'), null);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
echo "\n\n---> Type hints with callback instance method:\n";
class D {
@@ -67,43 +114,68 @@ Ensure type hints are enforced for functions invoked as callbacks.
}
}
$d = new D;
- call_user_func(array($d, 'f1'), 1);
- call_user_func(array($d, 'f1'), new A);
- call_user_func(array($d, 'f2'), 1);
- call_user_func(array($d, 'f2'));
- call_user_func(array($d, 'f2'), new A);
- call_user_func(array($d, 'f2'), null);
+
+ try {
+ call_user_func(array($d, 'f1'), 1);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func(array($d, 'f1'), new A);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func(array($d, 'f2'), 1);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func(array($d, 'f2'));
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func(array($d, 'f2'), new A);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
+ try {
+ call_user_func(array($d, 'f2'), null);
+ } catch (EngineException $ex) {
+ echo "{$ex->getCode()}: {$ex->getMessage()} - {$ex->getFile()}({$ex->getLine()})\n\n";
+ }
?>
--EXPECTF--
---> Type hints with callback function:
-4096: Argument 1 passed to f1() must be an instance of A, integer given%s(10)
-in f1;
+4096: Argument 1 passed to f1() must be an instance of A, integer given%s(%d)
+
in f1;
-4096: Argument 1 passed to f2() must be an instance of A, integer given%s(13)
-in f2;
+4096: Argument 1 passed to f2() must be an instance of A, integer given%s(%d)
+
in f2;
in f2;
in f2;
---> Type hints with callback static method:
-4096: Argument 1 passed to C::f1() must be an instance of A, integer given%s(26)
-in C::f1 (static);
+4096: Argument 1 passed to C::f1() must be an instance of A, integer given%s(%d)
+
in C::f1 (static);
-4096: Argument 1 passed to C::f2() must be an instance of A, integer given%s(33)
-in C::f2 (static);
+4096: Argument 1 passed to C::f2() must be an instance of A, integer given%s(%d)
+
in C::f2 (static);
in C::f2 (static);
in C::f2 (static);
---> Type hints with callback instance method:
-4096: Argument 1 passed to D::f1() must be an instance of A, integer given%s(51)
-in C::f1 (instance);
+4096: Argument 1 passed to D::f1() must be an instance of A, integer given%s(%d)
+
in C::f1 (instance);
-4096: Argument 1 passed to D::f2() must be an instance of A, integer given%s(58)
-in C::f2 (instance);
+4096: Argument 1 passed to D::f2() must be an instance of A, integer given%s(%d)
+
in C::f2 (instance);
in C::f2 (instance);
in C::f2 (instance);
diff --git a/tests/lang/catchable_error_002.phpt b/tests/lang/catchable_error_002.phpt
index c1762b2db7..a80928523b 100644
--- a/tests/lang/catchable_error_002.phpt
+++ b/tests/lang/catchable_error_002.phpt
@@ -17,21 +17,13 @@ Catchable fatal error [2]
set_error_handler('error');
- blah (new StdClass);
+ try {
+ blah (new StdClass);
+ } catch (engineException $ex) {
+ echo $ex->getMessage(), "\n";
+ }
echo "ALIVE!\n";
?>
--EXPECTF--
-array(5) {
- [0]=>
- int(4096)
- [1]=>
- string(%d) "Argument 1 passed to blah() must be an instance of Foo, instance of stdClass given, called in %scatchable_error_002.php on line %d and defined"
- [2]=>
- string(%d) "%scatchable_error_002.php"
- [3]=>
- int(5)
- [4]=>
- array(0) {
- }
-}
+Argument 1 passed to blah() must be an instance of Foo, instance of stdClass given, called in %scatchable_error_002.php on line 18 and defined
ALIVE!