namespaced_interface.phpt 2.5KB

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