Skip to content

Commit 4a6932c

Browse files
committed
Add missing observer tests
Closes phpGH-6378
1 parent ba525a6 commit 4a6932c

File tree

6 files changed

+239
-0
lines changed

6 files changed

+239
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Observer: call_user_func() from root namespace
3+
--SKIPIF--
4+
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
5+
--INI--
6+
zend_test.observer.enabled=1
7+
zend_test.observer.observe_all=1
8+
--FILE--
9+
<?php
10+
namespace Test {
11+
final class MyClass
12+
{
13+
public static function myMethod()
14+
{
15+
echo 'MyClass::myMethod called' . PHP_EOL;
16+
}
17+
}
18+
19+
function my_function()
20+
{
21+
echo 'my_function called' . PHP_EOL;
22+
}
23+
}
24+
namespace {
25+
call_user_func('Test\\MyClass::myMethod');
26+
call_user_func('Test\\my_function');
27+
}
28+
?>
29+
--EXPECTF--
30+
<!-- init '%s/observer_call_user_func_%d.php' -->
31+
<file '%s/observer_call_user_func_%d.php'>
32+
<!-- init Test\MyClass::myMethod() -->
33+
<Test\MyClass::myMethod>
34+
MyClass::myMethod called
35+
</Test\MyClass::myMethod>
36+
<!-- init Test\my_function() -->
37+
<Test\my_function>
38+
my_function called
39+
</Test\my_function>
40+
</file '%s/observer_call_user_func_%d.php'>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Observer: call_user_func_array() from root namespace
3+
--SKIPIF--
4+
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
5+
--INI--
6+
zend_test.observer.enabled=1
7+
zend_test.observer.observe_all=1
8+
--FILE--
9+
<?php
10+
namespace Test {
11+
final class MyClass
12+
{
13+
public static function myMethod(string $msg)
14+
{
15+
echo 'MyClass::myMethod ' . $msg . PHP_EOL;
16+
}
17+
}
18+
19+
function my_function(string $msg)
20+
{
21+
echo 'my_function ' . $msg . PHP_EOL;
22+
}
23+
}
24+
namespace {
25+
call_user_func_array('Test\\MyClass::myMethod', ['called']);
26+
call_user_func_array('Test\\my_function', ['called']);
27+
}
28+
?>
29+
--EXPECTF--
30+
<!-- init '%s/observer_call_user_func_%d.php' -->
31+
<file '%s/observer_call_user_func_%d.php'>
32+
<!-- init Test\MyClass::myMethod() -->
33+
<Test\MyClass::myMethod>
34+
MyClass::myMethod called
35+
</Test\MyClass::myMethod>
36+
<!-- init Test\my_function() -->
37+
<Test\my_function>
38+
my_function called
39+
</Test\my_function>
40+
</file '%s/observer_call_user_func_%d.php'>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Observer: call_user_func() from namespace
3+
--SKIPIF--
4+
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
5+
--INI--
6+
zend_test.observer.enabled=1
7+
zend_test.observer.observe_all=1
8+
--FILE--
9+
<?php
10+
namespace Test {
11+
final class MyClass
12+
{
13+
public static function myMethod()
14+
{
15+
echo 'MyClass::myMethod called' . PHP_EOL;
16+
}
17+
}
18+
19+
function my_function()
20+
{
21+
echo 'my_function called' . PHP_EOL;
22+
}
23+
24+
call_user_func('Test\\MyClass::myMethod');
25+
call_user_func('Test\\my_function');
26+
}
27+
?>
28+
--EXPECTF--
29+
<!-- init '%s/observer_call_user_func_%d.php' -->
30+
<file '%s/observer_call_user_func_%d.php'>
31+
<!-- init Test\MyClass::myMethod() -->
32+
<Test\MyClass::myMethod>
33+
MyClass::myMethod called
34+
</Test\MyClass::myMethod>
35+
<!-- init Test\my_function() -->
36+
<Test\my_function>
37+
my_function called
38+
</Test\my_function>
39+
</file '%s/observer_call_user_func_%d.php'>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Observer: call_user_func_array() from namespace
3+
--SKIPIF--
4+
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
5+
--INI--
6+
zend_test.observer.enabled=1
7+
zend_test.observer.observe_all=1
8+
--FILE--
9+
<?php
10+
namespace Test {
11+
final class MyClass
12+
{
13+
public static function myMethod(string $msg)
14+
{
15+
echo 'MyClass::myMethod ' . $msg . PHP_EOL;
16+
}
17+
}
18+
19+
function my_function(string $msg)
20+
{
21+
echo 'my_function ' . $msg . PHP_EOL;
22+
}
23+
24+
call_user_func_array('Test\\MyClass::myMethod', ['called']);
25+
call_user_func_array('Test\\my_function', ['called']);
26+
}
27+
?>
28+
--EXPECTF--
29+
<!-- init '%s/observer_call_user_func_%d.php' -->
30+
<file '%s/observer_call_user_func_%d.php'>
31+
<!-- init Test\MyClass::myMethod() -->
32+
<Test\MyClass::myMethod>
33+
MyClass::myMethod called
34+
</Test\MyClass::myMethod>
35+
<!-- init Test\my_function() -->
36+
<Test\my_function>
37+
my_function called
38+
</Test\my_function>
39+
</file '%s/observer_call_user_func_%d.php'>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--TEST--
2+
Observer: Generator with uncaught exception
3+
--SKIPIF--
4+
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
5+
--INI--
6+
zend_test.observer.enabled=1
7+
zend_test.observer.observe_all=1
8+
zend_test.observer.show_return_value=1
9+
--FILE--
10+
<?php
11+
function fooResults() {
12+
yield 0;
13+
yield 1;
14+
throw new RuntimeException('Oops!');
15+
}
16+
17+
function doSomething() {
18+
$generator = fooResults();
19+
foreach ($generator as $value) {
20+
echo $value . PHP_EOL;
21+
}
22+
23+
return 'You should not see this';
24+
}
25+
26+
echo doSomething() . PHP_EOL;
27+
?>
28+
--EXPECTF--
29+
<!-- init '%s/observer_generator_%d.php' -->
30+
<file '%s/observer_generator_%d.php'>
31+
<!-- init doSomething() -->
32+
<doSomething>
33+
<!-- init fooResults() -->
34+
<fooResults>
35+
</fooResults:0>
36+
0
37+
<fooResults>
38+
</fooResults:1>
39+
1
40+
<fooResults>
41+
<!-- Exception: RuntimeException -->
42+
</fooResults:NULL>
43+
<!-- Exception: RuntimeException -->
44+
</doSomething:NULL>
45+
<!-- Exception: RuntimeException -->
46+
</file '%s/observer_generator_%d.php'>
47+
48+
Fatal error: Uncaught RuntimeException: Oops! in %s/observer_generator_%d.php:%d
49+
Stack trace:
50+
#0 %s/observer_generator_%d.php(%d): fooResults()
51+
#1 %s/observer_generator_%d.php(%d): doSomething()
52+
#2 {main}
53+
thrown in %s/observer_generator_%d.php on line %d
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Observer: Observe basic TypeError
3+
--SKIPIF--
4+
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
5+
--INI--
6+
zend_test.observer.enabled=1
7+
zend_test.observer.observe_all=1
8+
zend_test.observer.show_return_value=1
9+
--FILE--
10+
<?php
11+
function foo(array $a) { return 1; }
12+
foo(42);
13+
?>
14+
--EXPECTF--
15+
<!-- init '%s/observer_types_%d.php' -->
16+
<file '%s/observer_types_%d.php'>
17+
<!-- init foo() -->
18+
<foo>
19+
<!-- Exception: TypeError -->
20+
</foo:NULL>
21+
<!-- Exception: TypeError -->
22+
</file '%s/observer_types_%d.php'>
23+
24+
Fatal error: Uncaught TypeError: foo(): Argument #1 ($a) must be of type array, int given, called in %s:%d
25+
Stack trace:
26+
#0 %s/observer_types_%d.php(%d): foo(42)
27+
#1 {main}
28+
thrown in %s/observer_types_%d.php on line %d

0 commit comments

Comments
 (0)