Tests / test (push) Waiting to run
Do not latch full on transient zero current; require explicit completion. Validate go-e errors and Pico status/timestamps, keep historical events diagnostic, and preserve faults until a fresh successful poll. Budget the 6 A phase probe through the manager and correct stale phase counts conservatively. Add adapter, regulator, isolated runtime and Symcon regression cases plus migration documentation. Verified: composer check (402 tests, 1875 assertions), 92 pure-function assertions in Symcon 8.0, git diff --check. No plant deployment or hardware commands.
93 lines
4.1 KiB
PHP
93 lines
4.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
// Used only by isolated PHPUnit processes; never load inside a Symcon kernel.
|
|
if (function_exists('IPS_GetKernelVersion')) {
|
|
throw new RuntimeException('Der isolierte Test darf nicht in Symcon laufen.');
|
|
}
|
|
|
|
final class LadestationRuntime
|
|
{
|
|
public static array $variables = [];
|
|
public static array $children = [];
|
|
public static array $managers = [];
|
|
public static array $messages = [];
|
|
public static array $commands = [];
|
|
public static int $nextID = 40000;
|
|
}
|
|
|
|
class IPSModule
|
|
{
|
|
public int $InstanceID;
|
|
public array $testProperties = [];
|
|
public array $testAttributes = [];
|
|
public array $testTimers = [];
|
|
public int $testStatus = 0;
|
|
|
|
public function __construct(int $id) { $this->InstanceID = $id; }
|
|
public function Create(): void {}
|
|
public function ApplyChanges(): void {}
|
|
public function EnableAction(string $ident): void {}
|
|
public function SetStatus(int $status): void { $this->testStatus = $status; }
|
|
public function SetTimerInterval(string $ident, int $interval): void { $this->testTimers[$ident] = $interval; }
|
|
public function RegisterTimer(string $ident, int $interval, string $script): void { $this->SetTimerInterval($ident, $interval); }
|
|
public function SendDebug(string $sender, string $text, int $format): void {}
|
|
|
|
public function __call(string $method, array $arguments)
|
|
{
|
|
if (preg_match('/^(Register|Read|Write)(Property|Attribute)(Boolean|Integer|Float|String)$/', $method, $parts)) {
|
|
$storage = $parts[2] === 'Property' ? 'testProperties' : 'testAttributes';
|
|
$ident = $arguments[0];
|
|
if ($parts[1] === 'Register') {
|
|
$this->{$storage}[$ident] = $this->{$storage}[$ident] ?? $arguments[1];
|
|
return null;
|
|
}
|
|
if ($parts[1] === 'Write') {
|
|
$this->{$storage}[$ident] = $arguments[1];
|
|
return null;
|
|
}
|
|
if (!array_key_exists($ident, $this->{$storage})) {
|
|
throw new RuntimeException('Unregistered test property/attribute: ' . $ident);
|
|
}
|
|
return $this->{$storage}[$ident];
|
|
}
|
|
if (preg_match('/^RegisterVariable(Boolean|Integer|Float|String)$/', $method, $parts)) {
|
|
$ident = $arguments[0];
|
|
$id = LadestationRuntime::$children[$this->InstanceID][$ident] ?? ++LadestationRuntime::$nextID;
|
|
LadestationRuntime::$children[$this->InstanceID][$ident] = $id;
|
|
LadestationRuntime::$variables[$id] = LadestationRuntime::$variables[$id]
|
|
?? ['Boolean' => false, 'Integer' => 0, 'Float' => 0.0, 'String' => ''][$parts[1]];
|
|
return $id;
|
|
}
|
|
throw new BadMethodCallException('Unsupported test call: ' . $method);
|
|
}
|
|
|
|
public function GetIDForIdent(string $ident): int
|
|
{
|
|
return LadestationRuntime::$children[$this->InstanceID][$ident] ?? 0;
|
|
}
|
|
public function SetValue(string $ident, $value): void
|
|
{
|
|
$id = $this->GetIDForIdent($ident);
|
|
if (!$id) { throw new RuntimeException('Unregistered test variable: ' . $ident); }
|
|
LadestationRuntime::$variables[$id] = $value;
|
|
if ($ident === 'LetzterGeraetebefehl') {
|
|
LadestationRuntime::$commands[] = json_decode($value, true, 512, JSON_THROW_ON_ERROR);
|
|
}
|
|
}
|
|
public function GetValue(string $ident) { return LadestationRuntime::$variables[$this->GetIDForIdent($ident)]; }
|
|
public function UnregisterVariable(string $ident): void
|
|
{
|
|
unset(LadestationRuntime::$variables[$this->GetIDForIdent($ident)], LadestationRuntime::$children[$this->InstanceID][$ident]);
|
|
}
|
|
}
|
|
|
|
function IPS_VariableExists(int $id): bool { return array_key_exists($id, LadestationRuntime::$variables); }
|
|
function IPS_GetInstanceListByModuleID(string $id): array { return array_keys(LadestationRuntime::$managers); }
|
|
function IPS_GetProperty(int $id, string $property) { return LadestationRuntime::$managers[$id][$property]; }
|
|
function IPS_RequestAction(int $id, string $ident, $value): bool
|
|
{
|
|
LadestationRuntime::$messages[] = [$id, $ident, $value];
|
|
return true;
|
|
}
|