mirror of
https://github.com/php/php-src.git
synced 2026-04-28 18:53:33 +02:00
Merge branch 'PHP-8.0'
* PHP-8.0: Add missing observer tests
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
--TEST--
|
||||
Observer: call_user_func() from root namespace
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
|
||||
--INI--
|
||||
zend_test.observer.enabled=1
|
||||
zend_test.observer.observe_all=1
|
||||
--FILE--
|
||||
<?php
|
||||
namespace Test {
|
||||
final class MyClass
|
||||
{
|
||||
public static function myMethod()
|
||||
{
|
||||
echo 'MyClass::myMethod called' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function my_function()
|
||||
{
|
||||
echo 'my_function called' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
namespace {
|
||||
call_user_func('Test\\MyClass::myMethod');
|
||||
call_user_func('Test\\my_function');
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
<!-- init '%s/observer_call_user_func_%d.php' -->
|
||||
<file '%s/observer_call_user_func_%d.php'>
|
||||
<!-- init Test\MyClass::myMethod() -->
|
||||
<Test\MyClass::myMethod>
|
||||
MyClass::myMethod called
|
||||
</Test\MyClass::myMethod>
|
||||
<!-- init Test\my_function() -->
|
||||
<Test\my_function>
|
||||
my_function called
|
||||
</Test\my_function>
|
||||
</file '%s/observer_call_user_func_%d.php'>
|
||||
@@ -0,0 +1,40 @@
|
||||
--TEST--
|
||||
Observer: call_user_func_array() from root namespace
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
|
||||
--INI--
|
||||
zend_test.observer.enabled=1
|
||||
zend_test.observer.observe_all=1
|
||||
--FILE--
|
||||
<?php
|
||||
namespace Test {
|
||||
final class MyClass
|
||||
{
|
||||
public static function myMethod(string $msg)
|
||||
{
|
||||
echo 'MyClass::myMethod ' . $msg . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function my_function(string $msg)
|
||||
{
|
||||
echo 'my_function ' . $msg . PHP_EOL;
|
||||
}
|
||||
}
|
||||
namespace {
|
||||
call_user_func_array('Test\\MyClass::myMethod', ['called']);
|
||||
call_user_func_array('Test\\my_function', ['called']);
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
<!-- init '%s/observer_call_user_func_%d.php' -->
|
||||
<file '%s/observer_call_user_func_%d.php'>
|
||||
<!-- init Test\MyClass::myMethod() -->
|
||||
<Test\MyClass::myMethod>
|
||||
MyClass::myMethod called
|
||||
</Test\MyClass::myMethod>
|
||||
<!-- init Test\my_function() -->
|
||||
<Test\my_function>
|
||||
my_function called
|
||||
</Test\my_function>
|
||||
</file '%s/observer_call_user_func_%d.php'>
|
||||
@@ -0,0 +1,39 @@
|
||||
--TEST--
|
||||
Observer: call_user_func() from namespace
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
|
||||
--INI--
|
||||
zend_test.observer.enabled=1
|
||||
zend_test.observer.observe_all=1
|
||||
--FILE--
|
||||
<?php
|
||||
namespace Test {
|
||||
final class MyClass
|
||||
{
|
||||
public static function myMethod()
|
||||
{
|
||||
echo 'MyClass::myMethod called' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function my_function()
|
||||
{
|
||||
echo 'my_function called' . PHP_EOL;
|
||||
}
|
||||
|
||||
call_user_func('Test\\MyClass::myMethod');
|
||||
call_user_func('Test\\my_function');
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
<!-- init '%s/observer_call_user_func_%d.php' -->
|
||||
<file '%s/observer_call_user_func_%d.php'>
|
||||
<!-- init Test\MyClass::myMethod() -->
|
||||
<Test\MyClass::myMethod>
|
||||
MyClass::myMethod called
|
||||
</Test\MyClass::myMethod>
|
||||
<!-- init Test\my_function() -->
|
||||
<Test\my_function>
|
||||
my_function called
|
||||
</Test\my_function>
|
||||
</file '%s/observer_call_user_func_%d.php'>
|
||||
@@ -0,0 +1,39 @@
|
||||
--TEST--
|
||||
Observer: call_user_func_array() from namespace
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
|
||||
--INI--
|
||||
zend_test.observer.enabled=1
|
||||
zend_test.observer.observe_all=1
|
||||
--FILE--
|
||||
<?php
|
||||
namespace Test {
|
||||
final class MyClass
|
||||
{
|
||||
public static function myMethod(string $msg)
|
||||
{
|
||||
echo 'MyClass::myMethod ' . $msg . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
function my_function(string $msg)
|
||||
{
|
||||
echo 'my_function ' . $msg . PHP_EOL;
|
||||
}
|
||||
|
||||
call_user_func_array('Test\\MyClass::myMethod', ['called']);
|
||||
call_user_func_array('Test\\my_function', ['called']);
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
<!-- init '%s/observer_call_user_func_%d.php' -->
|
||||
<file '%s/observer_call_user_func_%d.php'>
|
||||
<!-- init Test\MyClass::myMethod() -->
|
||||
<Test\MyClass::myMethod>
|
||||
MyClass::myMethod called
|
||||
</Test\MyClass::myMethod>
|
||||
<!-- init Test\my_function() -->
|
||||
<Test\my_function>
|
||||
my_function called
|
||||
</Test\my_function>
|
||||
</file '%s/observer_call_user_func_%d.php'>
|
||||
@@ -0,0 +1,53 @@
|
||||
--TEST--
|
||||
Observer: Generator with uncaught exception
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
|
||||
--INI--
|
||||
zend_test.observer.enabled=1
|
||||
zend_test.observer.observe_all=1
|
||||
zend_test.observer.show_return_value=1
|
||||
--FILE--
|
||||
<?php
|
||||
function fooResults() {
|
||||
yield 0;
|
||||
yield 1;
|
||||
throw new RuntimeException('Oops!');
|
||||
}
|
||||
|
||||
function doSomething() {
|
||||
$generator = fooResults();
|
||||
foreach ($generator as $value) {
|
||||
echo $value . PHP_EOL;
|
||||
}
|
||||
|
||||
return 'You should not see this';
|
||||
}
|
||||
|
||||
echo doSomething() . PHP_EOL;
|
||||
?>
|
||||
--EXPECTF--
|
||||
<!-- init '%s/observer_generator_%d.php' -->
|
||||
<file '%s/observer_generator_%d.php'>
|
||||
<!-- init doSomething() -->
|
||||
<doSomething>
|
||||
<!-- init fooResults() -->
|
||||
<fooResults>
|
||||
</fooResults:0>
|
||||
0
|
||||
<fooResults>
|
||||
</fooResults:1>
|
||||
1
|
||||
<fooResults>
|
||||
<!-- Exception: RuntimeException -->
|
||||
</fooResults:NULL>
|
||||
<!-- Exception: RuntimeException -->
|
||||
</doSomething:NULL>
|
||||
<!-- Exception: RuntimeException -->
|
||||
</file '%s/observer_generator_%d.php'>
|
||||
|
||||
Fatal error: Uncaught RuntimeException: Oops! in %s/observer_generator_%d.php:%d
|
||||
Stack trace:
|
||||
#0 %s/observer_generator_%d.php(%d): fooResults()
|
||||
#1 %s/observer_generator_%d.php(%d): doSomething()
|
||||
#2 {main}
|
||||
thrown in %s/observer_generator_%d.php on line %d
|
||||
@@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
Observer: Observe basic TypeError
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded('zend-test')) die('skip: zend-test extension required'); ?>
|
||||
--INI--
|
||||
zend_test.observer.enabled=1
|
||||
zend_test.observer.observe_all=1
|
||||
zend_test.observer.show_return_value=1
|
||||
--FILE--
|
||||
<?php
|
||||
function foo(array $a) { return 1; }
|
||||
foo(42);
|
||||
?>
|
||||
--EXPECTF--
|
||||
<!-- init '%s/observer_types_%d.php' -->
|
||||
<file '%s/observer_types_%d.php'>
|
||||
<!-- init foo() -->
|
||||
<foo>
|
||||
<!-- Exception: TypeError -->
|
||||
</foo:NULL>
|
||||
<!-- Exception: TypeError -->
|
||||
</file '%s/observer_types_%d.php'>
|
||||
|
||||
Fatal error: Uncaught TypeError: foo(): Argument #1 ($a) must be of type array, int given, called in %s:%d
|
||||
Stack trace:
|
||||
#0 %s/observer_types_%d.php(%d): foo(42)
|
||||
#1 {main}
|
||||
thrown in %s/observer_types_%d.php on line %d
|
||||
Reference in New Issue
Block a user