Quelltext des aktuellen Standes
<?php
declare(strict_types=1);
use OpenNIT\Services\RelutionSyncService;
/**
* Deckt die Auflösung des Plattform-Filters und das Auslesen der Geräteliste ab.
*
* Beide entscheiden darüber, ob ein Sync Geräte findet, und müssen für bereits
* konfigurierte Instanzen exakt das bisherige Ergebnis liefern.
*/
return static function (): void {
/** Ruft eine private Methode der Klasse auf (ohne HTTP-Zugriff). */
$callPrivate = static function (string $method, array $args) {
$ref = new ReflectionClass(RelutionSyncService::class);
$svc = $ref->newInstanceWithoutConstructor();
$m = $ref->getMethod($method);
$m->setAccessible(true);
return $m->invokeArgs($svc, $args);
};
// ----------------------------------------------------------------
// Plattform-Filter
// ----------------------------------------------------------------
test('Plattform-Filter: nie konfiguriert ergibt die Standardplattformen', function () {
assertSame(
['ANDROID', 'ANDROID_ENTERPRISE', 'IOS'],
RelutionSyncService::resolvePlatformFilter(null, false)
);
});
test('Plattform-Filter: leer gespeichert ergibt weiterhin die Standardplattformen', function () {
// Bestandsverhalten: Ein leeres Array bedeutet nicht "kein Filter".
assertSame(
['ANDROID', 'ANDROID_ENTERPRISE', 'IOS'],
RelutionSyncService::resolvePlatformFilter('[]', false)
);
});
test('Plattform-Filter: gespeicherte Auswahl bleibt erhalten', function () {
assertSame(
['IOS', 'WINDOWS'],
RelutionSyncService::resolvePlatformFilter('["IOS","WINDOWS"]', false)
);
});
test('Plattform-Filter: Werte werden auf Großschreibung normalisiert', function () {
assertSame(
['IOS', 'MACOS'],
RelutionSyncService::resolvePlatformFilter('[" ios ","macos"]', false)
);
});
test('Plattform-Filter: "alle Plattformen" schaltet den Filter ab', function () {
assertSame([], RelutionSyncService::resolvePlatformFilter('["IOS"]', true));
assertSame([], RelutionSyncService::resolvePlatformFilter(null, true));
});
test('Plattform-Filter: unbrauchbarer Wert fällt auf die Standardplattformen zurück', function () {
assertSame(
['ANDROID', 'ANDROID_ENTERPRISE', 'IOS'],
RelutionSyncService::resolvePlatformFilter('kein json', false)
);
});
// ----------------------------------------------------------------
// Geräteliste aus der API-Antwort
// ----------------------------------------------------------------
test('Geräteliste: bekannter Schlüssel "results" hat Vorrang', function () use ($callPrivate) {
$out = $callPrivate('extractDeviceList', [[
'results' => [['uuid' => 'a'], ['uuid' => 'b']],
'nonPagedCount' => 2,
]]);
assertSame(2, count($out));
assertSame('a', $out[0]['uuid']);
});
test('Geräteliste: "list" wird weiterhin gelesen', function () use ($callPrivate) {
$out = $callPrivate('extractDeviceList', [['list' => [['uuid' => 'x']]]]);
assertSame(1, count($out));
assertSame('x', $out[0]['uuid']);
});
test('Geräteliste: abweichende Schlüssel werden erkannt', function () use ($callPrivate) {
foreach (['content', 'items', 'data', 'devices'] as $key) {
$out = $callPrivate('extractDeviceList', [[$key => [['uuid' => 'y']]]]);
assertSame(1, count($out), 'Schlüssel ' . $key);
}
});
test('Geräteliste: unbekannt benannte Liste aus Objekten wird gefunden', function () use ($callPrivate) {
$out = $callPrivate('extractDeviceList', [[
'meta' => ['page' => 1],
'geraeteBestand' => [['uuid' => 'z']],
]]);
assertSame(1, count($out));
assertSame('z', $out[0]['uuid']);
});
test('Geräteliste: ohne verwertbare Liste bleibt sie leer', function () use ($callPrivate) {
assertSame([], $callPrivate('extractDeviceList', [['nonPagedCount' => 0]]));
assertSame([], $callPrivate('extractDeviceList', [[]]));
// Eine Liste aus Skalaren ist keine Geräteliste.
assertSame([], $callPrivate('extractDeviceList', [['tags' => ['a', 'b']]]));
});
// ----------------------------------------------------------------
// Gesamtzahl
// ----------------------------------------------------------------
test('Gesamtzahl: bekannte Zählfelder werden gelesen', function () use ($callPrivate) {
assertSame(7, $callPrivate('extractTotal', [['nonPagedCount' => 7]]));
assertSame(7, $callPrivate('extractTotal', [['nonpagedCount' => 7]]));
assertSame(7, $callPrivate('extractTotal', [['total' => '7']]));
assertSame(7, $callPrivate('extractTotal', [['totalElements' => 7]]));
});
test('Gesamtzahl: fehlt sie, wird das gemeldet statt geraten', function () use ($callPrivate) {
assertSame(null, $callPrivate('extractTotal', [['results' => [['uuid' => 'a']]]]));
});
};