namespaced_class.phpt 3.1KB

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