Files
XC_VM/tests/Unit/QueryHelperTest.php
T
Divarion_D 73875dd112 test: name the covered class in full in every @covers
PHPUnit reads @covers without the file's use imports, so a short name
(@covers AdminHelpers) is invalid. It checks them only when it collects
coverage, and failOnWarning turned the 77 warnings into exit code 1:
the coverage run had always failed behind continue-on-error, and the
suite run that now writes coverage failed CI with every test passing.
2026-10-07 20:21:51 +03:00

43 lines
1.4 KiB
PHP

<?php
use XcVm\Core\Database\Database;
use XcVm\Core\Database\QueryHelper;
use PHPUnit\Framework\TestCase;
/**
* @covers \XcVm\Core\Database\QueryHelper
*/
final class QueryHelperTest extends TestCase {
public function testPrepareColumnSanitizesToSafeIdentifier() {
$this->assertSame('foobar23', QueryHelper::prepareColumn('Foo Bar!23'));
$this->assertSame('user_id', QueryHelper::prepareColumn('user_id'));
$this->assertSame('droptable', QueryHelper::prepareColumn('drop;table'));
}
public function testPrepareArrayBuildsColumnsPlaceholdersAndData() {
$result = QueryHelper::prepareArray(array('name' => 'x', 'age' => 5));
$this->assertSame('`name`,`age`', $result['columns']);
$this->assertSame('?,?', $result['placeholder']);
$this->assertSame(array('x', 5), $result['data']);
$this->assertSame('`name` = ?,`age` = ?', $result['update']);
}
public function testPrepareArrayJsonEncodesArrayValues() {
$result = QueryHelper::prepareArray(array('tags' => array(1, 2, 3)));
$this->assertSame('[1,2,3]', $result['data'][0]);
}
public function testPrepareArrayNormalizesNullValues() {
$result = QueryHelper::prepareArray(array('a' => null, 'b' => 'null'));
$this->assertNull($result['data'][0]);
$this->assertNull($result['data'][1]);
}
public function testPrepareArraySanitizesColumnNames() {
$result = QueryHelper::prepareArray(array('na me!' => 'v'));
$this->assertSame('`name`', $result['columns']);
}
}