Skip to content
This repository was archived by the owner on Feb 20, 2023. It is now read-only.

Commit 5184fd5

Browse files
committed
Added simpler to use will* methods
1 parent 8ce9c35 commit 5184fd5

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

PHPUnit/Framework/MockObject/Builder/InvocationMocker.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,92 @@ public function will(PHPUnit_Framework_MockObject_Stub $stub)
114114
return $this;
115115
}
116116

117+
/**
118+
* @param mixed $value
119+
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
120+
*/
121+
public function willReturn($value)
122+
{
123+
$stub = new PHPUnit_Framework_MockObject_Stub_Return(
124+
$value
125+
);
126+
127+
return $this->will($stub);
128+
}
129+
130+
/**
131+
* @param array $valueMap
132+
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
133+
*/
134+
public function willReturnMap(array $valueMap)
135+
{
136+
$stub = new PHPUnit_Framework_MockObject_Stub_ReturnValueMap(
137+
$valueMap
138+
);
139+
140+
return $this->will($stub);
141+
}
142+
143+
/**
144+
* @param mixed $argumentIndex
145+
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
146+
*/
147+
public function willReturnArgument($argumentIndex)
148+
{
149+
$stub = new PHPUnit_Framework_MockObject_Stub_ReturnArgument(
150+
$argumentIndex
151+
);
152+
153+
return $this->will($stub);
154+
}
155+
156+
/**
157+
* @param callable $callback
158+
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
159+
*/
160+
public function willReturnCallback($callback)
161+
{
162+
$stub = new PHPUnit_Framework_MockObject_Stub_ReturnCallback(
163+
$callback
164+
);
165+
166+
return $this->will($stub);
167+
}
168+
169+
/**
170+
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
171+
*/
172+
public function willReturnSelf()
173+
{
174+
$stub = new PHPUnit_Framework_MockObject_Stub_ReturnSelf();
175+
176+
return $this->will($stub);
177+
}
178+
179+
/**
180+
* @param mixed $value, ...
181+
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
182+
*/
183+
public function willReturnOnConsecutiveCalls()
184+
{
185+
$args = func_get_args();
186+
187+
$stub = new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls($args);
188+
189+
return $this->will($stub);
190+
}
191+
192+
/**
193+
* @param Exception $exception
194+
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
195+
*/
196+
public function willThrowException(Exception $exception)
197+
{
198+
$stub = new PHPUnit_Framework_MockObject_Stub_Exception($exception);
199+
200+
return $this->will($stub);
201+
}
202+
117203
/**
118204
* @param mixed $id
119205
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker

0 commit comments

Comments
 (0)