bug72101.phpt 2.8 KB

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