rossmitchell /
UpdateCloudFlare
| 1 | <?php |
||
| 2 | declare(strict_types = 1); |
||
| 3 | /** |
||
| 4 | * |
||
| 5 | * Copyright (C) 2018 Ross Mitchell |
||
| 6 | * |
||
| 7 | * This file is part of RossMitchell/UpdateCloudFlare. |
||
| 8 | * |
||
| 9 | * RossMitchell/UpdateCloudFlare is free software: you can redistribute |
||
| 10 | * it and/or modify it under the terms of the GNU General Public License |
||
| 11 | * as published by the Free Software Foundation, either version 3 of the |
||
| 12 | * License, or (at your option) any later version. |
||
| 13 | * |
||
| 14 | * This program is distributed in the hope that it will be useful, |
||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 17 | * GNU General Public License for more details. |
||
| 18 | * |
||
| 19 | * You should have received a copy of the GNU General Public License |
||
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
| 21 | */ |
||
| 22 | |||
| 23 | namespace RossMitchell\UpdateCloudFlare\Tests\Fakes; |
||
| 24 | |||
| 25 | use RossMitchell\UpdateCloudFlare\Interfaces\CurlResourceInterface; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Class CurlResource - Used to allow testing of the main curl class |
||
| 29 | * @package RossMitchell\UpdateCloudFlare\Tests\Fakes |
||
| 30 | */ |
||
| 31 | class CurlResource implements CurlResourceInterface |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | private $error; |
||
| 37 | /** |
||
| 38 | * @var array |
||
| 39 | */ |
||
| 40 | private $options = []; |
||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $result = 'worked'; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Used To initialise the curl resource |
||
| 48 | * |
||
| 49 | * @return bool |
||
| 50 | */ |
||
| 51 | public function curlInit(): bool |
||
| 52 | { |
||
| 53 | return true; |
||
|
0 ignored issues
–
show
|
|||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Used to set a curl option |
||
| 58 | * |
||
| 59 | * @param resource $curl |
||
| 60 | * @param int $option |
||
| 61 | * @param mixed $value |
||
| 62 | * |
||
| 63 | * @return void |
||
| 64 | */ |
||
| 65 | public function setOption($curl, int $option, $value): void |
||
| 66 | { |
||
| 67 | $this->options[$option] = $value; |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @param $option |
||
| 72 | * |
||
| 73 | * @return mixed |
||
| 74 | */ |
||
| 75 | public function getOption($option) |
||
| 76 | { |
||
| 77 | if (!isset($this->options[$option])) { |
||
| 78 | throw new \LogicException("${option} has not been set"); |
||
| 79 | } |
||
| 80 | |||
| 81 | return $this->options[$option]; |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Used to make the curl request |
||
| 86 | * |
||
| 87 | * @param $curl |
||
| 88 | * |
||
| 89 | * @return mixed |
||
| 90 | */ |
||
| 91 | public function curlExec($curl): string |
||
| 92 | { |
||
| 93 | return $this->result; |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Can be used to set a fake result |
||
| 98 | * |
||
| 99 | * @param string $result |
||
| 100 | */ |
||
| 101 | public function setResult(string $result): void |
||
| 102 | { |
||
| 103 | $this->result = $result; |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Used to check if there has been an error with the request |
||
| 108 | * |
||
| 109 | * @param $curl |
||
| 110 | * |
||
| 111 | * @return mixed |
||
| 112 | */ |
||
| 113 | public function curlError($curl) |
||
| 114 | { |
||
| 115 | if ($this->error !== null) { |
||
| 116 | return $this->error; |
||
| 117 | } |
||
| 118 | |||
| 119 | return false; |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Used to close the connection |
||
| 124 | * |
||
| 125 | * @param $curl |
||
| 126 | * |
||
| 127 | * @return void |
||
| 128 | */ |
||
| 129 | public function curlClose($curl): void |
||
| 130 | { |
||
| 131 | |||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @param string $error |
||
| 136 | */ |
||
| 137 | public function setError(string $error): void |
||
| 138 | { |
||
| 139 | $this->error = $error; |
||
| 140 | } |
||
| 141 | } |
||
| 142 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: