216 lines
6.7 KiB
PHP
216 lines
6.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Belevo\EnelixEMS\Tests;
|
|
|
|
use Belevo\EnelixEMS\VerbraucherBasisTrait;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class VerbraucherBasisTraitTest extends TestCase
|
|
{
|
|
/** @dataProvider sollwerte */
|
|
public function testVerwerfenLoeschtGespeicherteUndSichtbareVorgabe(int $leistung, bool $sichtbar): void
|
|
{
|
|
$modul = new VerbraucherBasisDummy();
|
|
$modul->zustand = ['Sollleistung' => $leistung, 'SollwertGueltig' => true];
|
|
$modul->sichtbareWerte = $sichtbar ? $modul->zustand : [];
|
|
|
|
$modul->verwerfen();
|
|
$modul->verwerfen();
|
|
|
|
self::assertSame(['Sollleistung' => 0, 'SollwertGueltig' => false], $modul->zustand);
|
|
self::assertSame($sichtbar ? $modul->zustand : [], $modul->sichtbareWerte);
|
|
}
|
|
|
|
/** @dataProvider sollwerte */
|
|
public function testUpdateBereinigtAlteUngueltigeVorgaben(int $leistung, bool $sichtbar): void
|
|
{
|
|
$modul = new VerbraucherBasisDummy();
|
|
$modul->zustand = ['Sollleistung' => $leistung, 'SollwertGueltig' => false];
|
|
$modul->sichtbareWerte = $sichtbar ? $modul->zustand : [];
|
|
|
|
$modul->bereinigen();
|
|
|
|
self::assertSame(['Sollleistung' => 0, 'SollwertGueltig' => false], $modul->zustand);
|
|
self::assertSame($sichtbar ? $modul->zustand : [], $modul->sichtbareWerte);
|
|
}
|
|
|
|
/** @dataProvider sollwerte */
|
|
public function testUpdateErhaeltGueltigeVorgabenAuchNullUndEntladen(int $leistung, bool $sichtbar): void
|
|
{
|
|
$modul = new VerbraucherBasisDummy();
|
|
$modul->zustand = ['Sollleistung' => $leistung, 'SollwertGueltig' => true];
|
|
$modul->sichtbareWerte = $sichtbar ? $modul->zustand : [];
|
|
$vorher = $modul->zustand;
|
|
|
|
$modul->bereinigen();
|
|
|
|
self::assertSame($vorher, $modul->zustand);
|
|
self::assertSame($sichtbar ? $vorher : [], $modul->sichtbareWerte);
|
|
}
|
|
|
|
public static function sollwerte(): array
|
|
{
|
|
return [[10944, true], [10944, false], [-843, true], [-843, false], [0, true], [0, false]];
|
|
}
|
|
|
|
public function testWiederholtesVerwerfenLaesstNeuBerechneteLokaleSchutzleistungStehen(): void
|
|
{
|
|
$modul = new VerbraucherBasisDummy();
|
|
$modul->zustand = ['Sollleistung' => 3000, 'SollwertGueltig' => false];
|
|
$modul->sichtbareWerte = $modul->zustand;
|
|
|
|
$modul->verwerfen();
|
|
|
|
self::assertSame(['Sollleistung' => 3000, 'SollwertGueltig' => false], $modul->zustand);
|
|
self::assertSame($modul->zustand, $modul->sichtbareWerte);
|
|
}
|
|
|
|
public function testAlleVerbraucherVerwerfenSollwerteUeberDieGemeinsameFunktion(): void
|
|
{
|
|
$anzahl = 0;
|
|
foreach (glob(__DIR__ . '/../*/module.php') as $datei) {
|
|
$quelle = (string) file_get_contents($datei);
|
|
if (!str_contains($quelle, 'implements VerbraucherSchnittstelle')) {
|
|
continue;
|
|
}
|
|
++$anzahl;
|
|
self::assertStringContainsString('use VerbraucherBasisTrait;', $quelle, $datei);
|
|
self::assertStringContainsString('$this->verwerfeSollwert();', $quelle, $datei);
|
|
self::assertStringNotContainsString("setzeZustand('SollwertGueltig', false)", $quelle, $datei);
|
|
self::assertStringNotContainsString("WriteAttributeBoolean('ZustandSollwertGueltig', false)", $quelle, $datei);
|
|
self::assertStringContainsString(
|
|
'$this->aktualisiereVariablen();' . "\n " . '$this->bereinigeUngueltigenSollwert();',
|
|
$quelle,
|
|
$datei
|
|
);
|
|
}
|
|
self::assertSame(7, $anzahl);
|
|
}
|
|
|
|
public function testGemeinsamePropertiesUndVariablenWerdenRegistriert(): void
|
|
{
|
|
$modul = new VerbraucherBasisDummy();
|
|
$modul->registriere();
|
|
|
|
self::assertSame(
|
|
[
|
|
'PrioritaetPV',
|
|
'PrioritaetPeak',
|
|
'Meldeintervall',
|
|
'VorgabeTimeout',
|
|
'EinstellungenInVisu',
|
|
'LoggingEin',
|
|
],
|
|
array_keys($modul->properties)
|
|
);
|
|
self::assertSame(['Aktiv'], array_keys($modul->variablen));
|
|
self::assertSame(['Aktiv'], $modul->aktionen);
|
|
|
|
$modul->registriereDiagnose();
|
|
self::assertSame(
|
|
[
|
|
'Aktiv',
|
|
'Istleistung',
|
|
'Leistungsquelle',
|
|
'Sollleistung',
|
|
'SollwertGueltig',
|
|
'Verfuegbar',
|
|
'AenderungMoeglich',
|
|
'Stoerung',
|
|
'Stoertext',
|
|
],
|
|
array_keys($modul->variablen)
|
|
);
|
|
}
|
|
}
|
|
|
|
final class VerbraucherBasisDummy
|
|
{
|
|
use VerbraucherBasisTrait;
|
|
|
|
/** @var array<string, int|bool> */
|
|
public array $zustand = [];
|
|
|
|
/** @var array<string, int|bool> */
|
|
public array $sichtbareWerte = [];
|
|
|
|
public function verwerfen(): void
|
|
{
|
|
$this->verwerfeSollwert();
|
|
}
|
|
|
|
public function bereinigen(): void
|
|
{
|
|
$this->bereinigeUngueltigenSollwert();
|
|
}
|
|
|
|
private function setzeZustand(string $ident, $wert): void
|
|
{
|
|
$this->zustand[$ident] = $wert;
|
|
if (array_key_exists($ident, $this->sichtbareWerte)) {
|
|
$this->sichtbareWerte[$ident] = $wert;
|
|
}
|
|
}
|
|
|
|
private function leseZustand(string $ident)
|
|
{
|
|
return $this->zustand[$ident];
|
|
}
|
|
|
|
/** @var array<string, mixed> */
|
|
public array $properties = [];
|
|
|
|
/** @var array<string, string> */
|
|
public array $variablen = [];
|
|
|
|
/** @var list<string> */
|
|
public array $aktionen = [];
|
|
|
|
public function registriere(): void
|
|
{
|
|
$this->registriereVerbraucherBasis();
|
|
}
|
|
|
|
public function registriereDiagnose(): void
|
|
{
|
|
$this->registriereVerbraucherDiagnose();
|
|
}
|
|
|
|
public function RegisterPropertyInteger(string $ident, int $standard): void
|
|
{
|
|
$this->properties[$ident] = $standard;
|
|
}
|
|
|
|
public function RegisterPropertyBoolean(string $ident, bool $standard): void
|
|
{
|
|
$this->properties[$ident] = $standard;
|
|
}
|
|
|
|
public function RegisterVariableBoolean(string $ident, string $name, string $profil, int $position): void
|
|
{
|
|
$this->variablen[$ident] = 'Boolean';
|
|
}
|
|
|
|
public function RegisterVariableFloat(string $ident, string $name, string $profil, int $position): void
|
|
{
|
|
$this->variablen[$ident] = 'Float';
|
|
}
|
|
|
|
public function RegisterVariableInteger(string $ident, string $name, string $profil, int $position): void
|
|
{
|
|
$this->variablen[$ident] = 'Integer';
|
|
}
|
|
|
|
public function RegisterVariableString(string $ident, string $name, string $profil, int $position): void
|
|
{
|
|
$this->variablen[$ident] = 'String';
|
|
}
|
|
|
|
public function EnableAction(string $ident): void
|
|
{
|
|
$this->aktionen[] = $ident;
|
|
}
|
|
}
|