castopod/tests/unit/HealthTest.php
Yassine Doghri 5c5c6da4be
refactor: add rector to enforce type declarations, code quality + style and remove dead code
- update CI process to include quality stage (tests + code review)
- add captainhook to install git pre-commit & pre-push hooks
- remove .devcontainer Dockerfile to use project's docker-compose services: all
services can now be started automatically using vscode
- update docs/setup-development.md
2021-05-12 10:48:30 +00:00

60 lines
1.6 KiB
PHP

<?php
namespace Tests\Unit;
use Config\App;
use Config\Services;
use Tests\Support\Libraries\ConfigReader;
class HealthTest extends \CodeIgniter\Test\CIUnitTestCase
{
public function setUp(): void
{
parent::setUp();
}
public function testIsDefinedAppPath()
{
$test = defined('APPPATH');
$this->assertTrue($test);
}
public function testBaseUrlHasBeenSet()
{
$validation = Services::validation();
$env = false;
// Check the baseURL in .env
if (is_file(HOMEPATH . '.env')) {
$env = (bool) preg_grep(
'/^app\.baseURL = ./',
file(HOMEPATH . '.env'),
);
}
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(
$validation->check($config->baseURL, 'valid_url'),
'baseURL "' . $config->baseURL . '" in .env is not valid URL',
);
}
// Get the baseURL in app/Config/App.php
// You can't use Config\App, because phpunit.xml.dist sets app.baseURL
$reader = new ConfigReader();
// BaseURL in app/Config/App.php is a valid URL?
$this->assertTrue(
$validation->check($reader->baseURL, 'valid_url'),
'baseURL "' .
$reader->baseURL .
'" in app/Config/App.php is not valid URL',
);
}
}