Goal
Several pure helper methods without MediaWiki context dependencies are untested or only indirectly covered via SpecialKnowledgeGraphDesignerTest.php. Low test effort, good coverage payoff per line of test code.
Test scenarios
applyDefaultParams() (includes/KnowledgeGraph.php:498-540)
- Type
bool/boolean: a valid value is converted to bool correctly; an invalid value falls back to the default (also interpreted via filter_var).
- Type
array: a comma-separated string is split correctly and empty entries are removed.
- Type
number: valid/invalid float value.
- Type
int/integer: valid/invalid integer value.
- Unknown type (
default branch): value is passed through unchanged.
- Missing key in
$params → default value is used.
parseParameters() (includes/KnowledgeGraph.php:548-565)
- A known parameter (
key=value) is extracted into $options, including normalization of spaces to hyphens in the key.
- An unknown parameter or a value without
= remains in the returned list ($ret).
makeRelationKey() (includes/KnowledgeGraph.php:813-817)
makeRelationKey('A', 'B', 'prop') and makeRelationKey('B', 'A', 'prop') produce the same key (reflection needed, since it's private).
resetSeenRelations() (includes/KnowledgeGraph.php:819-821)
- Resets
self::$relationsSeen to [] (reflection-based assertion before/after the call).
Mocking pattern
No mocks needed — plain PHPUnit\Framework\TestCase tests. Use reflection for private/static properties, analogous to tests/phpunit/Unit/KnowledgeGraphSetSemanticDataFromApiTest.php.
Part of the "raise PHP coverage to ~70%" effort.
Goal
Several pure helper methods without MediaWiki context dependencies are untested or only indirectly covered via
SpecialKnowledgeGraphDesignerTest.php. Low test effort, good coverage payoff per line of test code.Test scenarios
applyDefaultParams()(includes/KnowledgeGraph.php:498-540)bool/boolean: a valid value is converted toboolcorrectly; an invalid value falls back to the default (also interpreted viafilter_var).array: a comma-separated string is split correctly and empty entries are removed.number: valid/invalid float value.int/integer: valid/invalid integer value.defaultbranch): value is passed through unchanged.$params→ default value is used.parseParameters()(includes/KnowledgeGraph.php:548-565)key=value) is extracted into$options, including normalization of spaces to hyphens in the key.=remains in the returned list ($ret).makeRelationKey()(includes/KnowledgeGraph.php:813-817)makeRelationKey('A', 'B', 'prop')andmakeRelationKey('B', 'A', 'prop')produce the same key (reflection needed, since it'sprivate).resetSeenRelations()(includes/KnowledgeGraph.php:819-821)self::$relationsSeento[](reflection-based assertion before/after the call).Mocking pattern
No mocks needed — plain
PHPUnit\Framework\TestCasetests. Use reflection for private/static properties, analogous totests/phpunit/Unit/KnowledgeGraphSetSemanticDataFromApiTest.php.Part of the "raise PHP coverage to ~70%" effort.