mediawiki-extensions-Cite/tests/phpunit/TestUtils.php
Adam Wight 262fbe24eb Encapsulate ref object: limited to ReferenceStack
This encapsulation gives us field name, type validation and code
documentation.

This patch only affects ReferenceStack and continues to return
approximately the same array outputs to callers.  Some additional
information is included and the placeholder column has a new name.

Bug: T353451
Change-Id: I405fe7ac241f6991fd4c526bfbb58fbc34f2e147
2024-01-09 09:59:16 +01:00

35 lines
683 B
PHP

<?php
namespace Cite\Tests;
use Cite\ReferenceStackItem;
/**
* @license GPL-2.0-or-later
*/
class TestUtils {
/**
* Factory to create internal ref data structures from array fixtures.
*/
public static function refFromArray( ?array $val ): ?ReferenceStackItem {
if ( $val === null ) {
return null;
}
$ref = new ReferenceStackItem();
foreach ( $val as $k => $v ) {
$ref->{$k} = $v;
}
return $ref;
}
/**
* @return array<string,array<string|int,?ReferenceStackItem>>
*/
public static function refGroupsFromArray( array $refs ) {
return array_map(
fn ( $groupRefs ) => array_map( [ self::class, 'refFromArray' ], $groupRefs ),
$refs
);
}
}