interface.phpt 2.5 KB

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