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