232.phpt 2.8 KB

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