2020-05-27 18:46:16 +02:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
use CodeIgniter\Test\CIUnitTestCase;
|
2021-05-06 14:00:48 +00:00
|
|
|
use Config\App;
|
|
|
|
use Tests\Support\Libraries\ConfigReader;
|
|
|
|
|
2022-01-04 15:40:27 +00:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
final class HealthTest extends CIUnitTestCase
|
2020-05-27 18:46:16 +02:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
public function testIsDefinedAppPath(): void
|
2020-08-04 11:25:22 +00:00
|
|
|
{
|
2022-01-04 15:40:27 +00:00
|
|
|
$this->assertTrue(defined('APPPATH'));
|
2020-08-04 11:25:22 +00:00
|
|
|
}
|
2020-05-27 18:46:16 +02:00
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
public function testBaseUrlHasBeenSet(): void
|
2020-08-04 11:25:22 +00:00
|
|
|
{
|
2025-01-08 11:11:19 +00:00
|
|
|
$validation = service('validation');
|
2022-01-04 15:40:27 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
$env = false;
|
2020-05-27 18:46:16 +02:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
// Check the baseURL in .env
|
2020-08-04 11:25:22 +00:00
|
|
|
if (is_file(HOMEPATH . '.env')) {
|
2022-01-04 15:40:27 +00:00
|
|
|
$env = preg_grep('~^app\.baseURL = .~', file(HOMEPATH . '.env')) !== false;
|
2021-05-06 14:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($env) {
|
|
|
|
// BaseURL in .env is a valid URL?
|
|
|
|
// phpunit.xml.dist sets app.baseURL in $_SERVER
|
|
|
|
// So if you set app.baseURL in .env, it takes precedence
|
|
|
|
$config = new App();
|
|
|
|
$this->assertTrue(
|
2022-03-04 14:33:48 +00:00
|
|
|
$validation->check($config->baseURL, 'valid_url_strict'),
|
2022-01-04 15:40:27 +00:00
|
|
|
'baseURL "' . $config->baseURL . '" in .env is not valid URL'
|
2020-08-04 11:25:22 +00:00
|
|
|
);
|
|
|
|
}
|
2020-05-27 18:46:16 +02:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
// Get the baseURL in app/Config/App.php
|
|
|
|
// You can't use Config\App, because phpunit.xml.dist sets app.baseURL
|
|
|
|
$reader = new ConfigReader();
|
2020-05-27 18:46:16 +02:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
// BaseURL in app/Config/App.php is a valid URL?
|
|
|
|
$this->assertTrue(
|
2022-03-04 14:33:48 +00:00
|
|
|
$validation->check($reader->baseURL, 'valid_url_strict'),
|
2022-01-04 15:40:27 +00:00
|
|
|
'baseURL "' . $reader->baseURL . '" in app/Config/App.php is not valid URL'
|
2021-05-06 14:00:48 +00:00
|
|
|
);
|
2020-08-04 11:25:22 +00:00
|
|
|
}
|
2020-05-27 18:46:16 +02:00
|
|
|
}
|