HealthTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. use CodeIgniter\Test\CIUnitTestCase;
  3. use Config\App;
  4. use Tests\Support\Libraries\ConfigReader;
  5. /**
  6. * @internal
  7. */
  8. final class HealthTest extends CIUnitTestCase
  9. {
  10. public function testIsDefinedAppPath(): void
  11. {
  12. $this->assertTrue(defined('APPPATH'));
  13. }
  14. public function testBaseUrlHasBeenSet(): void
  15. {
  16. $validation = service('validation');
  17. $env = false;
  18. // Check the baseURL in .env
  19. if (is_file(HOMEPATH . '.env')) {
  20. $env = preg_grep('/^app\.baseURL = ./', file(HOMEPATH . '.env')) !== false;
  21. }
  22. if ($env) {
  23. // BaseURL in .env is a valid URL?
  24. // phpunit.dist.xml sets app.baseURL in $_SERVER
  25. // So if you set app.baseURL in .env, it takes precedence
  26. $config = new App();
  27. $this->assertTrue(
  28. $validation->check($config->baseURL, 'valid_url'),
  29. 'baseURL "' . $config->baseURL . '" in .env is not valid URL',
  30. );
  31. }
  32. // Get the baseURL in app/Config/App.php
  33. // You can't use Config\App, because phpunit.dist.xml sets app.baseURL
  34. $reader = new ConfigReader();
  35. // BaseURL in app/Config/App.php is a valid URL?
  36. $this->assertTrue(
  37. $validation->check($reader->baseURL, 'valid_url'),
  38. 'baseURL "' . $reader->baseURL . '" in app/Config/App.php is not valid URL',
  39. );
  40. }
  41. }