Drupal investigation

abstract_class.phpt 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. public function __clone()
  30. {
  31. $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
  32. }
  33. public function one()
  34. {
  35. $arguments = array();
  36. $count = func_num_args();
  37. if ($count > 0) {
  38. $_arguments = func_get_args();
  39. for ($i = 0; $i < $count; $i++) {
  40. $arguments[] = $_arguments[$i];
  41. }
  42. }
  43. $result = $this->__phpunit_getInvocationMocker()->invoke(
  44. new PHPUnit_Framework_MockObject_Invocation_Object(
  45. 'Foo', 'one', $arguments, $this, TRUE
  46. )
  47. );
  48. return $result;
  49. }
  50. public function two()
  51. {
  52. $arguments = array();
  53. $count = func_num_args();
  54. if ($count > 0) {
  55. $_arguments = func_get_args();
  56. for ($i = 0; $i < $count; $i++) {
  57. $arguments[] = $_arguments[$i];
  58. }
  59. }
  60. $result = $this->__phpunit_getInvocationMocker()->invoke(
  61. new PHPUnit_Framework_MockObject_Invocation_Object(
  62. 'Foo', 'two', $arguments, $this, TRUE
  63. )
  64. );
  65. return $result;
  66. }
  67. protected function three()
  68. {
  69. $arguments = array();
  70. $count = func_num_args();
  71. if ($count > 0) {
  72. $_arguments = func_get_args();
  73. for ($i = 0; $i < $count; $i++) {
  74. $arguments[] = $_arguments[$i];
  75. }
  76. }
  77. $result = $this->__phpunit_getInvocationMocker()->invoke(
  78. new PHPUnit_Framework_MockObject_Invocation_Object(
  79. 'Foo', 'three', $arguments, $this, TRUE
  80. )
  81. );
  82. return $result;
  83. }
  84. public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
  85. {
  86. return $this->__phpunit_getInvocationMocker()->expects($matcher);
  87. }
  88. public function method()
  89. {
  90. $any = new PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount;
  91. $expects = $this->expects($any);
  92. return call_user_func_array(array($expects, 'method'), func_get_args());
  93. }
  94. public function __phpunit_setOriginalObject($originalObject)
  95. {
  96. $this->__phpunit_originalObject = $originalObject;
  97. }
  98. public function __phpunit_getInvocationMocker()
  99. {
  100. if ($this->__phpunit_invocationMocker === NULL) {
  101. $this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
  102. }
  103. return $this->__phpunit_invocationMocker;
  104. }
  105. public function __phpunit_hasMatchers()
  106. {
  107. return $this->__phpunit_getInvocationMocker()->hasMatchers();
  108. }
  109. public function __phpunit_verify()
  110. {
  111. $this->__phpunit_getInvocationMocker()->verify();
  112. $this->__phpunit_invocationMocker = NULL;
  113. }
  114. }