1
0
قرینه از https://github.com/matomo-org/matomo.git synced 2025-08-25 00:17:37 +00:00
Files
matomo/tests/PHPUnit/Unit/Config/ConfigTest.php
Stefan Giehl 1903b100fa [Coding Style] Enable rule PSR12.Classes.OpeningBraceSpace.Found (#21688)
* Enable rule PSR12.Classes.OpeningBraceSpace.Found

* autoapply cs
2023-12-14 11:07:27 +01:00

64 خطوط
1.8 KiB
PHP

<?php
namespace Piwik\Tests\Unit\Config;
use Piwik\Application\Kernel\GlobalSettingsProvider;
use Piwik\Config;
use PHPUnit\Framework\TestCase;
class ConfigTest extends TestCase
{
private $config;
protected function setUp(): void
{
$userSettingsPath = __DIR__ . '/test_files/boolean_settings_test.ini.php';
$settingsProvider = new GlobalSettingsProvider([], $userSettingsPath);
$this->config = new Config($settingsProvider);
}
/**
* Returns a boolean variable setting for convenience
* when calling e.g. getBool('General', 'force_ssl')
* This also documents that a boolean is only true if
* it is equal to 1.
* @see https://github.com/matomo-org/matomo/pull/17865
* return 1 === $value || '1' === $value || true === $value; // was suggested for future use by @sgiehl
*
* @param string $section Configuration section
* @param string $name variable name
* @return bool whether it is considered set true (== 1)
*/
private function getBool(string $section, string $name): bool
{
return $this->config->$section[$name] == 1;
}
/**
* @dataProvider getTestCases
*/
public function testGetBool($expected, $setting)
{
$this->assertSame($expected, $this->getBool('BoolSettings', $setting));
}
public function getTestCases(): array
{
return [
[true, 'one'],
[true, 'onestr'],
[true, 'truebool'],
[true, 'isyes'],
[true, 'ison'],
[false, 'truestr'],
[false, 'two'],
[false, 'twostr'],
[false, 'invalid'],
[false, 'oneinstr'],
[false, 'twoinstr'],
[false, 'isoff'],
[false, 'isno'],
];
}
}