Skip to content

Commit 35b5bff

Browse files
committed
* Added test tests/php_exceptions_007.phpt
1 parent cfa5e72 commit 35b5bff

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/php_exceptions_007.phpt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
--TEST--
2+
Test V8::executeString() : PHP Exception handling (throwed inside magic method)
3+
--SKIPIF--
4+
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
class SomeClass {
8+
function someMethod($someVariable) {
9+
return $someVariable;
10+
}
11+
12+
public function triggerException() {
13+
throw new Exception("Some exception");
14+
}
15+
16+
public function __get($key) {
17+
$this->triggerException();
18+
}
19+
}
20+
21+
function execute($code, $flags = V8Js::FLAG_NONE) {
22+
$js = new V8Js();
23+
$js->output = new stdClass();
24+
$js->SomeClassInstance = new SomeClass();
25+
try {
26+
$js->executeString("
27+
try {
28+
$code
29+
} catch(e) {
30+
PHP.output.result = 'Caught exception at javascript level : ' + e.getMessage();
31+
}
32+
", '', $flags);
33+
print($js->output->result.PHP_EOL);
34+
} catch (Exception $e) {
35+
print( "Caught exception at php level : ".$e->getMessage().PHP_EOL);
36+
}
37+
}
38+
39+
execute("PHP.SomeClassInstance.triggerException();");
40+
execute("PHP.SomeClassInstance.someMethod(PHP.SomeClassInstance.TriggerMagicMethod);");
41+
execute("PHP.SomeClassInstance.TriggerMagicMethod;");
42+
execute("PHP.SomeClassInstance.triggerException();", V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
43+
execute("PHP.SomeClassInstance.someMethod(PHP.SomeClassInstance.TriggerMagicMethod);", V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
44+
execute("PHP.SomeClassInstance.TriggerMagicMethod;", V8Js::FLAG_PROPAGATE_PHP_EXCEPTIONS);
45+
?>
46+
===EOF===
47+
--EXPECTF--
48+
Caught exception at php level : Some exception
49+
Caught exception at php level : Some exception
50+
Caught exception at php level : Some exception
51+
Caught exception at javascript level : Some exception
52+
Caught exception at javascript level : Some exception
53+
Caught exception at javascript level : Some exception
54+
===EOF===

0 commit comments

Comments
 (0)