Skip to content

test: tests for smaller helper methods in KnowledgeGraph (applyDefaultParams, parseParameters, makeRelationKey, resetSeenRelations) #74

Description

@gesinn-it-gea

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsPHPUnit coverage work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions