397.phpt 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. --TEST--
  2. https://github.com/sebastianbergmann/phpunit-mock-objects/issues/397
  3. --FILE--
  4. <?php
  5. class C
  6. {
  7. public function m(?self $other): self
  8. {
  9. }
  10. }
  11. require __DIR__ . '/../../vendor/autoload.php';
  12. $generator = new \PHPUnit\Framework\MockObject\Generator;
  13. $mock = $generator->generate(
  14. C::class,
  15. [],
  16. 'MockC',
  17. true,
  18. true
  19. );
  20. print $mock['code'];
  21. --EXPECTF--
  22. class MockC extends C implements PHPUnit\Framework\MockObject\MockObject
  23. {
  24. private $__phpunit_invocationMocker;
  25. private $__phpunit_originalObject;
  26. private $__phpunit_configurable = ['m'];
  27. public function __clone()
  28. {
  29. $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
  30. }
  31. public function m(?C $other): C
  32. {
  33. $arguments = array($other);
  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. 'C', 'm', $arguments, 'C', $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. }