xref: /php-src/Zend/tests/bug72101.phpt (revision 08b2ab22)
1--TEST--
2Bug #72101 (crash on complex code)
3--FILE--
4<?php
5class PHPUnit_Framework_MockObject_Stub_ReturnCallback {
6    protected $callback;
7    public function __construct($callback) {
8        $this->callback = $callback;
9    }
10    public function invoke($invocation) {
11        return call_user_func_array($this->callback, $invocation->parameters);
12    }
13}
14
15class PHPUnit_Framework_MockObject_InvocationMocker {
16    protected $matchers = [];
17    public function addMatcher( $matcher) {
18        $this->matchers[] = $matcher;
19    }
20    public function invoke( $invocation) {
21        foreach ($this->matchers as $match) {
22            $match->invoked($invocation);
23        }
24    }
25}
26
27class PHPUnit_Framework_MockObject_Matcher {
28    public $stub = null;
29    public $methodNameMatcher;
30    public function invoked($invocation) {
31        return $this->stub->invoke($invocation);
32    }
33}
34
35class MethodCallbackByReference {
36    public function bar(&$a, &$b, $c) {
37        Legacy::bar($a, $b, $c);
38    }
39    public function callback(&$a, &$b, $c) {
40        $b = 1;
41    }
42}
43class PHPUnit_Framework_MockObject_Invocation_Static {
44    public $parameters;
45    public function __construct(array $parameters) {
46        $this->parameters = $parameters;
47    }
48}
49
50class Mock_MethodCallbackByReference_7b180d26 extends MethodCallbackByReference {
51    public $inv_mocker;
52    public function bar(&$a, &$b, $c) {
53        $arguments = array($a, $b, $c);
54        $result = $this->inv_mocker->invoke(
55            new PHPUnit_Framework_MockObject_Invocation_Static(
56                $arguments
57            )
58        );
59        return $result;
60    }
61}
62
63set_error_handler(function() {
64//    var_dump(func_get_args());
65    DoesNotExists::$nope = true;
66}, E_ALL);
67
68$foo = new Mock_MethodCallbackByReference_7b180d26();
69$InvMocker = new PHPUnit_Framework_MockObject_InvocationMocker();
70$foo->inv_mocker = $InvMocker;
71$OuterMatcher = new PHPUnit_Framework_MockObject_Matcher();
72$InvMocker->addMatcher($OuterMatcher);
73$OuterMatcher->methodNameMatcher = null;
74$OuterMatcher->stub = new PHPUnit_Framework_MockObject_Stub_ReturnCallback([$foo, 'callback']);
75$a = $b = $c = 0;
76$foo->bar($a, $b, $c);
77?>
78--EXPECTF--
79Fatal error: Uncaught Error: Class "DoesNotExists" not found in %s:%d
80Stack trace:
81#0 %s(%d): {closure:%s:%d}(2, 'MethodCallbackB...', '%s', 8)
82#1 %sbug72101.php(%d): PHPUnit_Framework_MockObject_Stub_ReturnCallback->invoke(Object(PHPUnit_Framework_MockObject_Invocation_Static))
83#2 %sbug72101.php(%d): PHPUnit_Framework_MockObject_Matcher->invoked(Object(PHPUnit_Framework_MockObject_Invocation_Static))
84#3 %sbug72101.php(%d): PHPUnit_Framework_MockObject_InvocationMocker->invoke(Object(PHPUnit_Framework_MockObject_Invocation_Static))
85#4 %sbug72101.php(%d): Mock_MethodCallbackByReference_7b180d26->bar(0, 0, 0)
86#5 {main}
87  thrown in %sbug72101.php on line %d
88