class_with_deprecated_method.phpt 2.8 KB

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