|
6 | 6 |
|
7 | 7 | use Codeception\Lib\ModuleContainer; |
8 | 8 | use Codeception\Test\Unit; |
| 9 | +use Generator; |
9 | 10 | use GuzzleHttp\Client; |
10 | 11 | use GuzzleHttp\Handler\MockHandler; |
11 | 12 | use GuzzleHttp\HandlerStack; |
@@ -270,4 +271,82 @@ public function testSendClearRequestsCallsClearEndpoint(): void |
270 | 271 | // Should not throw exception |
271 | 272 | $this->assertTrue(true); |
272 | 273 | } |
| 274 | + |
| 275 | + /** |
| 276 | + * Test determineUrlKey method for proper url vs urlPath selection |
| 277 | + * |
| 278 | + * @dataProvider urlKeyDataProvider |
| 279 | + */ |
| 280 | + public function testDetermineUrlKey(array $matchers, string $expectedKey): void |
| 281 | + { |
| 282 | + $reflection = new ReflectionClass($this->module); |
| 283 | + $method = $reflection->getMethod('determineUrlKey'); |
| 284 | + |
| 285 | + $result = $method->invoke($this->module, $matchers); |
| 286 | + |
| 287 | + $this->assertSame($expectedKey, $result); |
| 288 | + } |
| 289 | + |
| 290 | + /** |
| 291 | + * Data provider for testDetermineUrlKey |
| 292 | + * |
| 293 | + * @return Generator<string, array{matchers: array<string, mixed>, expectedKey: string}> |
| 294 | + */ |
| 295 | + public static function urlKeyDataProvider(): Generator |
| 296 | + { |
| 297 | + yield 'no matchers - uses url' => [ |
| 298 | + 'matchers' => [], |
| 299 | + 'expectedKey' => 'url', |
| 300 | + ]; |
| 301 | + |
| 302 | + yield 'only method matcher - uses url' => [ |
| 303 | + 'matchers' => ['method' => 'GET'], |
| 304 | + 'expectedKey' => 'url', |
| 305 | + ]; |
| 306 | + |
| 307 | + yield 'with queryParameters - uses urlPath' => [ |
| 308 | + 'matchers' => [ |
| 309 | + 'queryParameters' => ['q' => ['equalTo' => 'London']], |
| 310 | + ], |
| 311 | + 'expectedKey' => 'urlPath', |
| 312 | + ]; |
| 313 | + |
| 314 | + yield 'with queryParameters and other matchers - uses urlPath' => [ |
| 315 | + 'matchers' => [ |
| 316 | + 'queryParameters' => ['q' => ['equalTo' => 'London']], |
| 317 | + 'headers' => ['Content-Type' => ['equalTo' => 'application/json']], |
| 318 | + ], |
| 319 | + 'expectedKey' => 'urlPath', |
| 320 | + ]; |
| 321 | + |
| 322 | + yield 'explicit urlPath overrides - uses url (respects user choice)' => [ |
| 323 | + 'matchers' => [ |
| 324 | + 'queryParameters' => ['q' => ['equalTo' => 'London']], |
| 325 | + 'urlPath' => '/api/weather', |
| 326 | + ], |
| 327 | + 'expectedKey' => 'url', |
| 328 | + ]; |
| 329 | + |
| 330 | + yield 'explicit urlPattern overrides - uses url (respects user choice)' => [ |
| 331 | + 'matchers' => [ |
| 332 | + 'queryParameters' => ['q' => ['equalTo' => 'London']], |
| 333 | + 'urlPattern' => '/api/.*', |
| 334 | + ], |
| 335 | + 'expectedKey' => 'url', |
| 336 | + ]; |
| 337 | + |
| 338 | + yield 'only bodyPatterns - uses url' => [ |
| 339 | + 'matchers' => [ |
| 340 | + 'bodyPatterns' => [['equalToJson' => '{"name":"test"}']], |
| 341 | + ], |
| 342 | + 'expectedKey' => 'url', |
| 343 | + ]; |
| 344 | + |
| 345 | + yield 'only headers - uses url' => [ |
| 346 | + 'matchers' => [ |
| 347 | + 'headers' => ['Authorization' => ['matches' => 'Bearer .*']], |
| 348 | + ], |
| 349 | + 'expectedKey' => 'url', |
| 350 | + ]; |
| 351 | + } |
273 | 352 | } |
0 commit comments