@@ 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. |
@@ 77-106 (lines=30) @@ | ||
74 | * |
|
75 | * @param ResponseInterface|Exception|ClientExceptionInterface|callable $result |
|
76 | */ |
|
77 | public function on(RequestMatcher $requestMatcher, $result) |
|
78 | { |
|
79 | $callable = null; |
|
80 | ||
81 | switch (true) { |
|
82 | case is_callable($result): |
|
83 | $callable = $result; |
|
84 | ||
85 | break; |
|
86 | case $result instanceof ResponseInterface: |
|
87 | $callable = function () use ($result) { |
|
88 | return $result; |
|
89 | }; |
|
90 | ||
91 | break; |
|
92 | case $result instanceof \Exception: |
|
93 | $callable = function () use ($result) { |
|
94 | throw $result; |
|
95 | }; |
|
96 | ||
97 | break; |
|
98 | default: |
|
99 | throw new \InvalidArgumentException('Result must be either a response, an exception, or a callable'); |
|
100 | } |
|
101 | ||
102 | $this->configuredSequence[] = [ |
|
103 | 'matcher' => $requestMatcher, |
|
104 | 'callable' => $callable, |
|
105 | ]; |
|
106 | } |
|
107 | ||
108 | /** |
|
109 | * Returns true when the configured sequence of requests and responses (or exceptions) |