You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
961 B

  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. use Symfony\Component\HttpFoundation\Response;
  4. class FetchTest extends PHPUnit\Framework\TestCase
  5. {
  6. private $http;
  7. public function setUp(): void
  8. {
  9. $this->http = new p3k\HTTP();
  10. }
  11. public function testTimeout()
  12. {
  13. $url = 'https://nghttp2.org/httpbin/delay/2';
  14. $this->http->timeout = 1;
  15. $response = $this->http->get($url);
  16. $this->assertEquals('timeout', $response['error']);
  17. }
  18. public function testRedirectLimit()
  19. {
  20. $url = 'https://nghttp2.org/httpbin/redirect/3';
  21. $this->http->max_redirects = 1;
  22. $response = $this->http->get($url);
  23. $this->assertEquals('too_many_redirects', $response['error']);
  24. }
  25. public function testNoError()
  26. {
  27. $url = 'https://nghttp2.org/httpbin/ip';
  28. $response = $this->http->get($url);
  29. $this->assertEquals('', $response['error']);
  30. }
  31. }