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