| Conditions | 8 |
| Paths | 6 |
| Total Lines | 35 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public function buildRequestMock($url, $getVars = [], $postVars = [], $method = null, Session $session = null) |
||
| 22 | { |
||
| 23 | if (is_null($session)) { |
||
| 24 | $session = new Session([]); |
||
| 25 | } |
||
| 26 | |||
| 27 | $request = $this->createMock(HTTPRequest::class); |
||
|
|
|||
| 28 | |||
| 29 | $request->method('getSession')->willReturn($session); |
||
| 30 | |||
| 31 | $request->method('getURL')->will($this->returnCallback(static function ($addParams) use ($url, $getVars) { |
||
| 32 | return $addParams && count($getVars) ? $url.'?'.http_build_query($getVars) : $url; |
||
| 33 | })); |
||
| 34 | |||
| 35 | $request->method('getVars')->willReturn($getVars); |
||
| 36 | $request->method('getVar')->will($this->returnCallback(static function ($key) use ($getVars) { |
||
| 37 | return isset($getVars[$key]) ? $getVars[$key] : null; |
||
| 38 | })); |
||
| 39 | |||
| 40 | $request->method('postVars')->willReturn($postVars); |
||
| 41 | $request->method('postVar')->will($this->returnCallback(static function ($key) use ($postVars) { |
||
| 42 | return isset($postVars[$key]) ? $postVars[$key] : null; |
||
| 43 | })); |
||
| 44 | |||
| 45 | if (is_null($method)) { |
||
| 46 | if (count($postVars)) { |
||
| 47 | $method = 'POST'; |
||
| 48 | } else { |
||
| 49 | $method = 'GET'; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | $request->method('httpMethod')->willReturn($method); |
||
| 54 | |||
| 55 | return $request; |
||
| 56 | } |
||
| 58 |