abstract_class.phpt 3.6KB

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