117 lines
3.5 KiB
PHP
117 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Belevo\EnelixEMS\Tests;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class SymconTestContractTest extends TestCase
|
|
{
|
|
public function testEveryModuleHasRegisteredSymconTest(): void
|
|
{
|
|
$root = dirname(__DIR__);
|
|
$moduleDirectories = array_map(
|
|
static fn (string $path): string => basename(dirname($path)),
|
|
glob($root . '/*/module.json') ?: []
|
|
);
|
|
sort($moduleDirectories);
|
|
|
|
$manifest = require __DIR__ . '/Symcon/manifest.php';
|
|
$registeredModules = array_keys($manifest);
|
|
sort($registeredModules);
|
|
|
|
self::assertSame(
|
|
$moduleDirectories,
|
|
$registeredModules,
|
|
'Jedes Modul benötigt einen Eintrag in tests/Symcon/manifest.php.'
|
|
);
|
|
}
|
|
|
|
public function testRegisteredScriptsReturnCallableTests(): void
|
|
{
|
|
$manifest = require __DIR__ . '/Symcon/manifest.php';
|
|
|
|
foreach ($manifest as $module => $definition) {
|
|
self::assertArrayHasKey('file', $definition, $module);
|
|
self::assertArrayHasKey('paths', $definition, $module);
|
|
self::assertFileExists($definition['file'], $module);
|
|
self::assertIsArray($definition['paths'], $module);
|
|
self::assertNotEmpty($definition['paths'], $module);
|
|
self::assertIsCallable(require $definition['file'], $module);
|
|
}
|
|
}
|
|
|
|
public function testFrameworkAndRunnerScriptsExist(): void
|
|
{
|
|
foreach ([
|
|
'TestContext.php',
|
|
'TestRunner.php',
|
|
'bootstrap.php',
|
|
'bin/affected-modules.php',
|
|
'bin/run-symcon-tests.sh',
|
|
] as $file) {
|
|
self::assertFileExists(__DIR__ . '/Symcon/' . $file);
|
|
}
|
|
}
|
|
|
|
public function testAffectedModuleResolverSelectsAllMatches(): void
|
|
{
|
|
self::assertSame(
|
|
[
|
|
'Batterie',
|
|
'LadestationGateway',
|
|
'LadestationStandAlone',
|
|
'Manager',
|
|
'Pufferspeicher',
|
|
'VerbraucherEinStufig',
|
|
'Warmwassererwaermer',
|
|
],
|
|
$this->resolveAffectedModules(['libs/Nachrichtenvertrag.php'])
|
|
);
|
|
}
|
|
|
|
public function testAffectedModuleResolverSelectsManagerForLicenseChecks(): void
|
|
{
|
|
self::assertSame(
|
|
['Manager'],
|
|
$this->resolveAffectedModules(['libs/Lizenzpruefung.php'])
|
|
);
|
|
}
|
|
|
|
public function testAffectedModuleResolverSelectsAllModulesForFrameworkChanges(): void
|
|
{
|
|
self::assertSame(
|
|
[
|
|
'Batterie',
|
|
'EaseeGateway',
|
|
'LadestationGateway',
|
|
'LadestationStandAlone',
|
|
'Manager',
|
|
'Pufferspeicher',
|
|
'VerbraucherEinStufig',
|
|
'Warmwassererwaermer',
|
|
],
|
|
$this->resolveAffectedModules(['tests/Symcon/TestContext.php'])
|
|
);
|
|
}
|
|
|
|
/** @param list<string> $paths
|
|
* @return list<string>
|
|
*/
|
|
private function resolveAffectedModules(array $paths): array
|
|
{
|
|
$argv = array_merge(['affected-modules.php'], $paths);
|
|
ob_start();
|
|
require __DIR__ . '/Symcon/bin/affected-modules.php';
|
|
$output = ob_get_clean();
|
|
self::assertIsString($output);
|
|
|
|
$modules = json_decode($output, true, 512, JSON_THROW_ON_ERROR);
|
|
self::assertIsArray($modules);
|
|
sort($modules);
|
|
|
|
return $modules;
|
|
}
|
|
}
|