RoundCube Webmail
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.

49 lines
1.3 KiB

  1. <?php
  2. namespace Roundcube\Tests;
  3. use PHPUnit\Framework\TestCase;
  4. use Symfony\Component\Process\Process;
  5. /**
  6. * Test class to test HTTP requests to Roundcube
  7. */
  8. class ServerTestCase extends TestCase
  9. {
  10. protected static $phpProcess;
  11. #[\Override]
  12. public static function setUpBeforeClass(): void
  13. {
  14. $path = realpath(__DIR__ . '/../public_html');
  15. $cmd = ['php', '-S', 'localhost:8000', '-t', $path];
  16. $env = [];
  17. static::$phpProcess = new Process($cmd, null, $env);
  18. static::$phpProcess->setWorkingDirectory($path);
  19. static::$phpProcess->start();
  20. usleep(100 * 1000); // give the server some time before we start testing
  21. }
  22. #[\Override]
  23. public static function tearDownAfterClass(): void
  24. {
  25. static::$phpProcess->stop();
  26. }
  27. /**
  28. * HTTP client request
  29. */
  30. protected function request($method, $path, $options = [])
  31. {
  32. $config = [
  33. 'base_uri' => 'http://localhost:8000',
  34. 'http_errors' => false, // no exceptions for HTTP error codes
  35. 'handler' => null, // reset Mock state from other tests
  36. ];
  37. $client = \rcmail::get_instance()->get_http_client($config);
  38. return $client->request($method, $path, $options);
  39. }
  40. }