proxy.phpt 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. --TEST--
  2. PHPUnit_Framework_MockObject_Generator::generate('Foo', null, 'ProxyFoo', true, true, true, true)
  3. --FILE--
  4. <?php
  5. class Foo
  6. {
  7. public function bar(Foo $foo)
  8. {
  9. }
  10. public function baz(Foo $foo)
  11. {
  12. }
  13. }
  14. require __DIR__ . '/../../../vendor/autoload.php';
  15. $generator = new PHPUnit_Framework_MockObject_Generator;
  16. $mock = $generator->generate(
  17. 'Foo', array(), 'ProxyFoo', true, true, true, true
  18. );
  19. print $mock['code'];
  20. ?>
  21. --EXPECTF--
  22. class ProxyFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
  23. {
  24. private $__phpunit_invocationMocker;
  25. private $__phpunit_originalObject;
  26. private $__phpunit_configurable = ['bar', 'baz'];
  27. public function __clone()
  28. {
  29. $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
  30. }
  31. public function bar(Foo $foo)
  32. {
  33. $arguments = array($foo);
  34. $count = func_num_args();
  35. if ($count > 1) {
  36. $_arguments = func_get_args();
  37. for ($i = 1; $i < $count; $i++) {
  38. $arguments[] = $_arguments[$i];
  39. }
  40. }
  41. $this->__phpunit_getInvocationMocker()->invoke(
  42. new PHPUnit_Framework_MockObject_Invocation_Object(
  43. 'Foo', 'bar', $arguments, '', $this, true
  44. )
  45. );
  46. return call_user_func_array(array($this->__phpunit_originalObject, "bar"), $arguments);
  47. }
  48. public function baz(Foo $foo)
  49. {
  50. $arguments = array($foo);
  51. $count = func_num_args();
  52. if ($count > 1) {
  53. $_arguments = func_get_args();
  54. for ($i = 1; $i < $count; $i++) {
  55. $arguments[] = $_arguments[$i];
  56. }
  57. }
  58. $this->__phpunit_getInvocationMocker()->invoke(
  59. new PHPUnit_Framework_MockObject_Invocation_Object(
  60. 'Foo', 'baz', $arguments, '', $this, true
  61. )
  62. );
  63. return call_user_func_array(array($this->__phpunit_originalObject, "baz"), $arguments);
  64. }
  65. public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
  66. {
  67. return $this->__phpunit_getInvocationMocker()->expects($matcher);
  68. }
  69. public function method()
  70. {
  71. $any = new PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount;
  72. $expects = $this->expects($any);
  73. return call_user_func_array(array($expects, 'method'), func_get_args());
  74. }
  75. public function __phpunit_setOriginalObject($originalObject)
  76. {
  77. $this->__phpunit_originalObject = $originalObject;
  78. }
  79. public function __phpunit_getInvocationMocker()
  80. {
  81. if ($this->__phpunit_invocationMocker === null) {
  82. $this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker($this->__phpunit_configurable);
  83. }
  84. return $this->__phpunit_invocationMocker;
  85. }
  86. public function __phpunit_hasMatchers()
  87. {
  88. return $this->__phpunit_getInvocationMocker()->hasMatchers();
  89. }
  90. public function __phpunit_verify($unsetInvocationMocker = true)
  91. {
  92. $this->__phpunit_getInvocationMocker()->verify();
  93. if ($unsetInvocationMocker) {
  94. $this->__phpunit_invocationMocker = null;
  95. }
  96. }
  97. }