class_partial.phpt 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. --TEST--
  2. \PHPUnit\Framework\MockObject\Generator::generate('Foo', array('bar'), '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('bar'),
  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. private $__phpunit_configurable = ['bar'];
  31. public function __clone()
  32. {
  33. $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
  34. }
  35. public function bar(Foo $foo)
  36. {
  37. $arguments = array($foo);
  38. $count = func_num_args();
  39. if ($count > 1) {
  40. $_arguments = func_get_args();
  41. for ($i = 1; $i < $count; $i++) {
  42. $arguments[] = $_arguments[$i];
  43. }
  44. }
  45. $result = $this->__phpunit_getInvocationMocker()->invoke(
  46. new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation(
  47. 'Foo', 'bar', $arguments, '', $this, true
  48. )
  49. );
  50. return $result;
  51. }
  52. public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher)
  53. {
  54. return $this->__phpunit_getInvocationMocker()->expects($matcher);
  55. }
  56. public function method()
  57. {
  58. $any = new \PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount;
  59. $expects = $this->expects($any);
  60. return call_user_func_array(array($expects, 'method'), func_get_args());
  61. }
  62. public function __phpunit_setOriginalObject($originalObject)
  63. {
  64. $this->__phpunit_originalObject = $originalObject;
  65. }
  66. public function __phpunit_getInvocationMocker()
  67. {
  68. if ($this->__phpunit_invocationMocker === null) {
  69. $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable);
  70. }
  71. return $this->__phpunit_invocationMocker;
  72. }
  73. public function __phpunit_hasMatchers()
  74. {
  75. return $this->__phpunit_getInvocationMocker()->hasMatchers();
  76. }
  77. public function __phpunit_verify($unsetInvocationMocker = true)
  78. {
  79. $this->__phpunit_getInvocationMocker()->verify();
  80. if ($unsetInvocationMocker) {
  81. $this->__phpunit_invocationMocker = null;
  82. }
  83. }
  84. }