This commit is contained in:
@@ -9,6 +9,86 @@ 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();
|
||||
@@ -50,6 +130,35 @@ 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 = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user