added unit tests
This commit is contained in:
56
tests/Unit/CommonHelpersTest.php
Normal file
56
tests/Unit/CommonHelpersTest.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class CommonHelpersTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
require_once dirname(__DIR__, 2) . '/common.php';
|
||||
}
|
||||
|
||||
public function testIsStableKey(): void
|
||||
{
|
||||
$this->assertTrue(qdb_is_stable_key('question_key'));
|
||||
$this->assertTrue(qdb_is_stable_key('yes'));
|
||||
$this->assertFalse(qdb_is_stable_key('Question Key'));
|
||||
$this->assertFalse(qdb_is_stable_key(''));
|
||||
}
|
||||
|
||||
public function testNormalizeStableKeyCoercesSpaces(): void
|
||||
{
|
||||
$this->assertSame('My_Key', qdb_normalize_stable_key('My Key'));
|
||||
$this->assertSame('consent_q', qdb_normalize_stable_key('consent_q'));
|
||||
}
|
||||
|
||||
public function testValidateStableKeyReturnsNormalized(): void
|
||||
{
|
||||
$this->assertSame('My_Key', qdb_validate_stable_key('My Key', 'Question key'));
|
||||
}
|
||||
|
||||
public function testMessageKeyFromConditionJson(): void
|
||||
{
|
||||
$json = json_encode(['messageKey' => 'locked_hint'], JSON_THROW_ON_ERROR);
|
||||
$this->assertSame('locked_hint', qdb_message_key_from_condition_json($json));
|
||||
$this->assertSame('', qdb_message_key_from_condition_json('{}'));
|
||||
}
|
||||
|
||||
public function testMergeGlassSymptomJson(): void
|
||||
{
|
||||
$merged = qdb_merge_glass_symptom_json('{"pain":"mild"}', ['fatigue' => 'severe']);
|
||||
$data = json_decode($merged, true, 512, JSON_THROW_ON_ERROR);
|
||||
$this->assertSame('mild', $data['pain']);
|
||||
$this->assertSame('severe', $data['fatigue']);
|
||||
}
|
||||
|
||||
public function testGlassSymptomAnswerValue(): void
|
||||
{
|
||||
$json = json_encode(['pain' => 'moderate'], JSON_THROW_ON_ERROR);
|
||||
$this->assertSame('moderate', qdb_glass_symptom_answer_value($json, 'pain'));
|
||||
$this->assertSame('', qdb_glass_symptom_answer_value($json, 'missing'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user