Drupal investigation

232.phpt 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. --TEST--
  2. PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', TRUE, TRUE)
  3. --SKIPIF--
  4. <?php
  5. if (version_compare(PHP_VERSION, '5.4.0', '<')) print 'skip: PHP >= 5.4.0 required';
  6. ?>
  7. --FILE--
  8. <?php
  9. trait BaseTrait
  10. {
  11. protected function hello()
  12. {
  13. return 'hello';
  14. }
  15. }
  16. trait ChildTrait
  17. {
  18. use BaseTrait
  19. {
  20. hello as private hi;
  21. }
  22. protected function hello()
  23. {
  24. return 'hi';
  25. }
  26. protected function world()
  27. {
  28. return $this->hi();
  29. }
  30. }
  31. class Foo
  32. {
  33. use ChildTrait;
  34. public function speak()
  35. {
  36. return $this->world();
  37. }
  38. }
  39. require __DIR__ . '/../../vendor/autoload.php';
  40. $generator = new PHPUnit_Framework_MockObject_Generator;
  41. $mock = $generator->generate(
  42. 'Foo',
  43. array(),
  44. 'MockFoo',
  45. TRUE,
  46. TRUE
  47. );
  48. print $mock['code'];
  49. ?>
  50. --EXPECTF--
  51. class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject
  52. {
  53. private $__phpunit_invocationMocker;
  54. private $__phpunit_originalObject;
  55. public function __clone()
  56. {
  57. $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
  58. }
  59. public function speak()
  60. {
  61. $arguments = array();
  62. $count = func_num_args();
  63. if ($count > 0) {
  64. $_arguments = func_get_args();
  65. for ($i = 0; $i < $count; $i++) {
  66. $arguments[] = $_arguments[$i];
  67. }
  68. }
  69. $result = $this->__phpunit_getInvocationMocker()->invoke(
  70. new PHPUnit_Framework_MockObject_Invocation_Object(
  71. 'Foo', 'speak', $arguments, $this, TRUE
  72. )
  73. );
  74. return $result;
  75. }
  76. public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
  77. {
  78. return $this->__phpunit_getInvocationMocker()->expects($matcher);
  79. }
  80. public function method()
  81. {
  82. $any = new PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount;
  83. $expects = $this->expects($any);
  84. return call_user_func_array(array($expects, 'method'), func_get_args());
  85. }
  86. public function __phpunit_setOriginalObject($originalObject)
  87. {
  88. $this->__phpunit_originalObject = $originalObject;
  89. }
  90. public function __phpunit_getInvocationMocker()
  91. {
  92. if ($this->__phpunit_invocationMocker === NULL) {
  93. $this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
  94. }
  95. return $this->__phpunit_invocationMocker;
  96. }
  97. public function __phpunit_hasMatchers()
  98. {
  99. return $this->__phpunit_getInvocationMocker()->hasMatchers();
  100. }
  101. public function __phpunit_verify()
  102. {
  103. $this->__phpunit_getInvocationMocker()->verify();
  104. $this->__phpunit_invocationMocker = NULL;
  105. }
  106. }