fix(compat): preserve PHP 8.0 support without changing control guards
Tests / test (push) Successful in 59s
Tests / test (push) Successful in 59s
Replace trait constants and array_is_list usage with equivalent PHP 8.0 constructs. Add strict list/expiry regressions and make isolated reflection tests PHP 8.0 compatible. No control activation, threshold or configuration change.
This commit is contained in:
@@ -19,6 +19,6 @@ final class NetzfahrplanV4RegeltestTest extends TestCase
|
||||
fclose($pipes[1]);fclose($pipes[2]);
|
||||
self::assertSame(0, proc_close($process), $out . $err);
|
||||
self::assertSame('', $err);
|
||||
self::assertStringContainsString('TOTAL 96 checks passed.', $out);
|
||||
self::assertStringContainsString('TOTAL 101 checks passed.', $out);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
if (function_exists('IPS_GetKernelVersion')) {
|
||||
throw new RuntimeException('Offline list checks must never run in Symcon.');
|
||||
}
|
||||
require_once __DIR__ . '/../Support/ManagerSDLRuntime.php';
|
||||
require_once __DIR__ . '/../../Manager/module.php';
|
||||
require_once __DIR__ . '/../../libs/NetzfahrplanV4Rueckmeldung.php';
|
||||
|
||||
use Belevo\EnelixEMS\NetzfahrplanV4Rueckmeldung as Feedback;
|
||||
|
||||
$count = 0;
|
||||
function verify(bool $ok, string $name): void
|
||||
{
|
||||
global $count;
|
||||
if (!$ok) throw new RuntimeException('FAIL ' . $name);
|
||||
++$count;
|
||||
}
|
||||
function invokePrivate(object $object, string $name, array $arguments)
|
||||
{
|
||||
$method = new ReflectionMethod($object, $name);
|
||||
if (PHP_VERSION_ID < 80100) $method->setAccessible(true);
|
||||
return $method->invokeArgs($object, $arguments);
|
||||
}
|
||||
function accepted(callable $call, string $message): bool
|
||||
{
|
||||
try { $call(); return true; }
|
||||
catch (RuntimeException | InvalidArgumentException $error) {
|
||||
if ($error->getMessage() !== $message) throw $error;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$row = ['ID' => 'example', 'VariableID' => 12345];
|
||||
$cases = [
|
||||
'empty' => [[], true],
|
||||
'one' => [[$row], true],
|
||||
'two' => [[$row, $row], true],
|
||||
'sparse' => [[0 => $row, 2 => $row], false],
|
||||
'one-based' => [[1 => $row, 2 => $row], false],
|
||||
'out-of-order' => [[1 => $row, 0 => $row], false],
|
||||
'negative-key' => [[-1 => $row, 0 => $row], false],
|
||||
'string-key' => [['source' => $row], false],
|
||||
'mixed-keys' => [[0 => $row, 'source' => $row], false],
|
||||
'scalar' => [false, false],
|
||||
'null' => [null, false],
|
||||
];
|
||||
foreach ($cases as $name => [$value, $expected]) {
|
||||
ManagerSDLRuntime::reset();
|
||||
$manager = new Manager(42);
|
||||
$manager->Create();
|
||||
$json = json_encode($value, JSON_THROW_ON_ERROR);
|
||||
$manager->testProperties['AnlagenBatterien'] = $json;
|
||||
$result = accepted(static function () use ($manager, $value, $expected): void {
|
||||
$actual = invokePrivate($manager, 'leseAnlagenKonfigurationsliste', ['AnlagenBatterien']);
|
||||
if ($expected) verify($actual === $value, 'valid manager list unchanged');
|
||||
}, 'AnlagenBatterien muss eine JSON-Liste sein.');
|
||||
verify($result === $expected, 'manager list: ' . $name);
|
||||
|
||||
ManagerSDLRuntime::child(42, 'EnergieflussSDL');
|
||||
ManagerSDLRuntime::$properties[700]['Config'] = $json;
|
||||
$result = accepted(static fn() => invokePrivate($manager, 'synchronisiereSDLEnergiefluss', [700]),
|
||||
'Die bestehende Energiefluss-Konfiguration ist keine Liste.');
|
||||
verify($result === $expected, 'SDL list: ' . $name);
|
||||
verify(ManagerSDLRuntime::$writes === [], 'list validation cannot change SDL configuration');
|
||||
verify(ManagerSDLRuntime::$properties[700]['Config'] === $json, 'SDL source remains byte-identical');
|
||||
}
|
||||
|
||||
$config = ['version'=>1, 'installationId'=>'e3a08f9e-af12-4695-99bd-8b51c0520021',
|
||||
'assetId'=>'ev', 'managerId'=>17004, 'batteryInstanceId'=>44234, 'mode'=>'physical_sum',
|
||||
'allowEstimatedForTrial'=>false, 'maxSkewSeconds'=>30, 'maxAgeSeconds'=>60,
|
||||
'idleToleranceW'=>50.0, 'trackingToleranceW'=>200.0, 'sources'=>[]];
|
||||
foreach (['grid', 'physical'] as $i => $role) {
|
||||
$config['sources'][] = ['key'=>'source'.$i, 'role'=>$role, 'variableId'=>100+$i,
|
||||
'parentId'=>200, 'ident'=>'value'.$i, 'factorToW'=>1];
|
||||
}
|
||||
$hash = Feedback::fingerprint($config);
|
||||
$reordered = array_reverse($config, true);
|
||||
$reordered['sources'] = array_reverse($config['sources']);
|
||||
verify(Feedback::fingerprint($reordered) === $hash, 'canonical configuration fingerprint unchanged');
|
||||
foreach ([[], [1, 2], [0, 2], [1, 0], ['grid', 'physical']] as $keys) {
|
||||
$bad = $config;
|
||||
$bad['sources'] = $keys === [] ? [] : array_combine($keys, $config['sources']);
|
||||
verify(!accepted(static fn() => Feedback::configuration($bad), 'feedback_sources_invalid'),
|
||||
'malformed feedback source keys remain rejected');
|
||||
}
|
||||
echo 'PHP80_LISTS_OK ' . $count . " checks; real methods with isolated runtime only.\n";
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Belevo\EnelixEMS\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class Php80ListsTest extends TestCase
|
||||
{
|
||||
public function testListValidationIsIdenticalOnSupportedPhpVersions(): void
|
||||
{
|
||||
$pipes = [];
|
||||
$process = proc_open([PHP_BINARY, __DIR__ . '/Php80Lists/checks.php'],
|
||||
[0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
|
||||
self::assertIsResource($process);
|
||||
fclose($pipes[0]);
|
||||
$out = stream_get_contents($pipes[1]);
|
||||
$err = stream_get_contents($pipes[2]);
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
self::assertSame(0, proc_close($process), $out . $err);
|
||||
self::assertSame('', $err);
|
||||
self::assertStringContainsString('PHP80_LISTS_OK ', $out);
|
||||
}
|
||||
}
|
||||
@@ -210,6 +210,9 @@ namespace {
|
||||
$bad=$r;$bad['controlledTrial']['acceptEstimatedPeak']=false;rejects(fn()=>Gate::befehl($bad,$op,['b'=>0.],$local,$now,$now),'peak uncertainty needs explicit acceptance');
|
||||
[$m,$b]=activeFixture();$m->V4ManagerAktivtestSchalten(true);
|
||||
check($m->active()&&$b->active()&&$m->vars['NetzfahrplanV4Aktivtest'],'single runtime switch starts bounded active test');
|
||||
$activeSession=json_decode($m->buf['V4ManagerTrialSession'],true);
|
||||
check($activeSession['actuatorWatchdogEvidenceId']==='explicit_test_plant_watchdog_waiver',
|
||||
'active session retains exact explicit watchdog waiver identifier');
|
||||
$allocation=tick($m);
|
||||
check(end($b->writes)===3000&&!isset($allocation['Sollwerte'][44234]),'active test uses guarded command path');
|
||||
check($m->command()['executionMeaning']==='explicit_time_boxed_test_plant_operation','active command is explicitly distinguished');
|
||||
@@ -231,6 +234,19 @@ namespace {
|
||||
check($m->active()&&$b->active(),'local active authority refreshes while plan and measurements remain valid');
|
||||
$m->V4ManagerAktivtestSchalten(false);
|
||||
check(!$m->active()&&!$b->active()&&!$m->vars['NetzfahrplanV4Aktivtest']&&end($b->writes)===0,'switch off revokes session and requests zero');
|
||||
[$m,$b]=activeFixture();
|
||||
$m->attrs['NetzfahrplanV4AktivtestBeginn']=$clock-172800;
|
||||
$m->attrs['NetzfahrplanV4AktivtestEnde']=$clock;
|
||||
rejects(fn()=>$m->V4ManagerAktivtestSchalten(true),'active window rejects its exact expiry boundary');
|
||||
check($m->attrs['NetzfahrplanV4AktivtestBeginn']===$clock-172800
|
||||
&&$m->attrs['NetzfahrplanV4AktivtestEnde']===$clock&&!$m->active()&&!$b->active(),
|
||||
'expired active window is never renewed or armed');
|
||||
[$m,$b]=activeFixture();
|
||||
$m->attrs['NetzfahrplanV4AktivtestBeginn']=$clock-1;
|
||||
$m->attrs['NetzfahrplanV4AktivtestEnde']=$clock+172800;
|
||||
rejects(fn()=>$m->V4ManagerAktivtestSchalten(true),'active window rejects even one second beyond 48 hours');
|
||||
check($b->writes===[]&&!$m->active()&&!$b->active(),
|
||||
'oversized active window cannot cause register writes or arm either session');
|
||||
[$m,$b]=activeFixture();$m->props['NetzfahrplanV4WatchdogVerzichtErlaubt']=false;
|
||||
rejects(fn()=>$m->V4ManagerAktivtestSchalten(true),'active test requires explicit watchdog waiver property');
|
||||
[$m,$b]=activeFixture();$b->props['NetzfahrplanV4WatchdogVerzichtErlaubt']=false;
|
||||
|
||||
@@ -26,6 +26,7 @@ $battery->props = [
|
||||
'LeistungsRegisterVariableID' => 3, 'Aenderungssperre' => 0,
|
||||
];
|
||||
$method = new ReflectionMethod(Batterie::class, 'schreibeRegister');
|
||||
if (PHP_VERSION_ID < 80100) $method->setAccessible(true);
|
||||
$accepted = false; $writes = [];
|
||||
try { $method->invoke($battery, 12000, false); throw new LogicException('FALSE was accepted'); }
|
||||
catch (RuntimeException $error) {
|
||||
|
||||
@@ -14,6 +14,7 @@ class IPSModule {
|
||||
require __DIR__.'/../../Batterie/module.php';
|
||||
use Belevo\EnelixEMS\Nachrichtenvertrag as N;
|
||||
$b=new Batterie();$read=new ReflectionMethod(Batterie::class,'baueVerbraucherdaten');$count=0;
|
||||
if (PHP_VERSION_ID < 80100) $read->setAccessible(true);
|
||||
function ck($v,$s){global$count;if(!$v)throw new RuntimeException('FAIL '.$s);$count++;echo "PASS $s\n";}
|
||||
$d=$read->invoke($b,17004);ck($d['Leistungsquelle']===N::LEISTUNGSQUELLE_BERECHNET,'partition source quality independent of hidden diagnostic variables');
|
||||
$b->buffers['V4FeedbackEstimated']='0';$d=$read->invoke($b,17004);ck($d['Leistungsquelle']===N::LEISTUNGSQUELLE_GEMESSEN,'ordinary physical source marked measured');
|
||||
|
||||
Reference in New Issue
Block a user