Files
votianng/legacy-php-tests/tests/LegacyFunctionsTest.php
T
Sven 9de2358480 Portiere PHP-Cronjobs auf Spring-Tasks und ergänze Legacy-Tests
Migriert die weiterhin benötigten Zeitaufgaben einschließlich SOAP-Importen, Betriebsstatus und Wiederanlaufkontrolle. Aktiviert 115 native Spring-Tasks im Docker-Image ohne Cron-Daemon oder PHP und dokumentiert die entfallenen HHA-Aufrufe. Ergänzt PHP-/UI-Testwerkzeuge und aktualisiert den Projektstand auf Version 0.2.0.
2026-10-27 09:53:23 +01:00

45 lines
1.6 KiB
PHP

<?php
final class LegacyFunctionsTest extends PHPUnit\Framework\TestCase
{
public function testOnlySelectedTopLevelFunctionIsExtracted(): void
{
$source = <<<'SOURCE'
<?php
file_put_contents('/never-execute', 'startup');
// function wanted() { wrong }
class Example { function wanted() { return 'method'; } }
function unwanted() { return '}'; }
function wanted($name) { /* } */ return "{$name}: }"; }
SOURCE;
$found = LegacyFunctions::extract($source, ['wanted']);
self::assertSame(['wanted'], array_keys($found));
self::assertSame('function wanted($name) { /* } */ return "{$name}: }"; }', $found['wanted']['code']);
self::assertSame(6, $found['wanted']['line']);
}
public function testMissingFunctionFailsClosed(): void
{
$this->expectException(RuntimeException::class);
LegacyFunctions::extract('<?php function different() {}', ['wanted']);
}
public function testNestedFunctionCannotBeMistakenForGlobalDeclaration(): void
{
$this->expectException(RuntimeException::class);
LegacyFunctions::extract('<?php function outer() { function wanted() {} }', ['wanted']);
}
public function testIncludesCannotLoadApplicationBootstrap(): void
{
$this->expectException(RuntimeException::class);
LegacyFunctions::extract('<?php function wanted() { require "db.php"; }', ['wanted']);
}
public function testDuplicateDefinitionsFailClosed(): void
{
$this->expectException(RuntimeException::class);
LegacyFunctions::extract('<?php function wanted() {} function wanted() {}', ['wanted']);
}
}