HttpClientTraitTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 4.3.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase\Http\TestSuite;
  17. use Cake\Http\Client;
  18. use Cake\Http\TestSuite\HttpClientTrait;
  19. use Cake\TestSuite\TestCase;
  20. use PHPUnit\Framework\Attributes\DataProvider;
  21. class HttpClientTraitTest extends TestCase
  22. {
  23. use HttpClientTrait;
  24. /**
  25. * Provider for http methods.
  26. *
  27. * @return array<array>
  28. */
  29. public static function methodProvider(): array
  30. {
  31. return [
  32. ['Get'],
  33. ['Post'],
  34. ['Put'],
  35. ['Patch'],
  36. ['Delete'],
  37. ];
  38. }
  39. #[DataProvider('methodProvider')]
  40. public function testRequestMethods(string $httpMethod): void
  41. {
  42. $traitMethod = "mockClient{$httpMethod}";
  43. $response = $this->newClientResponse(200, ['Content-Type: application/json'], '{"ok":true}');
  44. $this->{$traitMethod}('http://example.com', $response);
  45. $client = new Client();
  46. $result = $client->{$httpMethod}('http://example.com');
  47. $this->assertSame($response, $result);
  48. }
  49. }