Public Access
feat: add ConfigValidator for plugin JSON schema validation
Generic: Repo Health / Access control (push) Has been cancelled
Generic: Repo Health / Site Health (push) Has been cancelled
Generic: Repo Health / Release configuration (push) Has been cancelled
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Site Health (pull_request) Has been cancelled
Universal: PR Check / Branch Policy (pull_request) Has been cancelled
Generic: Repo Health / Access control (pull_request) Has been cancelled
Universal: Secret Scanning / Gitleaks Secret Scan (pull_request) Has been cancelled
Universal: PR Check / Validate PR (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Generic: Repo Health / Release configuration (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 1: Code Quality (push) Has been cancelled
Platform: moko-platform CI / Gate 1: Code Quality (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (pull_request) Has been cancelled
Platform: moko-platform CI / CI Summary (push) Has been cancelled
Platform: moko-platform CI / CI Summary (pull_request) Has been cancelled
Generic: Repo Health / Access control (push) Has been cancelled
Generic: Repo Health / Site Health (push) Has been cancelled
Generic: Repo Health / Release configuration (push) Has been cancelled
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
Generic: Repo Health / Site Health (pull_request) Has been cancelled
Universal: PR Check / Branch Policy (pull_request) Has been cancelled
Generic: Repo Health / Access control (pull_request) Has been cancelled
Universal: Secret Scanning / Gitleaks Secret Scan (pull_request) Has been cancelled
Universal: PR Check / Validate PR (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Generic: Repo Health / Release configuration (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 1: Code Quality (push) Has been cancelled
Platform: moko-platform CI / Gate 1: Code Quality (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (pull_request) Has been cancelled
Platform: moko-platform CI / CI Summary (push) Has been cancelled
Platform: moko-platform CI / CI Summary (pull_request) Has been cancelled
Validates project config against plugin getConfigSchema() definitions. Supports: type checking, required fields, enum values, nested objects, arrays, string minLength/pattern, number min/max, unknown property warnings. 7 unit tests covering all validation paths. Closes #105 Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MokoStandards\Tests\Unit;
|
||||
|
||||
use MokoEnterprise\ConfigValidator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ConfigValidatorTest extends TestCase
|
||||
{
|
||||
private ConfigValidator $validator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->validator = new ConfigValidator();
|
||||
}
|
||||
|
||||
public function testValidConfigPasses(): void
|
||||
{
|
||||
$schema = [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'name' => ['type' => 'string'],
|
||||
'version' => ['type' => 'string'],
|
||||
],
|
||||
'required' => ['name'],
|
||||
];
|
||||
|
||||
$config = ['name' => 'MyProject', 'version' => '1.0'];
|
||||
|
||||
$this->assertTrue($this->validator->validate($config, $schema));
|
||||
$this->assertEmpty($this->validator->getErrors());
|
||||
}
|
||||
|
||||
public function testMissingRequiredField(): void
|
||||
{
|
||||
$schema = [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'name' => ['type' => 'string'],
|
||||
],
|
||||
'required' => ['name'],
|
||||
];
|
||||
|
||||
$this->assertFalse($this->validator->validate([], $schema));
|
||||
$this->assertStringContainsString(
|
||||
'required',
|
||||
$this->validator->getErrors()[0]
|
||||
);
|
||||
}
|
||||
|
||||
public function testEnumValidation(): void
|
||||
{
|
||||
$schema = [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'type' => [
|
||||
'type' => 'string',
|
||||
'enum' => ['component', 'module', 'plugin'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$valid = ['type' => 'component'];
|
||||
$this->assertTrue($this->validator->validate($valid, $schema));
|
||||
|
||||
$invalid = ['type' => 'banana'];
|
||||
$this->assertFalse($this->validator->validate($invalid, $schema));
|
||||
}
|
||||
|
||||
public function testNestedObjectValidation(): void
|
||||
{
|
||||
$schema = [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'db' => [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'host' => ['type' => 'string'],
|
||||
'port' => ['type' => 'integer'],
|
||||
],
|
||||
'required' => ['host'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$valid = ['db' => ['host' => 'localhost', 'port' => 3306]];
|
||||
$this->assertTrue($this->validator->validate($valid, $schema));
|
||||
|
||||
$invalid = ['db' => ['port' => 3306]];
|
||||
$this->assertFalse($this->validator->validate($invalid, $schema));
|
||||
}
|
||||
|
||||
public function testUnknownPropertiesWarn(): void
|
||||
{
|
||||
$schema = [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'name' => ['type' => 'string'],
|
||||
],
|
||||
];
|
||||
|
||||
$config = ['name' => 'ok', 'extra' => 'unknown'];
|
||||
$this->assertTrue($this->validator->validate($config, $schema));
|
||||
$this->assertNotEmpty($this->validator->getWarnings());
|
||||
}
|
||||
|
||||
public function testTypeMismatch(): void
|
||||
{
|
||||
$schema = [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'count' => ['type' => 'integer'],
|
||||
],
|
||||
];
|
||||
|
||||
$invalid = ['count' => 'not-a-number'];
|
||||
$this->assertFalse($this->validator->validate($invalid, $schema));
|
||||
}
|
||||
|
||||
public function testStringMinLength(): void
|
||||
{
|
||||
$schema = [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'name' => ['type' => 'string', 'minLength' => 3],
|
||||
],
|
||||
];
|
||||
|
||||
$short = ['name' => 'ab'];
|
||||
$this->assertFalse($this->validator->validate($short, $schema));
|
||||
|
||||
$ok = ['name' => 'abc'];
|
||||
$this->assertTrue($this->validator->validate($ok, $schema));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user