Skip to content

Commit 21bcabd

Browse files
committed
Add observer tests for call_user_func() and friend
1 parent e42abea commit 21bcabd

File tree

4 files changed

+158
-0
lines changed

4 files changed

+158
-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'>

0 commit comments

Comments
 (0)