| @@ 123-151 (lines=29) @@ | ||
| 120 | * |
|
| 121 | * @param ResponseInterface|Exception|ClientExceptionInterface|callable $result |
|
| 122 | */ |
|
| 123 | public function on(RequestMatcher $requestMatcher, $result) |
|
| 124 | { |
|
| 125 | $callable = null; |
|
| 126 | ||
| 127 | switch (true) { |
|
| 128 | case is_callable($result): |
|
| 129 | $callable = $result; |
|
| 130 | ||
| 131 | break; |
|
| 132 | case $result instanceof ResponseInterface: |
|
| 133 | $callable = function () use ($result) { |
|
| 134 | return $result; |
|
| 135 | }; |
|
| 136 | ||
| 137 | break; |
|
| 138 | case $result instanceof \Exception: |
|
| 139 | $callable = function () use ($result) { |
|
| 140 | throw $result; |
|
| 141 | }; |
|
| 142 | ||
| 143 | break; |
|
| 144 | default: |
|
| 145 | throw new \InvalidArgumentException('Result must be either a response, an exception, or a callable'); |
|
| 146 | } |
|
| 147 | $this->conditionalResults[] = [ |
|
| 148 | 'matcher' => $requestMatcher, |
|
| 149 | 'callable' => $callable, |
|
| 150 | ]; |
|
| 151 | } |
|
| 152 | ||
| 153 | /** |
|
| 154 | * Adds an exception that will be thrown. |
|
| @@ 76-105 (lines=30) @@ | ||
| 73 | * |
|
| 74 | * @param ResponseInterface|Exception|ClientExceptionInterface|callable $result |
|
| 75 | */ |
|
| 76 | public function on(RequestMatcher $requestMatcher, $result) |
|
| 77 | { |
|
| 78 | $callable = null; |
|
| 79 | ||
| 80 | switch (true) { |
|
| 81 | case is_callable($result): |
|
| 82 | $callable = $result; |
|
| 83 | ||
| 84 | break; |
|
| 85 | case $result instanceof ResponseInterface: |
|
| 86 | $callable = function () use ($result) { |
|
| 87 | return $result; |
|
| 88 | }; |
|
| 89 | ||
| 90 | break; |
|
| 91 | case $result instanceof \Exception: |
|
| 92 | $callable = function () use ($result) { |
|
| 93 | throw $result; |
|
| 94 | }; |
|
| 95 | ||
| 96 | break; |
|
| 97 | default: |
|
| 98 | throw new \InvalidArgumentException('Result must be either a response, an exception, or a callable'); |
|
| 99 | } |
|
| 100 | ||
| 101 | $this->configuredSequence[] = [ |
|
| 102 | 'matcher' => $requestMatcher, |
|
| 103 | 'callable' => $callable, |
|
| 104 | ]; |
|
| 105 | } |
|
| 106 | ||
| 107 | /** |
|
| 108 | * Returns true when the configured sequence of requests and responses (or exceptions) |
|