Drupal investigation

interface.phpt 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. public function __clone()
  26. {
  27. $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker();
  28. }
  29. public function bar(Foo $foo)
  30. {
  31. $arguments = array($foo);
  32. $count = func_num_args();
  33. if ($count > 1) {
  34. $_arguments = func_get_args();
  35. for ($i = 1; $i < $count; $i++) {
  36. $arguments[] = $_arguments[$i];
  37. }
  38. }
  39. $result = $this->__phpunit_getInvocationMocker()->invoke(
  40. new PHPUnit_Framework_MockObject_Invocation_Object(
  41. 'Foo', 'bar', $arguments, $this, TRUE
  42. )
  43. );
  44. return $result;
  45. }
  46. public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher)
  47. {
  48. return $this->__phpunit_getInvocationMocker()->expects($matcher);
  49. }
  50. public function method()
  51. {
  52. $any = new PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount;
  53. $expects = $this->expects($any);
  54. return call_user_func_array(array($expects, 'method'), func_get_args());
  55. }
  56. public function __phpunit_setOriginalObject($originalObject)
  57. {
  58. $this->__phpunit_originalObject = $originalObject;
  59. }
  60. public function __phpunit_getInvocationMocker()
  61. {
  62. if ($this->__phpunit_invocationMocker === NULL) {
  63. $this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker;
  64. }
  65. return $this->__phpunit_invocationMocker;
  66. }
  67. public function __phpunit_hasMatchers()
  68. {
  69. return $this->__phpunit_getInvocationMocker()->hasMatchers();
  70. }
  71. public function __phpunit_verify()
  72. {
  73. $this->__phpunit_getInvocationMocker()->verify();
  74. $this->__phpunit_invocationMocker = NULL;
  75. }
  76. }