1--TEST--
2runkit7_method_redefine() function and runkit7_method_remove(), with variadic functions with return values
3--SKIPIF--
4<?php if(!extension_loaded("runkit7") || !RUNKIT7_FEATURE_MANIPULATION) print "skip"; ?>
5--INI--
6display_errors=on
7--FILE--
8<?php
9// This is the same as runkit_method_variadic.phpt, with return types added to the original redefined function
10function create_mock($className, $originalName, $temporaryName) {
11    if (!runkit7_method_copy($className, $temporaryName, $className, $originalName))
12        throw new RuntimeException($className . '::' . $originalName . ' runkit_method_copy create_mock');
13    if (!runkit7_method_remove($className, $originalName))
14        throw new RuntimeException($className . '::' . $originalName . ' runkit_method_remove create_mock');
15    if (!runkit7_method_add($className, $originalName, '', 'printf("In mock: %s\n", serialize(func_get_args()));return null;', RUNKIT7_ACC_STATIC))
16        throw new RuntimeException($className . '::' . $originalName . ' runkit_method_add create_mock');
17}
18
19function remove_mock($className, $originalName, $temporaryName) {
20    if (!runkit7_method_remove($className, $originalName))
21        throw new RuntimeException($className . '::' . $originalName . ' runkit_method_remove1 remove_mock');
22    if (!runkit7_method_copy($className, $originalName, $className, $temporaryName))
23        throw new RuntimeException($className . '::' . $originalName . ' runkit_method_copy remove_mock');
24    if (!runkit7_method_remove($className, $temporaryName))
25        throw new RuntimeException($className . '::' . $originalName . ' runkit_method_remove2 remove_mock');
26}
27
28class FooImpl {
29    public function methodName($arg) {
30        return 33 + $arg;
31    }
32}
33
34class foo {
35    public static function bar($method, ...$args) : string {
36        global $impl;
37        if ($impl === null) {
38            throw new RuntimeException('No $impl');
39        }
40
41        $id = self::getter();
42        return $id . call_user_func_array(array($impl, $method), $args);
43    }
44
45    public static function getter() {
46        return 'VALUE';
47    }
48}
49
50function main() {
51    ini_set('error_reporting', E_ALL | E_STRICT);
52    global $impl;
53    $impl = new FooImpl();
54    printf("Before mock: %s\n", var_export(foo::bar('methodName', 0), true));
55    create_mock('foo', 'bar', 'bar0000001123');
56    printf("After mock: %s\n", var_export(foo::bar('methodName', 0), true));
57    remove_mock('foo', 'bar', 'bar0000001123');
58    printf("After unmock: %s\n", var_export(foo::bar('methodName', 100), true));
59}
60main();
61?>
62--EXPECT--
63Before mock: 'VALUE33'
64In mock: a:2:{i:0;s:10:"methodName";i:1;i:0;}
65After mock: NULL
66After unmock: 'VALUE133'
67