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.

HealthTest.php 1.4KB

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