| 1 | <?php |
||
| 9 | class Mock |
||
| 10 | { |
||
| 11 | private $converter; |
||
| 12 | private $test; |
||
| 13 | |||
| 14 | public $params; |
||
| 15 | public $result; |
||
| 16 | public $calls = 0; |
||
| 17 | |||
| 18 | 5 | public function __construct(Converter $converter, Test $test, array $params = []) |
|
| 26 | |||
| 27 | public function withParams($params) |
||
| 32 | |||
| 33 | 5 | public function handler($result) |
|
| 34 | { |
||
| 35 | 5 | $this->result = $result; |
|
| 36 | 5 | if (is_string($result)) { |
|
| 37 | if (!method_exists($this->test, $result)) { |
||
| 38 | throw new Exception("Invalid method ".get_class($this->test)."::$result"); |
||
| 39 | } |
||
| 40 | $this->result = function($params) use ($result) { |
||
| 41 | 3 | $params = $this->converter->toObject($params); |
|
| 42 | 3 | return $this->test->$result($params); |
|
| 43 | }; |
||
| 44 | } |
||
| 45 | 5 | return $this; |
|
| 46 | } |
||
| 47 | |||
| 48 | 1 | public function willDo($result) |
|
| 52 | |||
| 53 | 5 | public function willReturn($result) |
|
| 57 | } |
||
| 58 |