No Description

class.phpt 2.9KB

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