Drupal investigation

namespaced_interface.phpt 2.3KB

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