blob: 601b354b1e42d5317dac3d3fbea4402ca3e836a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<?php
/*
* This file is part of the PHPUnit_MockObject package.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* @since Class available since Release 1.0.0
*/
class PHPUnit_Framework_MockObject_Stub_ReturnCallback implements PHPUnit_Framework_MockObject_Stub
{
protected $callback;
public function __construct($callback)
{
$this->callback = $callback;
}
public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
{
return call_user_func_array($this->callback, $invocation->parameters);
}
public function toString()
{
if (is_array($this->callback)) {
if (is_object($this->callback[0])) {
$class = get_class($this->callback[0]);
$type = '->';
} else {
$class = $this->callback[0];
$type = '::';
}
return sprintf(
'return result of user defined callback %s%s%s() with the ' .
'passed arguments',
$class,
$type,
$this->callback[1]
);
} else {
return 'return result of user defined callback ' . $this->callback .
' with the passed arguments';
}
}
}
|